From 65703c5dfb3d71b4a1922597f62300f45bf1954c Mon Sep 17 00:00:00 2001 From: Shuowei Li Date: Thu, 13 Aug 2026 21:21:28 +0000 Subject: [PATCH 1/3] feat(bigframes): add query_dry_run code sample (b/546160994) --- bigquery/bigframes/query_dry_run.py | 46 ++++++++++++++++++++++++ bigquery/bigframes/query_dry_run_test.py | 21 +++++++++++ 2 files changed, 67 insertions(+) create mode 100644 bigquery/bigframes/query_dry_run.py create mode 100644 bigquery/bigframes/query_dry_run_test.py diff --git a/bigquery/bigframes/query_dry_run.py b/bigquery/bigframes/query_dry_run.py new file mode 100644 index 0000000000..06d71748ca --- /dev/null +++ b/bigquery/bigframes/query_dry_run.py @@ -0,0 +1,46 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START bigquery_bigframes_query_dry_run] +import bigframes.pandas as bpd + +from google.cloud import bigquery + +# Set partial ordering mode as the default configuration for BigQuery +# DataFrames. +bpd.options.bigquery.ordering_mode = "partial" + + +def query_dry_run() -> int: + sql = """ + SELECT name, COUNT(*) as name_count + FROM `bigquery-public-data.usa_names.usa_1910_2013` + WHERE state = 'WA' + GROUP BY name + """ + + session = bpd.get_global_session() + job_config = bigquery.QueryJobConfig(dry_run=True, use_query_cache=False) + + # Perform a dry run query using the session BigQuery client. + query_job = session.bqclient.query(sql, job_config=job_config) + + # A dry run query completes immediately and returns query metadata. + print(f"This query will process {query_job.total_bytes_processed} bytes.") + return query_job.total_bytes_processed +# [END bigquery_bigframes_query_dry_run] + + +if __name__ == "__main__": + query_dry_run() diff --git a/bigquery/bigframes/query_dry_run_test.py b/bigquery/bigframes/query_dry_run_test.py new file mode 100644 index 0000000000..22b244e3c5 --- /dev/null +++ b/bigquery/bigframes/query_dry_run_test.py @@ -0,0 +1,21 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import query_dry_run + + +def test_query_dry_run() -> None: + bytes_processed = query_dry_run.query_dry_run() + assert bytes_processed is not None + assert bytes_processed > 0 From f1c91c6918dc314289ea3a8efc86bbdb02a98e89 Mon Sep 17 00:00:00 2001 From: Shuowei Li Date: Thu, 13 Aug 2026 16:10:30 -0700 Subject: [PATCH 2/3] Update bigquery/bigframes/query_dry_run.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- bigquery/bigframes/query_dry_run.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/bigquery/bigframes/query_dry_run.py b/bigquery/bigframes/query_dry_run.py index 06d71748ca..7de2b803b2 100644 --- a/bigquery/bigframes/query_dry_run.py +++ b/bigquery/bigframes/query_dry_run.py @@ -17,10 +17,6 @@ from google.cloud import bigquery -# Set partial ordering mode as the default configuration for BigQuery -# DataFrames. -bpd.options.bigquery.ordering_mode = "partial" - def query_dry_run() -> int: sql = """ From cd15e9840548de7a253a9a15c2dac7b11026868f Mon Sep 17 00:00:00 2001 From: Shuowei Li Date: Thu, 13 Aug 2026 16:10:37 -0700 Subject: [PATCH 3/3] Update bigquery/bigframes/query_dry_run.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- bigquery/bigframes/query_dry_run.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bigquery/bigframes/query_dry_run.py b/bigquery/bigframes/query_dry_run.py index 7de2b803b2..5effac8d01 100644 --- a/bigquery/bigframes/query_dry_run.py +++ b/bigquery/bigframes/query_dry_run.py @@ -33,8 +33,12 @@ def query_dry_run() -> int: query_job = session.bqclient.query(sql, job_config=job_config) # A dry run query completes immediately and returns query metadata. - print(f"This query will process {query_job.total_bytes_processed} bytes.") - return query_job.total_bytes_processed + bytes_processed = query_job.total_bytes_processed + if bytes_processed is None: + raise RuntimeError("Query dry run did not return the number of bytes processed.") + + print(f"This query will process {bytes_processed} bytes.") + return bytes_processed # [END bigquery_bigframes_query_dry_run]