17
17
import os
18
18
import typing
19
19
from typing import Optional
20
+ import warnings
20
21
21
22
import google .api_core .client_info
22
23
import google .api_core .client_options
@@ -94,8 +95,22 @@ def __init__(
94
95
else _APPLICATION_NAME
95
96
)
96
97
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
+ )
97
111
self ._location = location
98
112
self ._use_regional_endpoints = use_regional_endpoints
113
+
99
114
self ._credentials = credentials
100
115
self ._bq_kms_key_name = bq_kms_key_name
101
116
self ._client_endpoints_override = client_endpoints_override
@@ -117,20 +132,22 @@ def __init__(
117
132
118
133
def _create_bigquery_client (self ):
119
134
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
- )
130
135
if "bqclient" in self ._client_endpoints_override :
131
136
bq_options = google .api_core .client_options .ClientOptions (
132
137
api_endpoint = self ._client_endpoints_override ["bqclient" ]
133
138
)
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
+ )
134
151
135
152
bq_info = google .api_core .client_info .ClientInfo (
136
153
user_agent = self ._application_name
@@ -172,16 +189,16 @@ def bqclient(self):
172
189
def bqconnectionclient (self ):
173
190
if not self ._bqconnectionclient :
174
191
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 :
176
197
bqconnection_options = google .api_core .client_options .ClientOptions (
177
198
api_endpoint = _BIGQUERYCONNECTION_LOCATIONAL_ENDPOINT .format (
178
199
location = self ._location
179
200
)
180
201
)
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
- )
185
202
186
203
bqconnection_info = google .api_core .gapic_v1 .client_info .ClientInfo (
187
204
user_agent = self ._application_name
@@ -200,21 +217,23 @@ def bqconnectionclient(self):
200
217
def bqstoragereadclient (self ):
201
218
if not self ._bqstoragereadclient :
202
219
bqstorage_options = None
203
- if self ._use_regional_endpoints :
220
+ if "bqstoragereadclient" in self ._client_endpoints_override :
204
221
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" ]
212
223
)
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
213
232
214
- if "bqstoragereadclient" in self ._client_endpoints_override :
215
233
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 )
217
235
)
236
+
218
237
bqstorage_info = google .api_core .gapic_v1 .client_info .ClientInfo (
219
238
user_agent = self ._application_name
220
239
)
0 commit comments