Skip to content

Commit

Permalink
fix: Syntax Error in BigQuery While Retrieving Columns that Start wit…
Browse files Browse the repository at this point in the history
…h a Number

Signed-off-by: Theodor Mihalache <[email protected]>
  • Loading branch information
tmihalac committed Oct 29, 2024
1 parent 47dc04d commit a4cce1c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions sdk/python/feast/infra/offline_stores/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def pull_latest_from_table_or_query(
assert isinstance(data_source, BigQuerySource)
from_expression = data_source.get_table_query_string()

partition_by_join_key_string = ", ".join(join_key_columns)
partition_by_join_key_string = ", ".join(
BigQueryOfflineStore._escape_query_columns(join_key_columns)
)
if partition_by_join_key_string != "":
partition_by_join_key_string = (
"PARTITION BY " + partition_by_join_key_string
Expand All @@ -146,7 +148,11 @@ def pull_latest_from_table_or_query(
if created_timestamp_column:
timestamps.append(created_timestamp_column)
timestamp_desc_string = " DESC, ".join(timestamps) + " DESC"
field_string = ", ".join(join_key_columns + feature_name_columns + timestamps)
field_string = ", ".join(
BigQueryOfflineStore._escape_query_columns(join_key_columns)
+ BigQueryOfflineStore._escape_query_columns(feature_name_columns)
+ timestamps
)
project_id = (
config.offline_store.billing_project_id or config.offline_store.project_id
)
Expand Down Expand Up @@ -196,7 +202,9 @@ def pull_all_from_table_or_query(
location=config.offline_store.location,
)
field_string = ", ".join(
join_key_columns + feature_name_columns + [timestamp_field]
BigQueryOfflineStore._escape_query_columns(join_key_columns)
+ BigQueryOfflineStore._escape_query_columns(feature_name_columns)
+ [timestamp_field]
)
query = f"""
SELECT {field_string}
Expand Down Expand Up @@ -429,6 +437,10 @@ def offline_write_batch(
job_config=job_config,
).result()

@staticmethod
def _escape_query_columns(columns: List[str]) -> List[str]:
return [f"`{x}`" for x in columns]


class BigQueryRetrievalJob(RetrievalJob):
def __init__(
Expand Down

0 comments on commit a4cce1c

Please sign in to comment.