Skip to content

Commit 1c6b196

Browse files
committed
deployment changes dev
1 parent a8539cb commit 1c6b196

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

scripts/check_udf_signature.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import os
2+
import sys
3+
import argparse
4+
5+
def check_udf_signature(udf_path):
6+
"""Check the signature of a UDF function.py file."""
7+
function_file = os.path.join(udf_path, "function.py")
8+
9+
if not os.path.exists(function_file):
10+
print(f"Error: Function file not found at: {function_file}")
11+
return False
12+
13+
with open(function_file, 'r') as f:
14+
content = f.read()
15+
16+
# Look for the main function definition
17+
if "def main(session, input_data" in content:
18+
print("✅ UDF uses Snowpark style with session and input_data parameters")
19+
print("Use this SQL:")
20+
print("""
21+
CREATE OR REPLACE FUNCTION UDF_NAME(input_data VARIANT)
22+
RETURNS VARIANT
23+
LANGUAGE PYTHON
24+
RUNTIME_VERSION=3.8
25+
PACKAGES = ('snowflake-snowpark-python')
26+
IMPORTS = ('@STAGE/path/to/zip')
27+
HANDLER = 'function.main'
28+
""")
29+
return True
30+
31+
elif "def main(input_data" in content:
32+
print("✅ UDF uses basic style with just input_data parameter")
33+
print("Use this SQL:")
34+
print("""
35+
CREATE OR REPLACE FUNCTION UDF_NAME(input_data VARIANT)
36+
RETURNS VARIANT
37+
LANGUAGE PYTHON
38+
RUNTIME_VERSION=3.8
39+
PACKAGES = ('snowflake-snowpark-python')
40+
IMPORTS = ('@STAGE/path/to/zip')
41+
HANDLER = 'function.main'
42+
""")
43+
return True
44+
45+
else:
46+
print("❌ Could not identify UDF signature pattern")
47+
print("Please check the function.py file manually")
48+
return False
49+
50+
if __name__ == "__main__":
51+
parser = argparse.ArgumentParser(description='Check UDF function signature')
52+
parser.add_argument('udf_path', help='Path to UDF directory')
53+
args = parser.parse_args()
54+
55+
check_udf_signature(args.udf_path)

scripts/snowflake_deployer.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,19 @@ def deploy_component(profile_name, component_path, component_name, component_typ
190190
for f in files:
191191
logger.info(f"{sub_indent}{f}")
192192

193+
# Check if UDF requires session parameter by examining function.py
194+
has_session_param = False
195+
try:
196+
function_file = os.path.join(code_dir, "function.py")
197+
if os.path.exists(function_file):
198+
with open(function_file, 'r') as f:
199+
content = f.read()
200+
if "def main(session, input_data" in content:
201+
logger.info("Detected UDF with session parameter")
202+
has_session_param = True
203+
except Exception as e:
204+
logger.warning(f"Could not check function signature: {str(e)}")
205+
193206
# Zip the directory
194207
zip_directory(code_dir, zip_path)
195208
logger.info(f"Created zip file: {zip_path}")
@@ -204,6 +217,7 @@ def deploy_component(profile_name, component_path, component_name, component_typ
204217
import_path = f"@{stage_name}/{component_name.replace(' ', '_')}/{zip_filename}"
205218

206219
if component_type.lower() == "udf":
220+
# For Snowpark UDFs that use session parameter
207221
sql = f"""
208222
CREATE OR REPLACE FUNCTION {component_name.replace(' ', '_')}(input_data VARIANT)
209223
RETURNS VARIANT
@@ -305,4 +319,4 @@ def execute_sql_file(profile_name, sql_file):
305319

306320
else:
307321
parser.print_help()
308-
sys.exit(1)
322+
sys.exit(1)

0 commit comments

Comments
 (0)