Skip to content

Commit 15f3f2a

Browse files
authored
perf: use JOB_CREATION_OPTIONAL when allow_large_results=False (#1763)
1 parent 1cfbb47 commit 15f3f2a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

bigframes/session/clients.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ def _create_bigquery_client(self):
181181
location=self._location,
182182
)
183183

184+
# If a new enough client library is available, we opt-in to the faster
185+
# backend behavior. This only affects code paths where query_and_wait is
186+
# used, which doesn't expose a query job directly. See internal issue
187+
# b/417985981.
188+
if hasattr(bq_client, "default_job_creation_mode"):
189+
bq_client.default_job_creation_mode = "JOB_CREATION_OPTIONAL"
190+
184191
if self._bq_kms_key_name:
185192
# Note: Key configuration only applies automatically to load and query jobs, not copy jobs.
186193
encryption_config = bigquery.EncryptionConfiguration(

tests/unit/session/test_clients.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def create_clients_provider(application_name: Optional[str] = None):
4646
def monkeypatch_client_constructors(monkeypatch):
4747
bqclient = mock.create_autospec(google.cloud.bigquery.Client)
4848
bqclient.return_value = bqclient
49+
# Assume we have a new client library in the unit tests.
50+
bqclient.default_job_creation_mode = None # type: ignore
4951
monkeypatch.setattr(google.cloud.bigquery, "Client", bqclient)
5052

5153
bqconnectionclient = mock.create_autospec(
@@ -83,6 +85,11 @@ def monkeypatch_client_constructors(monkeypatch):
8385
)
8486

8587

88+
def assert_bqclient_sets_default_job_creation_mode(provider: clients.ClientsProvider):
89+
bqclient = provider.bqclient
90+
assert bqclient.default_job_creation_mode == "JOB_CREATION_OPTIONAL"
91+
92+
8693
def assert_constructed_w_user_agent(mock_client: mock.Mock, expected_user_agent: str):
8794
assert (
8895
expected_user_agent

0 commit comments

Comments
 (0)