0
0
Snowflakecloud~20 mins

User-defined functions with Snowpark in Snowflake - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Snowpark UDF Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
What is the output of this Snowpark UDF execution?

Given a Snowflake Snowpark UDF that doubles an integer input, what will be the output of calling it with input 5?

Snowflake
from snowflake.snowpark.functions import udf

@udf
def double_value(x: int) -> int:
    return x * 2

result = double_value(5).collect()[0][0]
A25
B5
C10
DNone
Attempts:
2 left
💡 Hint

Think about what doubling 5 means mathematically.

Configuration
intermediate
2:00remaining
Which option correctly registers a Python UDF in Snowflake using Snowpark?

Select the code snippet that correctly registers a Python UDF named add_one that adds 1 to an integer input.

Asession.udf.add('add_one', lambda x: x + 1, IntegerType())
Bsession.udf.register(lambda x: x + 1, return_type=IntegerType(), input_types=[IntegerType()], name='add_one')
Csession.create_udf('add_one', lambda x: x + 1, IntegerType())
Dsession.udf.create('add_one', lambda x: x + 1, IntegerType())
Attempts:
2 left
💡 Hint

Look for the method that registers a UDF with name, input, and return types.

Architecture
advanced
2:00remaining
Which Snowpark UDF design best supports processing large datasets efficiently?

Choose the UDF design that optimizes performance when applied to large Snowflake tables.

AA vectorized UDF that processes batches of rows in parallel
BA scalar UDF that processes one row at a time without vectorization
CA UDF that writes intermediate results to external storage during execution
DA UDF that uses global variables to store state across calls
Attempts:
2 left
💡 Hint

Think about how batch processing can improve speed over row-by-row processing.

security
advanced
2:00remaining
What is the best practice to secure Snowpark UDFs that access sensitive data?

Which option ensures that a Snowpark UDF accessing sensitive data follows security best practices?

AGrant the UDF owner minimal privileges and use role-based access control
BEmbed credentials inside the UDF code for direct database access
CAllow public access to the UDF for easier sharing
DDisable all logging to hide UDF activity
Attempts:
2 left
💡 Hint

Consider how to limit access and track usage securely.

🧠 Conceptual
expert
2:00remaining
What error will this Snowpark UDF raise when called with a string input?

Consider this UDF that expects an integer input but is called with a string:

from snowflake.snowpark.functions import udf

@udf
def square(x: int) -> int:
    return x * x

result = square('text').collect()[0][0]

What error occurs?

ANo error, returns 'texttext'
BValueError: invalid literal for int() with base 10: 'text'
CSnowparkUDFExecutionError: Input type mismatch
DTypeError: unsupported operand type(s) for *: 'str' and 'str'
Attempts:
2 left
💡 Hint

Think about what happens when multiplying a string by a string in Python.