Bird
Raised Fist0
Snowflakecloud~10 mins

Why Snowpark brings code to the data in Snowflake - Test Your Understanding

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

Complete the code to create a Snowpark session.

Snowflake
from snowflake.snowpark import Session

connection_parameters = {
    "account": "[1]",
    "user": "user_name",
    "password": "password",
    "role": "SYSADMIN",
    "warehouse": "COMPUTE_WH",
    "database": "MY_DB",
    "schema": "PUBLIC"
}
session = Session.builder.configs(connection_parameters).create()
Drag options to blanks, or click blank then click option'
Amy_warehouse
Bmy_account
Cmy_database
Dmy_schema
Attempts:
3 left
💡 Hint
Common Mistakes
Using warehouse or database names instead of the account identifier.
Leaving the account parameter empty.
2fill in blank
medium

Complete the code to create a DataFrame from a Snowflake table.

Snowflake
df = session.table("[1]")
Drag options to blanks, or click blank then click option'
Amy_table
Bmy_warehouse
Cmy_database
Dmy_schema
Attempts:
3 left
💡 Hint
Common Mistakes
Using warehouse or database names instead of the table name.
Omitting quotes around the table name.
3fill in blank
hard

Fix the error in the code to apply a filter on the DataFrame.

Snowflake
filtered_df = df.filter(df["AGE"] [1] 30)
Drag options to blanks, or click blank then click option'
A==
B=>
C=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' or '>'.
Using '=>' which is invalid syntax.
4fill in blank
hard

Fill both blanks to select columns and show the first 5 rows.

Snowflake
result = df.select([1]).limit([2]).collect()
Drag options to blanks, or click blank then click option'
A"NAME", "AGE"
B5
C10
D"SALARY"
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting only one column when multiple are needed.
Using limit(10) instead of limit(5).
5fill in blank
hard

Fill all three blanks to create a new column with a calculation and filter rows.

Snowflake
from snowflake.snowpark.functions import col

new_df = df.withColumn("AGE_PLUS_SALARY", col("AGE") [1] col("SALARY")).filter(col("AGE_PLUS_SALARY") [2] [3])
Drag options to blanks, or click blank then click option'
A+
B>
C1000
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' for addition.
Using '<' instead of '>' for filtering.
Using a wrong threshold value.

Practice

(1/5)
1. What is the main benefit of Snowpark bringing code to the data inside Snowflake?
easy
A. It increases data duplication across systems.
B. It requires exporting data to external servers.
C. It only supports SQL queries.
D. It reduces data movement and improves performance.

Solution

  1. Step 1: Understand Snowpark's design

    Snowpark runs code inside Snowflake, close to the data storage.
  2. Step 2: Identify benefits of running code near data

    This reduces the need to move large data sets, saving time and resources.
  3. Final Answer:

    It reduces data movement and improves performance. -> Option D
  4. Quick Check:

    Code near data = less data movement [OK]
Hint: Code runs inside Snowflake, so data stays put [OK]
Common Mistakes:
  • Thinking data must be exported to run code
  • Believing Snowpark only supports SQL
  • Assuming data is duplicated across systems
2. Which of the following is the correct way to create a Snowpark session in Python?
easy
A. session = SnowflakeSession.create(connection_parameters)
B. session = snowpark.connect(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 Python session creation syntax

    Snowpark uses Session.builder.configs(...).create() to start a session.
  2. Step 2: Match the correct method call

    session = snowflake.snowpark.Session.builder.configs(connection_parameters).create() matches the official syntax for creating a session in Snowpark Python API.
  3. Final Answer:

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

    Session.builder.configs(...).create() = correct syntax [OK]
Hint: Look for builder.configs(...).create() pattern [OK]
Common Mistakes:
  • Using incorrect method names like connect or connect_snowpark
  • Missing builder or configs in the call
  • Confusing Snowpark session with generic Snowflake connection
3. Given this Snowpark Python code snippet:
df = session.table('EMPLOYEES')
filtered = df.filter(df['DEPARTMENT'] == 'SALES')
count = filtered.count()

What does count represent?
medium
A. The number of rows where DEPARTMENT is 'SALES'.
B. The number of columns in the EMPLOYEES table.
C. The total number of rows in the EMPLOYEES table.
D. The number of distinct departments in EMPLOYEES.

Solution

  1. Step 1: Understand the filter operation

    The code filters rows where DEPARTMENT equals 'SALES'.
  2. Step 2: Understand the count method

    Count returns the number of rows in the filtered DataFrame.
  3. Final Answer:

    The number of rows where DEPARTMENT is 'SALES'. -> Option A
  4. Quick Check:

    filter + count = rows matching condition [OK]
Hint: Filter then count means count matching rows [OK]
Common Mistakes:
  • Thinking count returns total rows without filter
  • Confusing count with number of columns
  • Assuming count returns distinct values
4. You wrote this Snowpark code but get an error:
df = session.table('EMPLOYEES')
filtered = df.filter(df.DEPARTMENT = 'SALES')
count = filtered.count()

What is the error and how to fix it?
medium
A. Add parentheses around the filter condition.
B. Use '==' for comparison instead of '=' in the filter condition.
C. Rename 'DEPARTMENT' column to lowercase.
D. Change 'filter' to 'where' method.

Solution

  1. Step 1: Identify the filter condition syntax

    The filter uses '=' which is assignment, not comparison.
  2. Step 2: Correct the comparison operator

    Use '==' to compare column values in Snowpark expressions.
  3. Final Answer:

    Use '==' for comparison instead of '=' in the filter condition. -> Option B
  4. Quick Check:

    Comparison needs '==' not '=' [OK]
Hint: Use '==' for equality checks in filters [OK]
Common Mistakes:
  • Using single '=' instead of '==' in conditions
  • Thinking 'where' is required instead of 'filter'
  • Assuming column names must be lowercase
5. You want to process a large dataset using Snowpark and Python. Why is it better to write your transformation code in Snowpark rather than exporting data to your local machine?
hard
A. Snowpark runs code inside Snowflake, reducing data transfer and improving security.
B. Exporting data is faster and more secure than running code inside Snowflake.
C. Snowpark only supports SQL, so Python code must run locally.
D. Local processing avoids Snowflake compute costs.

Solution

  1. Step 1: Understand Snowpark's architecture

    Snowpark runs code inside Snowflake close to the data storage.
  2. Step 2: Benefits of running code inside Snowflake

    This reduces data transfer time and keeps data secure by not moving it outside.
  3. Final Answer:

    Snowpark runs code inside Snowflake, reducing data transfer and improving security. -> Option A
  4. Quick Check:

    Code near data = less transfer + better security [OK]
Hint: Run code inside Snowflake to keep data secure and fast [OK]
Common Mistakes:
  • Thinking exporting data is faster or safer
  • Believing Snowpark only supports SQL
  • Ignoring Snowflake compute costs benefits
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