From 776420b1669e9da854017bda99593e6a0d464f31 Mon Sep 17 00:00:00 2001 From: n0g0791 Date: Tue, 12 Nov 2024 10:43:14 +0530 Subject: [PATCH 1/5] Fixing issue https://github.com/feast-dev/feast/issues/4688 Signed-off-by: Dharmisha Doshi --- sdk/python/feast/infra/offline_stores/bigquery.py | 6 +++--- .../feast/infra/offline_stores/offline_utils.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/sdk/python/feast/infra/offline_stores/bigquery.py b/sdk/python/feast/infra/offline_stores/bigquery.py index 23f80d79ff2..933f24f9ffd 100644 --- a/sdk/python/feast/infra/offline_stores/bigquery.py +++ b/sdk/python/feast/infra/offline_stores/bigquery.py @@ -901,7 +901,7 @@ def arrow_schema_to_bq_schema(arrow_schema: pyarrow.Schema) -> List[SchemaField] {{ featureview.created_timestamp_column ~ ' as created_timestamp,' if featureview.created_timestamp_column else '' }} {{ featureview.entity_selections | join(', ')}}{% if featureview.entity_selections %},{% else %}{% endif %} {% for feature in featureview.features %} - {{ 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 %} + {{ feature | backticks }} as {% if full_feature_names %}{{ featureview.name }}__{{featureview.field_mapping.get(feature, feature)}}{% else %}{{ featureview.field_mapping.get(feature, feature) | backticks }}{% endif %}{% if loop.last %}{% else %}, {% endif %} {% endfor %} FROM {{ featureview.table_subquery }} WHERE {{ featureview.timestamp_field }} <= '{{ featureview.max_event_timestamp }}' @@ -995,14 +995,14 @@ def arrow_schema_to_bq_schema(arrow_schema: pyarrow.Schema) -> List[SchemaField] The entity_dataframe dataset being our source of truth here. */ -SELECT {{ final_output_feature_names | join(', ')}} +SELECT {{ final_output_feature_names | backticks | join(', ')}} FROM entity_dataframe {% for featureview in featureviews %} LEFT JOIN ( SELECT {{featureview.name}}__entity_row_unique_id {% for feature in featureview.features %} - ,{% if full_feature_names %}{{ featureview.name }}__{{featureview.field_mapping.get(feature, feature)}}{% else %}{{ featureview.field_mapping.get(feature, feature) }}{% endif %} + ,{% if full_feature_names %}{{ featureview.name }}__{{featureview.field_mapping.get(feature, feature)}}{% else %}{{ featureview.field_mapping.get(feature, feature) | backticks }}{% endif %} {% endfor %} FROM {{ featureview.name }}__cleaned ) USING ({{featureview.name}}__entity_row_unique_id) diff --git a/sdk/python/feast/infra/offline_stores/offline_utils.py b/sdk/python/feast/infra/offline_stores/offline_utils.py index 2d4fa268e40..5ea34ac0554 100644 --- a/sdk/python/feast/infra/offline_stores/offline_utils.py +++ b/sdk/python/feast/infra/offline_stores/offline_utils.py @@ -186,7 +186,9 @@ def build_point_in_time_query( full_feature_names: bool = False, ) -> str: """Build point-in-time query between each feature view table and the entity dataframe for Bigquery and Redshift""" - template = Environment(loader=BaseLoader()).from_string(source=query_template) + env = Environment(loader=BaseLoader()) + env.filters['backticks'] = enclose_in_backticks + template = env.from_string(source=query_template) final_output_feature_names = list(entity_df_columns) final_output_feature_names.extend( @@ -252,3 +254,11 @@ def get_pyarrow_schema_from_batch_source( column_names.append(column_name) return pa.schema(pa_schema), column_names + + +def enclose_in_backticks(value): + # Check if the input is a list + if isinstance(value, list): + return [f'`{v}`' for v in value] + else: + return f'`{value}`' From f29b869b6c3c04be94cefe775b6b4dd74f6ffecb Mon Sep 17 00:00:00 2001 From: nishantgaurav-dev Date: Tue, 12 Nov 2024 12:56:23 +0530 Subject: [PATCH 2/5] Fixing issue https://github.com/feast-dev/feast/issues/4688 Signed-off-by: Dharmisha Doshi --- sdk/python/feast/infra/offline_stores/offline_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/python/feast/infra/offline_stores/offline_utils.py b/sdk/python/feast/infra/offline_stores/offline_utils.py index 5ea34ac0554..94eec3765da 100644 --- a/sdk/python/feast/infra/offline_stores/offline_utils.py +++ b/sdk/python/feast/infra/offline_stores/offline_utils.py @@ -262,3 +262,4 @@ def enclose_in_backticks(value): return [f'`{v}`' for v in value] else: return f'`{value}`' + From 3fa7a107e0de3d53e324c7243aa2eb7255a27eea Mon Sep 17 00:00:00 2001 From: nishantgaurav-dev Date: Tue, 12 Nov 2024 12:56:58 +0530 Subject: [PATCH 3/5] Fixing issue https://github.com/feast-dev/feast/issues/4688 Signed-off-by: Dharmisha Doshi --- sdk/python/feast/infra/offline_stores/offline_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/python/feast/infra/offline_stores/offline_utils.py b/sdk/python/feast/infra/offline_stores/offline_utils.py index 94eec3765da..5ea34ac0554 100644 --- a/sdk/python/feast/infra/offline_stores/offline_utils.py +++ b/sdk/python/feast/infra/offline_stores/offline_utils.py @@ -262,4 +262,3 @@ def enclose_in_backticks(value): return [f'`{v}`' for v in value] else: return f'`{value}`' - From e947c72df889d10a4dc63bbabe47271b2479ec55 Mon Sep 17 00:00:00 2001 From: "dharmishadoshi@gmail.com" Date: Wed, 8 Jan 2025 22:39:31 -0800 Subject: [PATCH 4/5] resolving PEP 8 warnings Signed-off-by: Dharmisha Doshi --- sdk/python/feast/infra/offline_stores/bigquery.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sdk/python/feast/infra/offline_stores/bigquery.py b/sdk/python/feast/infra/offline_stores/bigquery.py index 933f24f9ffd..a98a34ff31e 100644 --- a/sdk/python/feast/infra/offline_stores/bigquery.py +++ b/sdk/python/feast/infra/offline_stores/bigquery.py @@ -898,10 +898,14 @@ def arrow_schema_to_bq_schema(arrow_schema: pyarrow.Schema) -> List[SchemaField] {{ featureview.name }}__subquery AS ( SELECT {{ featureview.timestamp_field }} as event_timestamp, - {{ featureview.created_timestamp_column ~ ' as created_timestamp,' if featureview.created_timestamp_column else '' }} + {{ featureview.created_timestamp_column ~ ' as created_timestamp,' if featureview.created_timestamp_column + else '' }} {{ featureview.entity_selections | join(', ')}}{% if featureview.entity_selections %},{% else %}{% endif %} {% for feature in featureview.features %} - {{ feature | backticks }} as {% if full_feature_names %}{{ featureview.name }}__{{featureview.field_mapping.get(feature, feature)}}{% else %}{{ featureview.field_mapping.get(feature, feature) | backticks }}{% endif %}{% if loop.last %}{% else %}, {% endif %} + {{ feature | backticks }} as {% if full_feature_names %} + {{ featureview.name }}__{{featureview.field_mapping.get(feature, feature)}}{% else %} + {{ featureview.field_mapping.get(feature, feature) | backticks }}{% endif %} + {% if loop.last %}{% else %}, {% endif %} {% endfor %} FROM {{ featureview.table_subquery }} WHERE {{ featureview.timestamp_field }} <= '{{ featureview.max_event_timestamp }}' From eb5610d0b4c271ac124ad60fa5d283f28fb735ea Mon Sep 17 00:00:00 2001 From: "dharmishadoshi@gmail.com" Date: Thu, 9 Jan 2025 00:26:18 -0800 Subject: [PATCH 5/5] resolving linting issues Signed-off-by: Dharmisha Doshi --- sdk/python/feast/infra/offline_stores/bigquery.py | 3 +-- sdk/python/feast/infra/offline_stores/offline_utils.py | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/sdk/python/feast/infra/offline_stores/bigquery.py b/sdk/python/feast/infra/offline_stores/bigquery.py index a98a34ff31e..f0516b594ee 100644 --- a/sdk/python/feast/infra/offline_stores/bigquery.py +++ b/sdk/python/feast/infra/offline_stores/bigquery.py @@ -898,8 +898,7 @@ def arrow_schema_to_bq_schema(arrow_schema: pyarrow.Schema) -> List[SchemaField] {{ featureview.name }}__subquery AS ( SELECT {{ featureview.timestamp_field }} as event_timestamp, - {{ featureview.created_timestamp_column ~ ' as created_timestamp,' if featureview.created_timestamp_column - else '' }} + {{ featureview.created_timestamp_column ~ ' as created_timestamp,' if featureview.created_timestamp_column else '' }} {{ featureview.entity_selections | join(', ')}}{% if featureview.entity_selections %},{% else %}{% endif %} {% for feature in featureview.features %} {{ feature | backticks }} as {% if full_feature_names %} diff --git a/sdk/python/feast/infra/offline_stores/offline_utils.py b/sdk/python/feast/infra/offline_stores/offline_utils.py index 5ea34ac0554..2076f977acc 100644 --- a/sdk/python/feast/infra/offline_stores/offline_utils.py +++ b/sdk/python/feast/infra/offline_stores/offline_utils.py @@ -187,7 +187,7 @@ def build_point_in_time_query( ) -> str: """Build point-in-time query between each feature view table and the entity dataframe for Bigquery and Redshift""" env = Environment(loader=BaseLoader()) - env.filters['backticks'] = enclose_in_backticks + env.filters["backticks"] = enclose_in_backticks template = env.from_string(source=query_template) final_output_feature_names = list(entity_df_columns) @@ -259,6 +259,6 @@ def get_pyarrow_schema_from_batch_source( def enclose_in_backticks(value): # Check if the input is a list if isinstance(value, list): - return [f'`{v}`' for v in value] + return [f"`{v}`" for v in value] else: - return f'`{value}`' + return f"`{value}`"