Skip to content

Commit

Permalink
feat: support regional endpoints for more bigquery locations (#1061)
Browse files Browse the repository at this point in the history
* feat: Support bigquery regional endpoints for more locations

* typo plural

* correct the arg documentation
  • Loading branch information
shobsi authored Oct 8, 2024
1 parent f86483d commit 45b672a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
27 changes: 19 additions & 8 deletions bigframes/_config/bigquery_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,29 @@ def skip_bq_connection_check(self, value: bool):
def use_regional_endpoints(self) -> bool:
"""Flag to connect to regional API endpoints.
.. deprecated:: 0.13.0
Use of regional endpoints is a feature in Preview and
available only in selected regions and projects.
.. note::
Use of regional endpoints is a feature in Preview and available only
in regions "europe-west3", "europe-west9", "europe-west8",
"me-central2", "us-east4" and "us-west1".
Requires that ``location`` is set. For example, to connect to
asia-northeast1-bigquery.googleapis.com, specify
``location='asia-northeast1'`` and ``use_regional_endpoints=True``.
.. deprecated:: 0.13.0
Use of locational endpoints is available only in selected projects.
Requires that ``location`` is set. For supported regions, for example
``europe-west3``, you need to specify ``location='europe-west3'`` and
``use_regional_endpoints=True``, and then BigQuery DataFrames would
connect to the BigQuery endpoint ``bigquery.europe-west3.rep.googleapis.com``.
For not supported regions, for example ``asia-northeast1``, when you
specify ``location='asia-northeast1'`` and ``use_regional_endpoints=True``,
a different endpoint (called locational endpoint, now deprecated, used
to provide weaker promise on the request remaining within the location
during transit) ``europe-west3-bigquery.googleapis.com`` would be used.
Returns:
bool:
A boolean value, where True indicates that a location is set;
otherwise False.
A boolean value, where True indicates that regional endpoints
would be used for BigQuery and BigQuery storage APIs; otherwise
global endpoints would be used.
"""
return self._use_regional_endpoints

Expand Down
5 changes: 3 additions & 2 deletions bigframes/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@
# https://cloud.google.com/storage/docs/regional-endpoints
REP_ENABLED_BIGQUERY_LOCATIONS = frozenset(
{
"me-central2",
"europe-west9",
"europe-west3",
"europe-west9",
"europe-west8",
"me-central2",
"us-east4",
"us-west1",
}
Expand Down
16 changes: 5 additions & 11 deletions bigframes/session/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,13 @@
import ibis
import pydata_google_auth

import bigframes.constants
import bigframes.version

_ENV_DEFAULT_PROJECT = "GOOGLE_CLOUD_PROJECT"
_APPLICATION_NAME = f"bigframes/{bigframes.version.__version__} ibis/{ibis.__version__}"
_SCOPES = ["https://www.googleapis.com/auth/cloud-platform"]

# Regions for which Regional Endpoints (REPs) are supported
_REP_SUPPORTED_REGIONS = {
"me-central2",
"europe-west9",
"europe-west3",
"us-east4",
"us-west1",
}


# BigQuery is a REST API, which requires the protocol as part of the URL.
_BIGQUERY_LOCATIONAL_ENDPOINT = "https://{location}-bigquery.googleapis.com"
Expand Down Expand Up @@ -129,7 +121,8 @@ def _create_bigquery_client(self):
api_endpoint=(
_BIGQUERY_REGIONAL_ENDPOINT
if self._location is not None
and self._location.lower() in _REP_SUPPORTED_REGIONS
and self._location.lower()
in bigframes.constants.REP_ENABLED_BIGQUERY_LOCATIONS
else _BIGQUERY_LOCATIONAL_ENDPOINT
).format(location=self._location),
)
Expand Down Expand Up @@ -201,7 +194,8 @@ def bqstoragereadclient(self):
api_endpoint=(
_BIGQUERYSTORAGE_REGIONAL_ENDPOINT
if self._location is not None
and self._location.lower() in _REP_SUPPORTED_REGIONS
and self._location.lower()
in bigframes.constants.REP_ENABLED_BIGQUERY_LOCATIONS
else _BIGQUERYSTORAGE_LOCATIONAL_ENDPOINT
).format(location=self._location),
)
Expand Down

0 comments on commit 45b672a

Please sign in to comment.