Skip to content

Commit be74b99

Browse files
authored
feat: add client_endpoints_override to bq options (#1167)
* feat: add client_endpoints_override to bq options * fix wording
1 parent b39a4b7 commit be74b99

File tree

6 files changed

+50
-2
lines changed

6 files changed

+50
-2
lines changed

bigframes/_config/bigquery_options.py

+20
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def __init__(
9191
skip_bq_connection_check: bool = False,
9292
*,
9393
ordering_mode: Literal["strict", "partial"] = "strict",
94+
client_endpoints_override: dict = {},
9495
):
9596
self._credentials = credentials
9697
self._project = project
@@ -103,6 +104,7 @@ def __init__(
103104
self._session_started = False
104105
# Determines the ordering strictness for the session.
105106
self._ordering_mode = _validate_ordering_mode(ordering_mode)
107+
self._client_endpoints_override = client_endpoints_override
106108

107109
@property
108110
def application_name(self) -> Optional[str]:
@@ -317,3 +319,21 @@ def ordering_mode(self) -> Literal["strict", "partial"]:
317319
@ordering_mode.setter
318320
def ordering_mode(self, ordering_mode: Literal["strict", "partial"]) -> None:
319321
self._ordering_mode = _validate_ordering_mode(ordering_mode)
322+
323+
@property
324+
def client_endpoints_override(self) -> dict:
325+
"""Option that sets the BQ client endpoints addresses directly as a dict. Possible keys are "bqclient", "bqconnectionclient", "bqstoragereadclient"."""
326+
return self._client_endpoints_override
327+
328+
@client_endpoints_override.setter
329+
def client_endpoints_override(self, value: dict):
330+
warnings.warn(
331+
"This is an advanced configuration option for directly setting endpoints. Incorrect use may lead to unexpected behavior or system instability. Proceed only if you fully understand its implications."
332+
)
333+
334+
if self._session_started and self._client_endpoints_override != value:
335+
raise ValueError(
336+
SESSION_STARTED_MESSAGE.format(attribute="client_endpoints_override")
337+
)
338+
339+
self._client_endpoints_override = value

bigframes/_config/experiment_options.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class ExperimentOptions:
2121
"""
2222

2323
def __init__(self):
24-
self._semantic_operators = False
25-
self._blob = False
24+
self._semantic_operators: bool = False
25+
self._blob: bool = False
2626

2727
@property
2828
def semantic_operators(self) -> bool:

bigframes/pandas/io/api.py

+1
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ def _set_default_session_location_if_possible(query):
332332
credentials=config.options.bigquery.credentials,
333333
application_name=config.options.bigquery.application_name,
334334
bq_kms_key_name=config.options.bigquery.kms_key_name,
335+
client_endpoints_override=config.options.bigquery.client_endpoints_override,
335336
)
336337

337338
bqclient = clients_provider.bqclient

bigframes/session/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ def __init__(
186186
credentials=context.credentials,
187187
application_name=context.application_name,
188188
bq_kms_key_name=self._bq_kms_key_name,
189+
client_endpoints_override=context.client_endpoints_override,
189190
)
190191

191192
# TODO(shobs): Remove this logic after https://github.com/ibis-project/ibis/issues/8494

bigframes/session/clients.py

+17
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __init__(
6767
credentials: Optional[google.auth.credentials.Credentials] = None,
6868
application_name: Optional[str] = None,
6969
bq_kms_key_name: Optional[str] = None,
70+
client_endpoints_override: dict = {},
7071
):
7172
credentials_project = None
7273
if credentials is None:
@@ -98,6 +99,7 @@ def __init__(
9899
self._use_regional_endpoints = use_regional_endpoints
99100
self._credentials = credentials
100101
self._bq_kms_key_name = bq_kms_key_name
102+
self._client_endpoints_override = client_endpoints_override
101103

102104
# cloud clients initialized for lazy load
103105
self._bqclient = None
@@ -126,6 +128,11 @@ def _create_bigquery_client(self):
126128
else _BIGQUERY_LOCATIONAL_ENDPOINT
127129
).format(location=self._location),
128130
)
131+
if "bqclient" in self._client_endpoints_override:
132+
bq_options = google.api_core.client_options.ClientOptions(
133+
api_endpoint=self._client_endpoints_override["bqclient"]
134+
)
135+
129136
bq_info = google.api_core.client_info.ClientInfo(
130137
user_agent=self._application_name
131138
)
@@ -172,6 +179,11 @@ def bqconnectionclient(self):
172179
location=self._location
173180
)
174181
)
182+
if "bqconnectionclient" in self._client_endpoints_override:
183+
bqconnection_options = google.api_core.client_options.ClientOptions(
184+
api_endpoint=self._client_endpoints_override["bqconnectionclient"]
185+
)
186+
175187
bqconnection_info = google.api_core.gapic_v1.client_info.ClientInfo(
176188
user_agent=self._application_name
177189
)
@@ -199,6 +211,11 @@ def bqstoragereadclient(self):
199211
else _BIGQUERYSTORAGE_LOCATIONAL_ENDPOINT
200212
).format(location=self._location),
201213
)
214+
215+
if "bqstoragereadclient" in self._client_endpoints_override:
216+
bqstorage_options = google.api_core.client_options.ClientOptions(
217+
api_endpoint=self._client_endpoints_override["bqstoragereadclient"]
218+
)
202219
bqstorage_info = google.api_core.gapic_v1.client_info.ClientInfo(
203220
user_agent=self._application_name
204221
)

tests/unit/_config/test_bigquery_options.py

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
("use_regional_endpoints", False, True),
3535
("kms_key_name", "kms/key/name/1", "kms/key/name/2"),
3636
("skip_bq_connection_check", False, True),
37+
("client_endpoints_override", {}, {"bqclient": "endpoint_address"}),
3738
],
3839
)
3940
def test_setter_raises_if_session_started(attribute, original_value, new_value):
@@ -67,6 +68,7 @@ def test_setter_raises_if_session_started(attribute, original_value, new_value):
6768
"bq_connection",
6869
"use_regional_endpoints",
6970
"bq_kms_key_name",
71+
"client_endpoints_override",
7072
]
7173
],
7274
)
@@ -152,3 +154,10 @@ def set_location_property():
152154
),
153155
):
154156
op()
157+
158+
159+
def test_client_endpoints_override_set_shows_warning():
160+
options = bigquery_options.BigQueryOptions()
161+
162+
with pytest.warns(UserWarning):
163+
options.client_endpoints_override = {"bqclient": "endpoint_address"}

0 commit comments

Comments
 (0)