From ed58a86fcc6ac5713b4dae0ceb2cbfd67a09a604 Mon Sep 17 00:00:00 2001 From: Ben Stuart Date: Tue, 27 Aug 2024 19:47:50 +0100 Subject: [PATCH 1/2] Check for snowflake functions over stage Signed-off-by: Ben Stuart --- .../feast/infra/materialization/snowflake_engine.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/python/feast/infra/materialization/snowflake_engine.py b/sdk/python/feast/infra/materialization/snowflake_engine.py index 9f9f41c83d2..68a4a4e8a84 100644 --- a/sdk/python/feast/infra/materialization/snowflake_engine.py +++ b/sdk/python/feast/infra/materialization/snowflake_engine.py @@ -128,16 +128,16 @@ def update( stage_context = f'"{self.repo_config.batch_engine.database}"."{self.repo_config.batch_engine.schema_}"' stage_path = f'{stage_context}."feast_{project}"' with GetSnowflakeConnection(self.repo_config.batch_engine) as conn: - query = f"SHOW STAGES IN {stage_context}" + query = f"SHOW USER FUNCTIONS LIKE 'FEAST_{project.upper()}%' IN SCHEMA {stage_context}" cursor = execute_snowflake_statement(conn, query) stage_list = pd.DataFrame( cursor.fetchall(), columns=[column.name for column in cursor.description], ) - # if the stage already exists, + # if the SHOW FUNCTIONS query returns results, # assumes that the materialization functions have been deployed - if f"feast_{project}" in stage_list["name"].tolist(): + if len(stage_list.index) > 0: click.echo( f"Materialization functions for {Style.BRIGHT + Fore.GREEN}{project}{Style.RESET_ALL} already detected." ) @@ -149,7 +149,7 @@ def update( ) click.echo() - query = f"CREATE STAGE {stage_path}" + query = f"CREATE STAGE IF NOT EXISTS {stage_path}" execute_snowflake_statement(conn, query) copy_path, zip_path = package_snowpark_zip(project) From 02ec6ad836c769df4debcd2363a45d715474fa67 Mon Sep 17 00:00:00 2001 From: Ben Stuart Date: Tue, 27 Aug 2024 19:53:35 +0100 Subject: [PATCH 2/2] Refactor stage_list to function_list Signed-off-by: Ben Stuart --- sdk/python/feast/infra/materialization/snowflake_engine.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/python/feast/infra/materialization/snowflake_engine.py b/sdk/python/feast/infra/materialization/snowflake_engine.py index 68a4a4e8a84..e8b0857e5d5 100644 --- a/sdk/python/feast/infra/materialization/snowflake_engine.py +++ b/sdk/python/feast/infra/materialization/snowflake_engine.py @@ -130,14 +130,14 @@ def update( with GetSnowflakeConnection(self.repo_config.batch_engine) as conn: query = f"SHOW USER FUNCTIONS LIKE 'FEAST_{project.upper()}%' IN SCHEMA {stage_context}" cursor = execute_snowflake_statement(conn, query) - stage_list = pd.DataFrame( + function_list = pd.DataFrame( cursor.fetchall(), columns=[column.name for column in cursor.description], ) # if the SHOW FUNCTIONS query returns results, # assumes that the materialization functions have been deployed - if len(stage_list.index) > 0: + if len(function_list.index) > 0: click.echo( f"Materialization functions for {Style.BRIGHT + Fore.GREEN}{project}{Style.RESET_ALL} already detected." )