1717import os
1818import typing
1919from typing import Optional
20+ import warnings
2021
2122import google .api_core .client_info
2223import google .api_core .client_options
@@ -94,8 +95,22 @@ def __init__(
9495 else _APPLICATION_NAME
9596 )
9697 self ._project = project
98+
99+ if (
100+ use_regional_endpoints
101+ and location is not None
102+ and location .lower ()
103+ not in bigframes .constants .REP_ENABLED_BIGQUERY_LOCATIONS
104+ ):
105+ warnings .warn (
106+ bigframes .constants .LEP_DEPRECATION_WARNING_MESSAGE .format (
107+ location = location
108+ ),
109+ category = FutureWarning ,
110+ )
97111 self ._location = location
98112 self ._use_regional_endpoints = use_regional_endpoints
113+
99114 self ._credentials = credentials
100115 self ._bq_kms_key_name = bq_kms_key_name
101116 self ._client_endpoints_override = client_endpoints_override
@@ -117,20 +132,22 @@ def __init__(
117132
118133 def _create_bigquery_client (self ):
119134 bq_options = None
120- if self ._use_regional_endpoints :
121- bq_options = google .api_core .client_options .ClientOptions (
122- api_endpoint = (
123- _BIGQUERY_REGIONAL_ENDPOINT
124- if self ._location is not None
125- and self ._location .lower ()
126- in bigframes .constants .REP_ENABLED_BIGQUERY_LOCATIONS
127- else _BIGQUERY_LOCATIONAL_ENDPOINT
128- ).format (location = self ._location ),
129- )
130135 if "bqclient" in self ._client_endpoints_override :
131136 bq_options = google .api_core .client_options .ClientOptions (
132137 api_endpoint = self ._client_endpoints_override ["bqclient" ]
133138 )
139+ elif self ._use_regional_endpoints :
140+ endpoint_template = _BIGQUERY_REGIONAL_ENDPOINT
141+ if (
142+ self ._location is not None
143+ and self ._location .lower ()
144+ not in bigframes .constants .REP_ENABLED_BIGQUERY_LOCATIONS
145+ ):
146+ endpoint_template = _BIGQUERY_LOCATIONAL_ENDPOINT
147+
148+ bq_options = google .api_core .client_options .ClientOptions (
149+ api_endpoint = endpoint_template .format (location = self ._location )
150+ )
134151
135152 bq_info = google .api_core .client_info .ClientInfo (
136153 user_agent = self ._application_name
@@ -172,16 +189,16 @@ def bqclient(self):
172189 def bqconnectionclient (self ):
173190 if not self ._bqconnectionclient :
174191 bqconnection_options = None
175- if self ._use_regional_endpoints :
192+ if "bqconnectionclient" in self ._client_endpoints_override :
193+ bqconnection_options = google .api_core .client_options .ClientOptions (
194+ api_endpoint = self ._client_endpoints_override ["bqconnectionclient" ]
195+ )
196+ elif self ._use_regional_endpoints :
176197 bqconnection_options = google .api_core .client_options .ClientOptions (
177198 api_endpoint = _BIGQUERYCONNECTION_LOCATIONAL_ENDPOINT .format (
178199 location = self ._location
179200 )
180201 )
181- if "bqconnectionclient" in self ._client_endpoints_override :
182- bqconnection_options = google .api_core .client_options .ClientOptions (
183- api_endpoint = self ._client_endpoints_override ["bqconnectionclient" ]
184- )
185202
186203 bqconnection_info = google .api_core .gapic_v1 .client_info .ClientInfo (
187204 user_agent = self ._application_name
@@ -200,21 +217,23 @@ def bqconnectionclient(self):
200217 def bqstoragereadclient (self ):
201218 if not self ._bqstoragereadclient :
202219 bqstorage_options = None
203- if self ._use_regional_endpoints :
220+ if "bqstoragereadclient" in self ._client_endpoints_override :
204221 bqstorage_options = google .api_core .client_options .ClientOptions (
205- api_endpoint = (
206- _BIGQUERYSTORAGE_REGIONAL_ENDPOINT
207- if self ._location is not None
208- and self ._location .lower ()
209- in bigframes .constants .REP_ENABLED_BIGQUERY_LOCATIONS
210- else _BIGQUERYSTORAGE_LOCATIONAL_ENDPOINT
211- ).format (location = self ._location ),
222+ api_endpoint = self ._client_endpoints_override ["bqstoragereadclient" ]
212223 )
224+ elif self ._use_regional_endpoints :
225+ endpoint_template = _BIGQUERYSTORAGE_REGIONAL_ENDPOINT
226+ if (
227+ self ._location is not None
228+ and self ._location .lower ()
229+ not in bigframes .constants .REP_ENABLED_BIGQUERY_LOCATIONS
230+ ):
231+ endpoint_template = _BIGQUERYSTORAGE_LOCATIONAL_ENDPOINT
213232
214- if "bqstoragereadclient" in self ._client_endpoints_override :
215233 bqstorage_options = google .api_core .client_options .ClientOptions (
216- api_endpoint = self ._client_endpoints_override [ "bqstoragereadclient" ]
234+ api_endpoint = endpoint_template . format ( location = self ._location )
217235 )
236+
218237 bqstorage_info = google .api_core .gapic_v1 .client_info .ClientInfo (
219238 user_agent = self ._application_name
220239 )
0 commit comments