Skip to content

perf: use JOB_CREATION_OPTIONAL when allow_large_results=False #1763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025
Merged
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
7 changes: 7 additions & 0 deletions bigframes/session/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ def _create_bigquery_client(self):
location=self._location,
)

# If a new enough client library is available, we opt-in to the faster
# backend behavior. This only affects code paths where query_and_wait is
# used, which doesn't expose a query job directly. See internal issue
# b/417985981.
if hasattr(bq_client, "default_job_creation_mode"):
bq_client.default_job_creation_mode = "JOB_CREATION_OPTIONAL"

if self._bq_kms_key_name:
# Note: Key configuration only applies automatically to load and query jobs, not copy jobs.
encryption_config = bigquery.EncryptionConfiguration(
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/session/test_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def create_clients_provider(application_name: Optional[str] = None):
def monkeypatch_client_constructors(monkeypatch):
bqclient = mock.create_autospec(google.cloud.bigquery.Client)
bqclient.return_value = bqclient
# Assume we have a new client library in the unit tests.
bqclient.default_job_creation_mode = None # type: ignore
monkeypatch.setattr(google.cloud.bigquery, "Client", bqclient)

bqconnectionclient = mock.create_autospec(
Expand Down Expand Up @@ -83,6 +85,11 @@ def monkeypatch_client_constructors(monkeypatch):
)


def assert_bqclient_sets_default_job_creation_mode(provider: clients.ClientsProvider):
bqclient = provider.bqclient
assert bqclient.default_job_creation_mode == "JOB_CREATION_OPTIONAL"


def assert_constructed_w_user_agent(mock_client: mock.Mock, expected_user_agent: str):
assert (
expected_user_agent
Expand Down