Skip to content

Commit d3495a0

Browse files
dharmishan0g0791nishantgaurav-devdharmishadoshi@gmail.com
authored
fix: Resolving syntax error while querying a feature view with column name starting with a number and BigQuery as data source (feast-dev#4908)
* Fixing issue feast-dev#4688 Signed-off-by: Dharmisha Doshi <dharmishadoshi@gmail.com> * Fixing issue feast-dev#4688 Signed-off-by: Dharmisha Doshi <dharmishadoshi@gmail.com> * Fixing issue feast-dev#4688 Signed-off-by: Dharmisha Doshi <dharmishadoshi@gmail.com> * resolving PEP 8 warnings Signed-off-by: Dharmisha Doshi <dharmishadoshi@gmail.com> * resolving linting issues Signed-off-by: Dharmisha Doshi <dharmishadoshi@gmail.com> --------- Signed-off-by: Dharmisha Doshi <dharmishadoshi@gmail.com> Co-authored-by: n0g0791 <nishant.gaurav0@walmart.com> Co-authored-by: nishantgaurav-dev <nishantgaurav26@gmail.com> Co-authored-by: dharmishadoshi@gmail.com <d0d0fmz@m-j2t66th1w2.homeoffice.wal-mart.com>
1 parent fc8cff0 commit d3495a0

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,10 @@ def arrow_schema_to_bq_schema(arrow_schema: pyarrow.Schema) -> List[SchemaField]
901901
{{ featureview.created_timestamp_column ~ ' as created_timestamp,' if featureview.created_timestamp_column else '' }}
902902
{{ featureview.entity_selections | join(', ')}}{% if featureview.entity_selections %},{% else %}{% endif %}
903903
{% for feature in featureview.features %}
904-
{{ feature }} as {% if full_feature_names %}{{ featureview.name }}__{{featureview.field_mapping.get(feature, feature)}}{% else %}{{ featureview.field_mapping.get(feature, feature) }}{% endif %}{% if loop.last %}{% else %}, {% endif %}
904+
{{ feature | backticks }} as {% if full_feature_names %}
905+
{{ featureview.name }}__{{featureview.field_mapping.get(feature, feature)}}{% else %}
906+
{{ featureview.field_mapping.get(feature, feature) | backticks }}{% endif %}
907+
{% if loop.last %}{% else %}, {% endif %}
905908
{% endfor %}
906909
FROM {{ featureview.table_subquery }}
907910
WHERE {{ featureview.timestamp_field }} <= '{{ featureview.max_event_timestamp }}'
@@ -995,14 +998,14 @@ def arrow_schema_to_bq_schema(arrow_schema: pyarrow.Schema) -> List[SchemaField]
995998
The entity_dataframe dataset being our source of truth here.
996999
*/
9971000
998-
SELECT {{ final_output_feature_names | join(', ')}}
1001+
SELECT {{ final_output_feature_names | backticks | join(', ')}}
9991002
FROM entity_dataframe
10001003
{% for featureview in featureviews %}
10011004
LEFT JOIN (
10021005
SELECT
10031006
{{featureview.name}}__entity_row_unique_id
10041007
{% for feature in featureview.features %}
1005-
,{% if full_feature_names %}{{ featureview.name }}__{{featureview.field_mapping.get(feature, feature)}}{% else %}{{ featureview.field_mapping.get(feature, feature) }}{% endif %}
1008+
,{% if full_feature_names %}{{ featureview.name }}__{{featureview.field_mapping.get(feature, feature)}}{% else %}{{ featureview.field_mapping.get(feature, feature) | backticks }}{% endif %}
10061009
{% endfor %}
10071010
FROM {{ featureview.name }}__cleaned
10081011
) USING ({{featureview.name}}__entity_row_unique_id)

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ def build_point_in_time_query(
186186
full_feature_names: bool = False,
187187
) -> str:
188188
"""Build point-in-time query between each feature view table and the entity dataframe for Bigquery and Redshift"""
189-
template = Environment(loader=BaseLoader()).from_string(source=query_template)
189+
env = Environment(loader=BaseLoader())
190+
env.filters["backticks"] = enclose_in_backticks
191+
template = env.from_string(source=query_template)
190192

191193
final_output_feature_names = list(entity_df_columns)
192194
final_output_feature_names.extend(
@@ -252,3 +254,11 @@ def get_pyarrow_schema_from_batch_source(
252254
column_names.append(column_name)
253255

254256
return pa.schema(pa_schema), column_names
257+
258+
259+
def enclose_in_backticks(value):
260+
# Check if the input is a list
261+
if isinstance(value, list):
262+
return [f"`{v}`" for v in value]
263+
else:
264+
return f"`{value}`"

0 commit comments

Comments
 (0)