Skip to content

Commit 8ebf84f

Browse files
committed
Dry runs return bytes processed, and cache hit now
1 parent d404b6d commit 8ebf84f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

bigquery/client.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def _submit_query_job(self, query_data):
243243
-------
244244
tuple
245245
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
247247
or a dict containing the response if invalid.
248248
249249
Raises
@@ -269,13 +269,17 @@ def _submit_query_job(self, query_data):
269269
schema = query_reply.get('schema', {'fields': None})['fields']
270270
rows = query_reply.get('rows', [])
271271
job_complete = query_reply.get('jobComplete', False)
272+
cache_hit = query_reply['cacheHit']
273+
total_bytes_processed = query_reply['totalBytesProcessed']
272274

273275
# raise exceptions if it's not an async query
274276
# and job is not completed after timeout
275277
if not job_complete and query_data.get("timeoutMs", False):
276278
logger.error('BigQuery job %s timeout' % job_id)
277279
raise BigQueryTimeoutException()
278-
280+
281+
if query_data.get("dryRun", True):
282+
return job_id, [cache_hit, total_bytes_processed]
279283
return job_id, [self._transform_row(row, schema) for row in rows]
280284

281285
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
345349
How long to wait for the query to complete, in seconds before
346350
the request times out and returns.
347351
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
350354
message it would if it wasn't a dry run.
351355
use_legacy_sql : bool, optional. Default True.
352356
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
359363
-------
360364
tuple
361365
(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
363367
or a ``dict`` containing the response if invalid.
364368
365369
Raises

0 commit comments

Comments
 (0)