0
0
Snowflakecloud~10 mins

Stored procedures in Python 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 stored procedure in Snowflake using Python.

Snowflake
CREATE OR REPLACE PROCEDURE my_proc() RETURNS STRING LANGUAGE PYTHON
RUNTIME_VERSION = '3.8'
PACKAGES = ('snowflake-snowpark-python')
HANDLER = 'run'
AS $$
    def run(session):
        return [1]
$$;
Drag options to blanks, or click blank then click option'
A'Hello from Snowflake!'
Bprint('Hello')
Creturn 'Hello'
DHello
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of return
Returning a bare word without quotes
Returning a Python statement instead of a string
2fill in blank
medium

Complete the code to define a stored procedure that accepts an integer parameter and returns its square.

Snowflake
CREATE OR REPLACE PROCEDURE square_num(num INT) RETURNS INT LANGUAGE PYTHON
RUNTIME_VERSION = '3.8'
PACKAGES = ('snowflake-snowpark-python')
HANDLER = 'run'
AS $$
    def run(session, num):
        return num [1] num
$$;
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of *
Using / which divides
Using - which subtracts
3fill in blank
hard

Fix the error in the stored procedure code that returns the length of a string parameter.

Snowflake
CREATE OR REPLACE PROCEDURE str_length(s STRING) RETURNS INT LANGUAGE PYTHON
RUNTIME_VERSION = '3.8'
PACKAGES = ('snowflake-snowpark-python')
HANDLER = 'run'
AS $$
    def run(session, s):
        return [1](s)
$$;
Drag options to blanks, or click blank then click option'
Alen
Blength
Csize
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using length instead of len
Using size or count which are not Python built-ins for length
4fill in blank
hard

Fill both blanks to create a stored procedure that returns the uppercase version of a string parameter.

Snowflake
CREATE OR REPLACE PROCEDURE to_uppercase(s STRING) RETURNS STRING LANGUAGE PYTHON
RUNTIME_VERSION = '3.8'
PACKAGES = ('snowflake-snowpark-python')
HANDLER = 'run'
AS $$
    def run(session, s):
        return s.[1]() [2] ''
$$;
Drag options to blanks, or click blank then click option'
Aupper
B+
C-
Dlower
Attempts:
3 left
💡 Hint
Common Mistakes
Using lower() instead of upper()
Using - instead of + for concatenation
5fill in blank
hard

Fill the blanks to create a stored procedure that returns a dictionary with keys as characters and values as their counts in the input string.

Snowflake
CREATE OR REPLACE PROCEDURE char_count(s STRING) RETURNS VARIANT LANGUAGE PYTHON
RUNTIME_VERSION = '3.8'
PACKAGES = ('snowflake-snowpark-python')
HANDLER = 'run'
AS $$
    def run(session, s):
        counts = [1]()
        for c in s:
            counts[c] = counts.get(c, 0) [2] 1
        return counts
$$;
Drag options to blanks, or click blank then click option'
Adict
B+
C-
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using list() instead of dict()
Using - instead of + for increment
Not initializing the dictionary