|
| 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) |
0 commit comments