0
0
Snowflakecloud~20 mins

Snowpark for Python basics in Snowflake - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Snowpark Python 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 Python code snippet?

Consider the following Snowpark Python code that creates a DataFrame and applies a filter:

from snowflake.snowpark import Session

session = Session.builder.configs({"account": "xyz", "user": "abc", "password": "***", "role": "SYSADMIN", "warehouse": "COMPUTE_WH", "database": "TEST_DB", "schema": "PUBLIC"}).create()
df = session.create_dataframe([(1, 'apple'), (2, 'banana'), (3, 'cherry')], schema=["id", "fruit"])
filtered_df = df.filter(df["id"] > 1)
result = filtered_df.collect()

What will result contain?

Snowflake
from snowflake.snowpark import Session

session = Session.builder.configs({"account": "xyz", "user": "abc", "password": "***", "role": "SYSADMIN", "warehouse": "COMPUTE_WH", "database": "TEST_DB", "schema": "PUBLIC"}).create()
df = session.create_dataframe([(1, 'apple'), (2, 'banana'), (3, 'cherry')], schema=["id", "fruit"])
filtered_df = df.filter(df["id"] > 1)
result = filtered_df.collect()
A[]
B[Row(id=1, fruit='apple')]
C[Row(id=2, fruit='banana'), Row(id=3, fruit='cherry')]
DSyntaxError due to incorrect filter syntax
Attempts:
2 left
💡 Hint

Remember that filter keeps rows where the condition is true.

🧠 Conceptual
intermediate
1:30remaining
Which Snowpark Python method creates a DataFrame from a local list?

You want to create a Snowpark DataFrame from a Python list of tuples. Which method should you use?

Asession.new_dataframe()
Bsession.create_dataframe()
Csession.load_table()
Dsession.read_csv()
Attempts:
2 left
💡 Hint

Look for the method that directly accepts Python data.

Architecture
advanced
1:30remaining
What happens when you call collect() on a Snowpark DataFrame?

In Snowpark for Python, what is the behavior of the collect() method on a DataFrame?

AIt executes the query and returns all rows as a list of Row objects to the client.
BIt streams the data row by row without loading all into memory.
CIt saves the DataFrame as a table in the database without returning data.
DIt only returns the schema of the DataFrame without executing the query.
Attempts:
2 left
💡 Hint

Think about what happens when you want to get all data from Snowflake to Python.

security
advanced
1:30remaining
Which practice improves security when connecting to Snowflake with Snowpark for Python?

When configuring a Snowpark Session in Python, which option is the most secure way to handle authentication?

AUsing environment variables or external secrets manager for credentials
BSharing credentials in plain text over email
CHardcoding username and password directly in the script
DUsing default public credentials without authentication
Attempts:
2 left
💡 Hint

Think about how to keep passwords safe and not expose them in code.

Best Practice
expert
2:00remaining
What is the best practice for managing Snowpark Session lifecycle in a Python application?

In a Python app using Snowpark, how should you manage the Session object to optimize resource use and avoid errors?

ACreate a new Session for every query and close it immediately after
BNever close the Session to keep it always open
CCreate multiple Sessions in parallel without closing any
DCreate one Session per application run and reuse it for all queries, closing it at the end
Attempts:
2 left
💡 Hint

Consider resource efficiency and connection limits.