Skip to content

Commit

Permalink
Add location to BigQueryOfflineStoreConfig (#1921)
Browse files Browse the repository at this point in the history
* update bq feature store configs and client configs

Signed-off-by: Kevin Loftis <loftiskg@gmail.com>

* add additional docs

Signed-off-by: Kevin Loftis <loftiskg@gmail.com>
  • Loading branch information
loftiskg authored Oct 3, 2021
1 parent 489f05f commit 982b7cd
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions sdk/python/feast/infra/offline_stores/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class BigQueryOfflineStoreConfig(FeastConfigBaseModel):
project_id: Optional[StrictStr] = None
""" (optional) GCP project name used for the BigQuery offline store """

location: Optional[StrictStr] = None
""" (optional) GCP location name used for the BigQuery offline store.
Examples of location names include ``US``, ``EU``, ``us-central1``, ``us-west4``.
If a location is not specified, the location defaults to the ``US`` multi-regional location.
For more information on BigQuery data locations see: https://cloud.google.com/bigquery/docs/locations
"""


class BigQueryOfflineStore(OfflineStore):
@staticmethod
Expand Down Expand Up @@ -79,7 +86,10 @@ def pull_latest_from_table_or_query(
timestamp_desc_string = " DESC, ".join(timestamps) + " DESC"
field_string = ", ".join(join_key_columns + feature_name_columns + timestamps)

client = _get_bigquery_client(project=config.offline_store.project_id)
client = _get_bigquery_client(
project=config.offline_store.project_id,
location=config.offline_store.location,
)
query = f"""
SELECT
{field_string}
Expand Down Expand Up @@ -115,7 +125,10 @@ def get_historical_features(
# TODO: Add entity_df validation in order to fail before interacting with BigQuery
assert isinstance(config.offline_store, BigQueryOfflineStoreConfig)

client = _get_bigquery_client(project=config.offline_store.project_id)
client = _get_bigquery_client(
project=config.offline_store.project_id,
location=config.offline_store.location,
)

assert isinstance(config.offline_store, BigQueryOfflineStoreConfig)

Expand Down Expand Up @@ -367,9 +380,9 @@ def _upload_entity_df_and_get_entity_schema(
return entity_schema


def _get_bigquery_client(project: Optional[str] = None):
def _get_bigquery_client(project: Optional[str] = None, location: Optional[str] = None):
try:
client = bigquery.Client(project=project)
client = bigquery.Client(project=project, location=location)
except DefaultCredentialsError as e:
raise FeastProviderLoginError(
str(e)
Expand Down

0 comments on commit 982b7cd

Please sign in to comment.