Bird
Raised Fist0
Snowflakecloud~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of Snowpark for Python in Snowflake?
easy
A. To run Python code directly inside Snowflake for data processing
B. To create visual dashboards from Snowflake data
C. To export Snowflake data to external Python scripts only
D. To replace SQL queries with Java code

Solution

  1. Step 1: Understand Snowpark for Python's role

    Snowpark for Python allows running Python code inside Snowflake, enabling fast data processing close to the data.
  2. Step 2: Compare options to the main purpose

    Creating visual dashboards, exporting Snowflake data to external Python scripts only, and replacing SQL queries with Java code describe other unrelated tasks or languages, while running Python code directly inside Snowflake for data processing correctly states the main purpose.
  3. Final Answer:

    To run Python code directly inside Snowflake for data processing -> Option A
  4. Quick Check:

    Snowpark runs Python inside Snowflake = A [OK]
Hint: Snowpark runs Python code inside Snowflake, not outside [OK]
Common Mistakes:
  • Confusing Snowpark with visualization tools
  • Thinking Snowpark exports data only
  • Assuming Snowpark uses Java
2. Which of the following is the correct way to create a Snowpark session in Python?
easy
A. session = SnowflakeSession.connect(connection_parameters)
B. session = snowpark.Session.create(connection_parameters)
C. session = snowflake.snowpark.Session.builder.configs(connection_parameters).create()
D. session = snowflake.connect.snowpark(connection_parameters)

Solution

  1. Step 1: Recall Snowpark session creation syntax

    The correct method uses the builder pattern: snowflake.snowpark.Session.builder.configs(...).create()
  2. Step 2: Check each option's syntax

    Only session = snowflake.snowpark.Session.builder.configs(connection_parameters).create() matches the official Snowpark Python API syntax; others are incorrect or invalid.
  3. Final Answer:

    session = snowflake.snowpark.Session.builder.configs(connection_parameters).create() -> Option C
  4. Quick Check:

    Session builder pattern = B [OK]
Hint: Use Session.builder.configs(...).create() to start Snowpark session [OK]
Common Mistakes:
  • Using incorrect method names like connect()
  • Wrong module or class names
  • Missing builder pattern
3. Given the following Snowpark Python code, what will df.show() display?
df = session.table('EMPLOYEES').filter(col('AGE') > 30).select('NAME', 'AGE')
medium
A. A table showing NAME and AGE of employees older than 30
B. A table showing all columns of EMPLOYEES
C. An error because filter syntax is wrong
D. A table showing only AGE column for employees younger than 30

Solution

  1. Step 1: Understand the filter condition

    The filter selects rows where AGE > 30, so only employees older than 30 remain.
  2. Step 2: Understand the select columns

    Only NAME and AGE columns are selected to display.
  3. Final Answer:

    A table showing NAME and AGE of employees older than 30 -> Option A
  4. Quick Check:

    Filter AGE > 30 and select NAME, AGE = A [OK]
Hint: Filter then select columns before show() to see filtered data [OK]
Common Mistakes:
  • Confusing filter condition syntax
  • Expecting all columns to show
  • Thinking filter selects AGE < 30
4. What is wrong with this Snowpark Python code snippet?
df = session.table('SALES').filter(col('AMOUNT') < 1000).select('DATE', 'AMOUNT')
df.show()
medium
A. The filter condition should use > instead of <
B. The table name SALES is invalid
C. The show() method does not exist
D. The col function is not imported or defined

Solution

  1. Step 1: Check usage of col function

    The col function must be imported from snowflake.snowpark.functions to be used.
  2. Step 2: Verify other parts

    Table name SALES can be valid, filter condition < 1000 is valid, and show() exists on DataFrame.
  3. Final Answer:

    The col function is not imported or defined -> Option D
  4. Quick Check:

    Missing import for col() causes error = C [OK]
Hint: Always import col() from snowflake.snowpark.functions before filtering [OK]
Common Mistakes:
  • Forgetting to import col()
  • Assuming show() is missing
  • Confusing filter operators
5. You want to create a new DataFrame with employee names in uppercase from the EMPLOYEES table using Snowpark for Python. Which code snippet correctly does this?
hard
A. df = session.table('EMPLOYEES').select(upper('NAME'))
B. df = session.table('EMPLOYEES').select(upper(col('NAME')).alias('NAME_UPPER'))
C. df = session.table('EMPLOYEES').select('NAME').map(str.upper)
D. df = session.table('EMPLOYEES').select(col('NAME').upper())

Solution

  1. Step 1: Use upper() function with col()

    To convert a column to uppercase, use upper(col('NAME')) and alias it for clarity.
  2. Step 2: Check each option's correctness

    df = session.table('EMPLOYEES').select(upper(col('NAME')).alias('NAME_UPPER')) uses correct syntax with upper() and col(). df = session.table('EMPLOYEES').select(col('NAME').upper()) tries to call upper() on a column object, which is invalid. df = session.table('EMPLOYEES').select('NAME').map(str.upper) uses map on DataFrame, which is not supported. df = session.table('EMPLOYEES').select(upper('NAME')) passes string directly to upper(), which is incorrect.
  3. Final Answer:

    df = session.table('EMPLOYEES').select(upper(col('NAME')).alias('NAME_UPPER')) -> Option B
  4. Quick Check:

    Use upper(col('NAME')) with alias = D [OK]
Hint: Use upper(col('COLUMN')) and alias() to transform columns [OK]
Common Mistakes:
  • Calling upper() as a method on column
  • Using map() on DataFrame
  • Passing column name as string to upper()
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard