Skip to content

Commit a20c4e2

Browse files
authored
Merge branch 'main' into feat-dataset-view
2 parents 11dcdc9 + d92b487 commit a20c4e2

File tree

15 files changed

+96
-44
lines changed

15 files changed

+96
-44
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@
55
[1]: https://pypi.org/project/google-cloud-bigquery/#history
66

77

8+
## [3.34.0](https://github.com/googleapis/python-bigquery/compare/v3.33.0...v3.34.0) (2025-05-27)
9+
10+
11+
### Features
12+
13+
* Job creation mode GA ([#2190](https://github.com/googleapis/python-bigquery/issues/2190)) ([64cd39f](https://github.com/googleapis/python-bigquery/commit/64cd39fb395c4a03ef6d2ec8261e1709477b2186))
14+
15+
16+
### Bug Fixes
17+
18+
* **deps:** Update all dependencies ([#2184](https://github.com/googleapis/python-bigquery/issues/2184)) ([12490f2](https://github.com/googleapis/python-bigquery/commit/12490f2f03681516465fc34217dcdf57000f6fdd))
19+
20+
21+
### Documentation
22+
23+
* Update query.py ([#2192](https://github.com/googleapis/python-bigquery/issues/2192)) ([9b5ee78](https://github.com/googleapis/python-bigquery/commit/9b5ee78f046d9ca3f758eeca6244b8485fe35875))
24+
* Use query_and_wait in the array parameters sample ([#2202](https://github.com/googleapis/python-bigquery/issues/2202)) ([28a9994](https://github.com/googleapis/python-bigquery/commit/28a9994792ec90a6a4d16835faf2137c09c0fb02))
25+
826
## [3.33.0](https://github.com/googleapis/python-bigquery/compare/v3.32.0...v3.33.0) (2025-05-19)
927

1028

google/cloud/bigquery/_job_helpers.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
import copy
3939
import functools
40-
import os
4140
import uuid
4241
import textwrap
4342
from typing import Any, Dict, Optional, TYPE_CHECKING, Union
@@ -400,12 +399,6 @@ def query_and_wait(
400399
) -> table.RowIterator:
401400
"""Run the query, wait for it to finish, and return the results.
402401
403-
While ``jobCreationMode=JOB_CREATION_OPTIONAL`` is in preview in the
404-
``jobs.query`` REST API, use the default ``jobCreationMode`` unless
405-
the environment variable ``QUERY_PREVIEW_ENABLED=true``. After
406-
``jobCreationMode`` is GA, this method will always use
407-
``jobCreationMode=JOB_CREATION_OPTIONAL``. See:
408-
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query
409402
410403
Args:
411404
client:
@@ -500,9 +493,8 @@ def query_and_wait(
500493
request_body["maxResults"] = min(page_size, max_results)
501494
elif page_size is not None or max_results is not None:
502495
request_body["maxResults"] = page_size or max_results
503-
504-
if os.getenv("QUERY_PREVIEW_ENABLED", "").casefold() == "true":
505-
request_body["jobCreationMode"] = "JOB_CREATION_OPTIONAL"
496+
if client.default_job_creation_mode:
497+
request_body["jobCreationMode"] = client.default_job_creation_mode
506498

507499
def do_query():
508500
request_body["requestId"] = make_job_id()

google/cloud/bigquery/client.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ class Client(ClientWithProject):
221221
client_options (Optional[Union[google.api_core.client_options.ClientOptions, Dict]]):
222222
Client options used to set user options on the client. API Endpoint
223223
should be set through client_options.
224+
default_job_creation_mode (Optional[str]):
225+
Sets the default job creation mode used by query methods such as
226+
query_and_wait(). For lightweight queries, JOB_CREATION_OPTIONAL is
227+
generally recommended.
224228
225229
Raises:
226230
google.auth.exceptions.DefaultCredentialsError:
@@ -243,6 +247,7 @@ def __init__(
243247
client_options: Optional[
244248
Union[google.api_core.client_options.ClientOptions, Dict[str, Any]]
245249
] = None,
250+
default_job_creation_mode: Optional[str] = None,
246251
) -> None:
247252
if client_options is None:
248253
client_options = {}
@@ -277,6 +282,7 @@ def __init__(
277282
self._connection = Connection(self, **kw_args)
278283
self._location = location
279284
self._default_load_job_config = copy.deepcopy(default_load_job_config)
285+
self.default_job_creation_mode = default_job_creation_mode
280286

281287
# Use property setter so validation can run.
282288
self.default_query_job_config = default_query_job_config
@@ -286,6 +292,15 @@ def location(self):
286292
"""Default location for jobs / datasets / tables."""
287293
return self._location
288294

295+
@property
296+
def default_job_creation_mode(self):
297+
"""Default job creation mode used for query execution."""
298+
return self._default_job_creation_mode
299+
300+
@default_job_creation_mode.setter
301+
def default_job_creation_mode(self, value: Optional[str]):
302+
self._default_job_creation_mode = value
303+
289304
@property
290305
def default_query_job_config(self) -> Optional[QueryJobConfig]:
291306
"""Default ``QueryJobConfig`` or ``None``.
@@ -3554,13 +3569,6 @@ def query_and_wait(
35543569
) -> RowIterator:
35553570
"""Run the query, wait for it to finish, and return the results.
35563571
3557-
While ``jobCreationMode=JOB_CREATION_OPTIONAL`` is in preview in the
3558-
``jobs.query`` REST API, use the default ``jobCreationMode`` unless
3559-
the environment variable ``QUERY_PREVIEW_ENABLED=true``. After
3560-
``jobCreationMode`` is GA, this method will always use
3561-
``jobCreationMode=JOB_CREATION_OPTIONAL``. See:
3562-
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query
3563-
35643572
Args:
35653573
query (str):
35663574
SQL query to be executed. Defaults to the standard SQL

google/cloud/bigquery/enums.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,22 @@ class BigLakeTableFormat(object):
425425

426426
ICEBERG = "ICEBERG"
427427
"""Apache Iceberg format."""
428+
429+
430+
class JobCreationMode(object):
431+
"""Documented values for Job Creation Mode."""
432+
433+
JOB_CREATION_MODE_UNSPECIFIED = "JOB_CREATION_MODE_UNSPECIFIED"
434+
"""Job creation mode is unspecified."""
435+
436+
JOB_CREATION_REQUIRED = "JOB_CREATION_REQUIRED"
437+
"""Job creation is always required."""
438+
439+
JOB_CREATION_OPTIONAL = "JOB_CREATION_OPTIONAL"
440+
"""Job creation is optional.
441+
442+
Returning immediate results is prioritized.
443+
BigQuery will automatically determine if a Job needs to be created.
444+
The conditions under which BigQuery can decide to not create a Job are
445+
subject to change.
446+
"""

google/cloud/bigquery/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = "3.33.0"
15+
__version__ = "3.34.0"
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@
1313
# limitations under the License.
1414

1515

16-
def client_query_shortmode() -> None:
17-
# [START bigquery_query_shortquery]
18-
# This example demonstrates issuing a query that may be run in short query mode.
19-
#
20-
# To enable the short query mode preview feature, the QUERY_PREVIEW_ENABLED
21-
# environmental variable should be set to `TRUE`.
16+
def client_query_job_optional() -> None:
17+
# [START bigquery_query_job_optional]
18+
# This example demonstrates executing a query without requiring an associated
19+
# job.
2220
from google.cloud import bigquery
21+
from google.cloud.bigquery.enums import JobCreationMode
2322

24-
# Construct a BigQuery client object.
25-
client = bigquery.Client()
23+
# Construct a BigQuery client object, specifying that the library should
24+
# avoid creating jobs when possible.
25+
client = bigquery.Client(
26+
default_job_creation_mode=JobCreationMode.JOB_CREATION_OPTIONAL
27+
)
2628

2729
query = """
2830
SELECT
@@ -44,10 +46,12 @@ def client_query_shortmode() -> None:
4446
if rows.job_id is not None:
4547
print("Query was run with job state. Job ID: {}".format(rows.job_id))
4648
else:
47-
print("Query was run in short mode. Query ID: {}".format(rows.query_id))
49+
print(
50+
"Query was run without creating a job. Query ID: {}".format(rows.query_id)
51+
)
4852

4953
print("The query data:")
5054
for row in rows:
5155
# Row values can be accessed by field name or index.
5256
print("name={}, gender={}, total={}".format(row[0], row[1], row["total"]))
53-
# [END bigquery_query_shortquery]
57+
# [END bigquery_query_job_optional]

samples/client_query_w_array_params.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def client_query_w_array_params() -> None:
3535
bigquery.ArrayQueryParameter("states", "STRING", ["WA", "WI", "WV", "WY"]),
3636
]
3737
)
38-
query_job = client.query(query, job_config=job_config) # Make an API request.
38+
rows = client.query_and_wait(query, job_config=job_config) # Make an API request.
3939

40-
for row in query_job:
40+
for row in rows:
4141
print("{}: \t{}".format(row.name, row.count))
4242
# [END bigquery_query_params_arrays]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
google-cloud-testutils==1.6.4
22
pytest==8.3.5
33
mock==5.2.0
4-
pytest-xdist==3.6.1
4+
pytest-xdist==3.7.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pytest==8.3.5
22
mock==5.2.0
3-
pytest-xdist==3.6.1
3+
pytest-xdist==3.7.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
google-cloud-testutils==1.6.4
22
pytest==8.3.5
33
mock==5.2.0
4-
pytest-xdist==3.6.1
4+
pytest-xdist==3.7.0

0 commit comments

Comments
 (0)