Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions sdk/python/feast/infra/offline_stores/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class SnowflakeOfflineStoreConfig(FeastConfigBaseModel):
blob_export_location: Optional[str] = None
""" Location (in S3, Google storage or Azure storage) where data is offloaded """

convert_timestamp_columns: Optional[bool] = None
""" Convert timestamp columns on export to a Parquet-supported format """

class Config:
allow_population_by_field_name = True

Expand Down Expand Up @@ -152,6 +155,21 @@ def pull_latest_from_table_or_query(
+ '"'
)

if config.offline_store.convert_timestamp_columns:
select_timestamps = list(map(lambda field_name: f"to_varchar({field_name}, 'YYYY-MM-DD\"T\"HH24:MI:SS.FFTZH:TZM') as {field_name}", timestamp_columns))
inner_field_string = (
Comment thread
adamschmidt marked this conversation as resolved.
Outdated
'"'
+ '", "'.join(join_key_columns + feature_name_columns)
+ '", '
+ ", ".join(select_timestamps)
)
else:
inner_field_string = (
Comment thread
adamschmidt marked this conversation as resolved.
Outdated
'"'
+ '", "'.join(join_key_columns + feature_name_columns + timestamp_columns)
+ '"'
)

if data_source.snowflake_options.warehouse:
config.offline_store.warehouse = data_source.snowflake_options.warehouse

Expand All @@ -166,7 +184,7 @@ def pull_latest_from_table_or_query(
{field_string}
{f''', TRIM({repr(DUMMY_ENTITY_VAL)}::VARIANT,'"') AS "{DUMMY_ENTITY_ID}"''' if not join_key_columns else ""}
FROM (
SELECT {field_string},
SELECT {inner_field_string},
ROW_NUMBER() OVER({partition_by_join_key_string} ORDER BY {timestamp_desc_string}) AS "_feast_row"
FROM {from_expression}
WHERE "{timestamp_field}" BETWEEN TIMESTAMP '{start_date}' AND TIMESTAMP '{end_date}'
Expand Down Expand Up @@ -533,7 +551,7 @@ def to_remote_storage(self) -> List[str]:
self.to_snowflake(table)

query = f"""
COPY INTO '{self.config.offline_store.blob_export_location}/{table}' FROM "{self.config.offline_store.database}"."{self.config.offline_store.schema_}"."{table}"\n
COPY INTO '{self.export_path}/{table}' FROM "{self.config.offline_store.database}"."{self.config.offline_store.schema_}"."{table}"\n
STORAGE_INTEGRATION = {self.config.offline_store.storage_integration_name}\n
FILE_FORMAT = (TYPE = PARQUET)
DETAILED_OUTPUT = TRUE
Expand Down