@@ -7181,8 +7181,12 @@ public void testStatelessQueries() throws InterruptedException {
71817181 // Stateless query should have no job id.
71827182 bigQuery .getOptions ().setDefaultJobCreationMode (JobCreationMode .JOB_CREATION_OPTIONAL );
71837183 TableResult tableResult = executeSimpleQuery (bigQuery );
7184- assertNotNull (tableResult .getQueryId ());
7185- assertNull (tableResult .getJobId ());
7184+ // Use XOR: We accept EITHER a QueryId (fast path) OR a JobId (slow fallback), but not both.
7185+ // Ideally Stateless query will return queryId but in some cases it would return jobId instead
7186+ // of queryId based on the query complexity or other factors (job timeout configs).
7187+ assertTrue (
7188+ "Exactly one of jobId or queryId should be non-null" ,
7189+ (tableResult .getJobId () != null ) ^ (tableResult .getQueryId () != null ));
71867190
71877191 // Job creation takes over, no query id is created.
71887192 bigQuery .getOptions ().setDefaultJobCreationMode (JobCreationMode .JOB_CREATION_REQUIRED );
@@ -7220,8 +7224,14 @@ public void testTableResultJobIdAndQueryId() throws InterruptedException {
72207224 String query = "SELECT 1 as one" ;
72217225 QueryJobConfiguration configStateless = QueryJobConfiguration .newBuilder (query ).build ();
72227226 TableResult result = bigQuery .query (configStateless );
7223- assertNull (result .getJobId ());
7224- assertNotNull (result .getQueryId ());
7227+ // A stateless query should result in either a queryId (stateless success) or a jobId (fallback
7228+ // to a job).
7229+ // Exactly one of them should be non-null.
7230+ // Ideally Stateless query will return queryId but in some cases it would return jobId instead
7231+ // of queryId based on the query complexity or other factors (job timeout configs).
7232+ assertTrue (
7233+ "Exactly one of jobId or queryId should be non-null" ,
7234+ (result .getJobId () != null ) ^ (result .getQueryId () != null ));
72257235
72267236 // Test scenario 2 by failing stateless check by setting job timeout.
72277237 QueryJobConfiguration configQueryWithJob =
0 commit comments