Python UDFs 故障排除

本主题提供有关 Python UDFs(用户定义函数)的故障排除信息。

故障排除

问题:Anaconda 无法提供所需的 Python 库

Third-party Python libraries, which do not have C/C++ extensions, can be imported by UDFs directly via Snowflake stages. For more information, see Creating a Python UDF with code uploaded from a stage.

To learn how to submit a request to support additional Anaconda packages, see Using third-party packages.

问题:UDF 失败并显示错误“Function available memory exhausted”

减少 UDF 使用的内存量。

检查 UDF 代码是否存在错误或内存泄漏。

For more information, see Memory.

问题:我想提取 UDF 中的 ZIP 或其他档案

To see an example of how to upload a ZIP file to a Snowflake stage and then unzip it into the /tmp directory inside the UDF, see Unzipping a staged file.

问题:UDF 性能缓慢

For information about how to improve the performance of UDFs, see Optimizing for scale and performance.

问题:ORGADMIN 角色未启用,因此无法使用 Anaconda 包

When going through the steps to get started using third-party packages from Anaconda, the organization administrator (ORGADMIN) role is required.

To resolve this problem, follow the instructions in Enabling the ORGADMIN role in an account.

问题:读取文件时 UDF 失败并显示错误“UnicodeDecodeError”

When you use the SnowflakeFile class to read files that contain non-text data, you must specify the input mode as binary. Otherwise you might encounter the following error:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf7 in position 12: invalid start byte

To resolve this problem, specify the input mode as binary by passing 'rb' for the mode argument (the second argument). For example:

with SnowflakeFile.open(file_name, 'rb') as f:

技巧

Training machine learning (ML) models can sometimes be very resource intensive. Snowpark-optimized warehouses are a type of Snowflake virtual warehouse that can be used for workloads that require a large amount of memory and compute resources. For information on machine learning models and Snowpark Python, see Training Machine Learning Models with Snowpark Python.

If using a Python UDF in a masking policy, ensure the data type of the column, UDF, and masking policy match.

For troubleshooting information about third-party packages, see Known issues with third-party packages.