Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions bigquery/bigframes/query_dry_run.py
Original file line number Diff line number Diff line change
@@ -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


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.
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]


if __name__ == "__main__":
query_dry_run()
21 changes: 21 additions & 0 deletions bigquery/bigframes/query_dry_run_test.py
Original file line number Diff line number Diff line change
@@ -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