File tree 3 files changed +42
-2
lines changed
3 files changed +42
-2
lines changed Original file line number Diff line number Diff line change 19
19
import decimal
20
20
import math
21
21
import re
22
+ import os
22
23
from typing import Optional , Union
23
24
24
25
from dateutil import relativedelta
28
29
from google .cloud ._helpers import _RFC3339_MICROS
29
30
from google .cloud ._helpers import _RFC3339_NO_FRACTION
30
31
from google .cloud ._helpers import _to_bytes
31
- import packaging .version
32
32
33
+ import packaging .version
33
34
34
35
_RFC3339_MICROS_NO_ZULU = "%Y-%m-%dT%H:%M:%S.%f"
35
36
_TIMEONLY_WO_MICROS = "%H:%M:%S"
51
52
52
53
_BQ_STORAGE_OPTIONAL_READ_SESSION_VERSION = packaging .version .Version ("2.6.0" )
53
54
55
+ BIGQUERY_EMULATOR_HOST = "BIGQUERY_EMULATOR_HOST"
56
+ """Environment variable defining host for emulator."""
57
+
58
+ _DEFAULT_HOST = "https://bigquery.googleapis.com"
59
+ """Default host for JSON API."""
60
+
61
+
62
+ def _get_bigquery_host ():
63
+ return os .environ .get (BIGQUERY_EMULATOR_HOST , _DEFAULT_HOST )
64
+
54
65
55
66
class BQStorageVersions :
56
67
"""Version comparisons for google-cloud-bigqueyr-storage package."""
Original file line number Diff line number Diff line change 56
56
import google .cloud ._helpers # type: ignore
57
57
from google .cloud import exceptions # pytype: disable=import-error
58
58
from google .cloud .client import ClientWithProject # type: ignore # pytype: disable=import-error
59
-
60
59
from google .cloud .bigquery_storage_v1 .services .big_query_read .client import (
61
60
DEFAULT_CLIENT_INFO as DEFAULT_BQSTORAGE_CLIENT_INFO ,
62
61
)
67
66
from google .cloud .bigquery ._helpers import _record_field_to_json
68
67
from google .cloud .bigquery ._helpers import _str_or_none
69
68
from google .cloud .bigquery ._helpers import _verify_job_config_type
69
+ from google .cloud .bigquery ._helpers import _get_bigquery_host
70
+ from google .cloud .bigquery ._helpers import _DEFAULT_HOST
70
71
from google .cloud .bigquery ._http import Connection
71
72
from google .cloud .bigquery import _pandas_helpers
72
73
from google .cloud .bigquery .dataset import Dataset
@@ -230,6 +231,8 @@ def __init__(
230
231
)
231
232
232
233
kw_args = {"client_info" : client_info }
234
+ bq_host = _get_bigquery_host ()
235
+ kw_args ["api_endpoint" ] = bq_host if bq_host != _DEFAULT_HOST else None
233
236
if client_options :
234
237
if type (client_options ) == dict :
235
238
client_options = google .api_core .client_options .from_dict (
Original file line number Diff line number Diff line change @@ -1288,3 +1288,29 @@ def test_decimal_as_float_api_repr():
1288
1288
"parameterValue" : {"value" : 42.0 },
1289
1289
"name" : "x" ,
1290
1290
}
1291
+
1292
+
1293
+ class Test__get_bigquery_host (unittest .TestCase ):
1294
+ @staticmethod
1295
+ def _call_fut ():
1296
+ from google .cloud .bigquery ._helpers import _get_bigquery_host
1297
+
1298
+ return _get_bigquery_host ()
1299
+
1300
+ def test_wo_env_var (self ):
1301
+ from google .cloud .bigquery ._helpers import _DEFAULT_HOST
1302
+
1303
+ with mock .patch ("os.environ" , {}):
1304
+ host = self ._call_fut ()
1305
+
1306
+ self .assertEqual (host , _DEFAULT_HOST )
1307
+
1308
+ def test_w_env_var (self ):
1309
+ from google .cloud .bigquery ._helpers import BIGQUERY_EMULATOR_HOST
1310
+
1311
+ HOST = "https://api.example.com"
1312
+
1313
+ with mock .patch ("os.environ" , {BIGQUERY_EMULATOR_HOST : HOST }):
1314
+ host = self ._call_fut ()
1315
+
1316
+ self .assertEqual (host , HOST )
You can’t perform that action at this time.
0 commit comments