@@ -243,7 +243,7 @@ def _submit_query_job(self, query_data):
243
243
-------
244
244
tuple
245
245
job id and query results if query completed. If dry_run is True,
246
- job id will be None and results will be empty if the query is valid
246
+ job id will be None and results will be [cacheHit and totalBytesProcessed] if the query is valid
247
247
or a dict containing the response if invalid.
248
248
249
249
Raises
@@ -269,13 +269,17 @@ def _submit_query_job(self, query_data):
269
269
schema = query_reply .get ('schema' , {'fields' : None })['fields' ]
270
270
rows = query_reply .get ('rows' , [])
271
271
job_complete = query_reply .get ('jobComplete' , False )
272
+ cache_hit = query_reply ['cacheHit' ]
273
+ total_bytes_processed = query_reply ['totalBytesProcessed' ]
272
274
273
275
# raise exceptions if it's not an async query
274
276
# and job is not completed after timeout
275
277
if not job_complete and query_data .get ("timeoutMs" , False ):
276
278
logger .error ('BigQuery job %s timeout' % job_id )
277
279
raise BigQueryTimeoutException ()
278
-
280
+
281
+ if query_data .get ("dryRun" , True ):
282
+ return job_id , [cache_hit , total_bytes_processed ]
279
283
return job_id , [self ._transform_row (row , schema ) for row in rows ]
280
284
281
285
def _get_job_reference (self , job_id ):
@@ -345,8 +349,8 @@ def query(self, query, max_results=None, timeout=0, dry_run=False, use_legacy_sq
345
349
How long to wait for the query to complete, in seconds before
346
350
the request times out and returns.
347
351
dry_run : bool, optional
348
- If True, the query isn't actually run. A valid query will return an
349
- empty response , while an invalid one will return the same error
352
+ If True, the query isn't actually run. A valid query will return
353
+ cache hit, and total bytes processed , while an invalid one will return the same error
350
354
message it would if it wasn't a dry run.
351
355
use_legacy_sql : bool, optional. Default True.
352
356
If False, the query will use BigQuery's standard SQL (https://cloud.google.com/bigquery/sql-reference/)
@@ -359,7 +363,7 @@ def query(self, query, max_results=None, timeout=0, dry_run=False, use_legacy_sq
359
363
-------
360
364
tuple
361
365
(job id, query results) if the query completed. If dry_run is True,
362
- job id will be None and results will be empty if the query is valid
366
+ job id will be None and results will be [cacheHit and totalBytesProcessed] if the query is valid
363
367
or a ``dict`` containing the response if invalid.
364
368
365
369
Raises
0 commit comments