SnowPro Associate: Platform Question 33
Single answer○ PythonA data engineering team wants to let analysts call a Python user-defined function (UDF) in Snowflake to standardize product descriptions during ad hoc SQL analysis. The function uses a third-party Python library that is available from Snowflake Anaconda packages. The team wants the solution to run entirely inside Snowflake without managing external compute. Which approach best meets this requirement?
- A
Create a Python UDF in Snowflake, specify the runtime version and required package, and call it directly from SQL queries.
- B
Create an external function that sends each product description to an API running the Python code outside Snowflake.
- C
Create a JavaScript UDF and import the Python package through the JavaScript handler.
- D
Run a Python script from SnowSQL on an analyst laptop each time the data is queried, then write the results back to a temporary table.
Show answer and explanation
Correct answer: A
Explanation
The best answer is to use a Python UDF. Snowflake supports Python UDFs and stored procedures for logic written in Python, and these run within Snowflake rather than on customer-managed servers. For package management, Snowflake supports many third-party Python libraries through Anaconda, allowing developers to specify dependencies in the function definition. This is the most direct way to expose reusable Python-based logic to analysts through SQL. By contrast, external functions are specifically for invoking services outside Snowflake, and client-side scripts do not provide governed, centralized execution. Relevant Snowflake documentation includes the sections on Python UDFs, handler languages, and using third-party packages from the Snowflake Anaconda channel.
- A. Correct.
Correct. Snowflake supports Python UDFs that execute inside Snowflake-managed compute. When the required third-party library is available through Snowflake's supported Anaconda integration, the function can declare the package and runtime version and then be invoked directly in SQL. This matches the requirement for in-platform execution without external infrastructure.
- B. Incorrect.
Incorrect. External functions rely on an external service endpoint, typically through API Gateway and a remote service. Although this could run Python code, it does not meet the requirement to run entirely inside Snowflake and would introduce external compute and operational overhead.
- C. Incorrect.
Incorrect. JavaScript UDFs use JavaScript as the handler language and cannot directly import and run Python libraries. This option confuses Snowflake's support for multiple handler languages with the idea that one language runtime can natively load packages from another runtime.
- D. Incorrect.
Incorrect. Running Python from SnowSQL or a local client uses client-side compute, not Snowflake's in-platform execution model. It also creates operational inconsistency because results depend on a user's environment and manual execution rather than a reusable SQL function managed in Snowflake.