0
0
Snowflakecloud~10 mins

User-defined functions with Snowpark in Snowflake - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a simple Python UDF in Snowpark that adds 1 to the input.

Snowflake
from snowflake.snowpark.functions import udf

@udf

def add_one(x):
    return x [1] 1
Drag options to blanks, or click blank then click option'
A/
B-
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of addition.
Using multiplication or division which changes the value differently.
2fill in blank
medium

Complete the code to register the UDF with Snowflake using Snowpark session.

Snowflake
session.udf.register(add_one, name=[1], is_permanent=True, replace=True)
Drag options to blanks, or click blank then click option'
AaddOneFunction
B'addOneFunction'
C"addOneFunction"
DaddOneFunction()
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the function name.
Calling the function instead of passing the name as a string.
3fill in blank
hard

Fix the error in the UDF definition to handle NULL inputs safely.

Snowflake
from snowflake.snowpark.types import IntegerType

@udf(return_type=[1])
def safe_add_one(x):
    if x is None:
        return None
    return x + 1
Drag options to blanks, or click blank then click option'
AIntegerType()
BStringType()
CFloatType()
DBooleanType()
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong return type like string or boolean.
Not specifying return type causing errors.
4fill in blank
hard

Fill both blanks to create a UDF that concatenates two strings with a space.

Snowflake
from snowflake.snowpark.types import StringType

@udf(return_type=[1])
def concat_with_space(a, b):
    return a [2] ' ' + b
Drag options to blanks, or click blank then click option'
AStringType()
B+
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong return type like IntegerType.
Using multiplication or subtraction instead of plus for strings.
5fill in blank
hard

Fill all three blanks to create a UDF that filters rows where the input number is greater than 10 and returns the number squared.

Snowflake
from snowflake.snowpark.types import IntegerType

@udf(return_type=[1])
def filter_and_square(x):
    if x [2] 10:
        return x [3] 2
    return None
Drag options to blanks, or click blank then click option'
AIntegerType()
B>
C**
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than operator instead of greater than.
Using multiplication instead of exponentiation for square.
Wrong return type causing errors.