Skip to content

Commit a4cce1c

Browse files
committed
fix: Syntax Error in BigQuery While Retrieving Columns that Start with a Number
Signed-off-by: Theodor Mihalache <tmihalac@redhat.com>
1 parent 47dc04d commit a4cce1c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

sdk/python/feast/infra/offline_stores/bigquery.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ def pull_latest_from_table_or_query(
137137
assert isinstance(data_source, BigQuerySource)
138138
from_expression = data_source.get_table_query_string()
139139

140-
partition_by_join_key_string = ", ".join(join_key_columns)
140+
partition_by_join_key_string = ", ".join(
141+
BigQueryOfflineStore._escape_query_columns(join_key_columns)
142+
)
141143
if partition_by_join_key_string != "":
142144
partition_by_join_key_string = (
143145
"PARTITION BY " + partition_by_join_key_string
@@ -146,7 +148,11 @@ def pull_latest_from_table_or_query(
146148
if created_timestamp_column:
147149
timestamps.append(created_timestamp_column)
148150
timestamp_desc_string = " DESC, ".join(timestamps) + " DESC"
149-
field_string = ", ".join(join_key_columns + feature_name_columns + timestamps)
151+
field_string = ", ".join(
152+
BigQueryOfflineStore._escape_query_columns(join_key_columns)
153+
+ BigQueryOfflineStore._escape_query_columns(feature_name_columns)
154+
+ timestamps
155+
)
150156
project_id = (
151157
config.offline_store.billing_project_id or config.offline_store.project_id
152158
)
@@ -196,7 +202,9 @@ def pull_all_from_table_or_query(
196202
location=config.offline_store.location,
197203
)
198204
field_string = ", ".join(
199-
join_key_columns + feature_name_columns + [timestamp_field]
205+
BigQueryOfflineStore._escape_query_columns(join_key_columns)
206+
+ BigQueryOfflineStore._escape_query_columns(feature_name_columns)
207+
+ [timestamp_field]
200208
)
201209
query = f"""
202210
SELECT {field_string}
@@ -429,6 +437,10 @@ def offline_write_batch(
429437
job_config=job_config,
430438
).result()
431439

440+
@staticmethod
441+
def _escape_query_columns(columns: List[str]) -> List[str]:
442+
return [f"`{x}`" for x in columns]
443+
432444

433445
class BigQueryRetrievalJob(RetrievalJob):
434446
def __init__(

0 commit comments

Comments
 (0)