Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ef9945a

Browse filesBrowse files
fix: BigFrames respects bq default region (#16933)
1 parent e7efd90 commit ef9945a
Copy full SHA for ef9945a

2 files changed

+37-25Lines changed: 37 additions & 25 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/bigframes/bigframes/session/__init__.py‎

Copy file name to clipboardExpand all lines: packages/bigframes/bigframes/session/__init__.py
+34-23Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -188,39 +188,50 @@ def __init__(
188188
if context is None:
189189
context = bigquery_options.BigQueryOptions()
190190

191-
if context.location is None:
192-
self._location = "US"
193-
msg = bfe.format_message(
194-
f"No explicit location is set, so using location {self._location} for the session."
195-
)
196-
# User's code
197-
# -> get_global_session()
198-
# -> connect()
199-
# -> Session()
200-
#
201-
# Note: We could also have:
202-
# User's code
203-
# -> read_gbq()
204-
# -> with_default_session()
205-
# -> get_global_session()
206-
# -> connect()
207-
# -> Session()
208-
# but we currently have no way to disambiguate these
209-
# situations.
210-
warnings.warn(msg, stacklevel=4, category=bfe.DefaultLocationWarning)
211-
else:
212-
self._location = context.location
213-
214191
self._bq_kms_key_name = context.kms_key_name
215192

216193
# Instantiate a clients provider to help with cloud clients that will be
217194
# used in the future operations in the session
218195
if clients_provider:
196+
# this path is only for unit testing. Not meant to be used by end users.
219197
self._clients_provider = clients_provider
198+
self._location = context.location or "US"
220199
else:
221200
credentials, project = (
222201
bigframes._config.auth.resolve_credentials_and_project(context)
223202
)
203+
if context.location is None:
204+
with bigquery.Client(
205+
project=project,
206+
credentials=credentials,
207+
) as temp_client:
208+
row_iter = temp_client.query_and_wait(
209+
"SELECT 1",
210+
job_config=bigquery.QueryJobConfig(dry_run=True),
211+
)
212+
self._location = row_iter.location or "US"
213+
msg = bfe.format_message(
214+
f"No explicit location is set, so using location {self._location} for the session."
215+
)
216+
# User's code
217+
# -> get_global_session()
218+
# -> connect()
219+
# -> Session()
220+
#
221+
# Note: We could also have:
222+
# User's code
223+
# -> read_gbq()
224+
# -> with_default_session()
225+
# -> get_global_session()
226+
# -> connect()
227+
# -> Session()
228+
# but we currently have no way to disambiguate these
229+
# situations.
230+
warnings.warn(
231+
msg, stacklevel=4, category=bfe.DefaultLocationWarning
232+
)
233+
else:
234+
self._location = context.location
224235

225236
self._clients_provider = clients.ClientsProvider(
226237
project=project,
Collapse file

‎packages/bigframes/bigframes/session/bq_caching_executor.py‎

Copy file name to clipboardExpand all lines: packages/bigframes/bigframes/session/bq_caching_executor.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,9 @@ def _cache_most_complex_subtree(self, node: nodes.BigFrameNode) -> bool:
547547
max_complexity=QUERY_COMPLEXITY_LIMIT,
548548
cache=self.cache,
549549
# Heuristic: subtree_compleixty * (copies of subtree)^2
550-
heuristic=lambda complexity, count: math.log(complexity)
551-
+ 2 * math.log(count),
550+
heuristic=lambda complexity, count: (
551+
math.log(complexity) + 2 * math.log(count)
552+
),
552553
)
553554
if selection is None:
554555
# No good subtrees to cache, just return original tree

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.