CertSafari
    Snowflake SnowPro Advanced: Data Engineer (DEA-C02)· Lessons

    Domain 5 · Lesson 22/22

    Snowpark DataFrames: architecture, sessions, transformations and actions

    Use Snowpark for data trans- formations.

    19 min read
    3.57% of exam
    11 sources
    Published 20 Oct 2026
    Docs as of 18 Oct 2026

    What you will be able to do

    • Explain how Snowpark pushes DataFrame work down to Snowflake compute instead of moving data to the client
    • Describe the client-side and server-side parts of the Snowpark architecture and what crosses between them
    • Predict when a chain of DataFrame calls actually sends SQL to Snowflake
    • Create a Session and build DataFrames from a table, local values, a range, a staged file and a SQL query
    • Filter, select, join and aggregate data with Column expressions, then trigger the work with an action

    Key concept

    Lazily evaluated DataFrame — A Snowpark DataFrame is a description of a query, not a set of fetched rows. Transformation calls add to the SQL it will generate. Snowflake runs that SQL only when an action such as collect or count is called.

    1.Where Snowpark code actually runs

    Snowpark is a client library that lets you write data transformations in a general-purpose language while the work itself runs inside Snowflake. Snowflake ships Snowpark libraries for Java, Python and Scala. You can write the code in local tools such as Jupyter, VS Code or IntelliJ, and in Snowsight Python worksheets. Wherever you write it, the processing happens in Snowflake.

    The design idea is pushdown. Snowpark pushes all operations down to the Snowflake engine, including Snowflake UDFs, so data stays in Snowflake rather than travelling to the machine running your script. Running a large table through a Snowpark pipeline from a laptop does not stream the table to the laptop. The laptop sends instructions, and a virtual warehouse does the heavy work.

    Pushdown also means there is no extra infrastructure to run. Unlike the Snowflake Connector for Spark, Snowpark needs no separate compute cluster outside Snowflake: all computation happens inside Snowflake, and Snowflake handles scaling and compute management.

    What the client does provide is language constructs for building SQL. You don't write 'select column_name' as a string. You call a select method and pass column objects, so your IDE can offer code completion and type checking. Writing UDFs is covered in user-defined functions.

    The architecture splits into a client half and a server half. The client half is the library you install, with a Session that connects to Snowflake and DataFrame objects, the core abstraction, that describe the data you want and the operations to apply. The server half is the Snowflake engine. Three things cross between them: the SQL that DataFrame calls generate, going to the server; the code of any UDF, which the library uploads to an internal stage so it runs next to the data; and the results, which come back only when an action asks for them. The same applies to whole pipelines: Snowpark code can be written as a stored procedure and scheduled as a task, so no client machine has to stay involved.

    Benefits of developing with Snowpark
    PropertySnowpark
    Where transformations executePushed down to the Snowflake engine, including Snowflake UDFs
    External compute clusterNot required; all computations are done within Snowflake
    Scale and compute managementHandled by Snowflake
    Authoring toolsLocal tools such as Jupyter, VS Code, or IntelliJ

    Checkpoint 1 of 9· Check yourself

    A data engineer runs a Snowpark Python pipeline from VS Code on their laptop. It filters and aggregates a multi-terabyte Snowflake table and calls a Snowpark UDF. Where does the processing happen?

    Checkpoint 2 of 9· Exam question

    A team is deciding between writing a transformation pipeline as raw SQL executed through a database driver versus writing it with the Snowpark Python DataFrame API. Which statement correctly describes a core architectural property of Snowpark that should inform this decision?

    Sources123

    2.Lazy evaluation: transformations build SQL, actions run it

    A DataFrame behaves like a query that has been written but not yet run. Building one is a three-step process:

    1. Construct a DataFrame from a data source.
    2. Describe the transformation: columns to select, rows to filter, sorting and grouping.
    3. Call an action method such as collect(). Only this step makes Snowflake run anything.

    Transformation methods such as filter and select do not retrieve data. They only change how the eventual SQL statement will be built. So an empty query history after a long chain of calls is normal. It is not a suspended warehouse, a batching timer or a missing registration step. The first entry appears when an action runs. Before that, there is no SQL to run.

    Building the DataFrame sends nothing to Snowflake; collect() runs the querypython
    >>> # Create a DataFrame with the "id" and "name" columns from the "sample_product_data" table.
    >>> # This does not execute the query.
    >>> df = session.table("sample_product_data").select(col("id"), col("name"))
    
    >>> # Send the query to the server for execution and
    >>> # return a list of Rows containing the results.
    >>> results = df.collect()

    Laziness has a practical benefit. Snowpark can postpone execution until late in the pipeline and combine many operations into a single one, so less data moves between client and database and performance improves. What a lazy DataFrame does know up front is its shape: it holds the column definitions of its source, and reading its schema property returns them without an action. The rows are different. They are not retrieved until you call an action method.

    Checkpoint 3 of 9· Fill the gap

    Building this DataFrame sends nothing to Snowflake. Which method call in the last line makes Snowflake run the query and return the rows?

    >>> # Create a DataFrame with the "id" and "name" columns from the "sample_product_data" table.
    >>> # This does not execute the query.
    >>> df = session.table("sample_product_data").select(col("id"), col("name"))
    
    >>> # Send the query to the server for execution and
    >>> # return a list of Rows containing the results.
    >>> results = df. ? ()

    Checkpoint 4 of 9· Exam question

    A data engineer writes a Python script that builds a Snowpark DataFrame by chaining .filter(), .select(), and .with_column() calls against a table. When the engineer checks the Snowflake query history immediately after the chain, no query has run yet. A query only appears once the engineer calls .collect() at the end of the script. What explains this behavior?

    Sources415

    3.Creating a Session and constructing DataFrames

    Every Snowpark program starts with a Session, the connection to Snowflake that all DataFrames are built from. Snowpark authenticates with the same mechanisms and connection parameters as the Snowflake Connector for Python. One way to connect is to put account, user, password, role, warehouse, database and schema into a Python dict, pass it to Session.builder.configs, and call create(). For the account, use your account identifier without the snowflakecomputing.com suffix.

    Building a Session from a dictionary of connection parameterspython
    connection_parameters = {
      "account": "<your snowflake account>",
      "user": "<your snowflake user>",
      "password": "<your snowflake password>",
      "role": "<your snowflake role>",  # optional
      "warehouse": "<your snowflake warehouse>",  # optional
      "database": "<your snowflake database>",  # optional
      "schema": "<your snowflake schema>",  # optional
    }
    
    new_session = Session.builder.configs(connection_parameters).create()

    Keeping credentials out of code is the other common pattern. Define a named connection such as [myconnection] in a connections.toml file, then write Session.builder.config("connection_name", "myconnection").create(). Adding a second entry, for example [myconnection_test] with its own warehouse and database, lets the same script target a test environment by changing only the connection name.

    Each Session method or property builds a DataFrame from a different kind of source. The choice affects tooling as much as results. session.sql() can run SELECT statements against tables and staged files. However, table and the read property give better syntax highlighting, error highlighting and code completion in development tools, so use them when they fit.

    Session entry points for constructing a DataFrame in Snowpark Python
    Source of dataCallExample
    Table, view, or streamsession.tablesession.table("sample_product_data")
    Values held in the clientsession.create_dataframesession.create_dataframe([1, 2, 3, 4]).to_df("a")
    A range of valuessession.rangesession.range(1, 10, 2).to_df("a")
    A file in a stagesession.read (DataFrameReader)session.read.json("@my_stage2/data1.json")
    Results of a SQL querysession.sqlsession.sql("SELECT name from sample_product_data")

    create_dataframe accepts several shapes of input. You can pass a flat list renamed with to_df, a list of lists with schema=["a", "b", "c", "d"], Row(a=1, b=2, c=3, d=4) objects, or a StructType of StructFields that fixes each column's type. For staged files, session.read returns a DataFrameReader. Call the method that matches the file format, and optionally call .schema(...) before .csv(...) to declare the columns. Loading those files into tables is covered in loading data.

    Checkpoint 5 of 9· Check yourself

    During code review, you see a Snowpark Python script that builds every DataFrame with session.sql(): one SELECTs from the ORDERS table, and another SELECTs from a CSV file in a stage. What should the reviewer recommend?

    Sources64

    4.Filtering, selecting and joining with Column objects

    Transformation methods identify columns through Column objects, not strings of SQL. In Python, col("name") from snowflake.snowpark.functions creates one. Comparisons and arithmetic on Column objects produce new Column expressions, and you pass those to filter, select or join. For example, session.table("sample_product_data").filter(col("id") == 1) uses the Column == operator for an equality check and keeps only the row with ID 1. where is an alias of filter.

    Compound conditions follow the same rule: build them as one Column expression and pass it to filter. Arithmetic works inside a condition, so filter((col("key") + col("category_id")) < 10) is the equivalent of WHERE key + category_id < 10. To require two conditions at once, connect them with the & operator, as in filter((col("id") > 5) & (col("key") < 4)). Put each comparison in its own parentheses, so each is evaluated as a condition of its own before & combines them; without the parentheses the operators can group differently than you intend. Some patterns look plausible but are wrong. limit caps the number of rows; it does not take column conditions. Grouping methods aggregate rows rather than filter them.

    Every transformation returns a new DataFrame and leaves the original unchanged, which is why chaining works. df.filter(...) does not modify df. If you call df.filter(...) and discard the result, then df.show() prints unfiltered rows. Assign the result, or keep chaining from it.

    Other manipulation calls follow the same pattern and each returns a new DataFrame. sort orders the rows by a column, and limit keeps only the first rows of the sorted result, so df.sort(col("category_id")).limit(2) is ORDER BY category_id LIMIT 2. Renaming happens on the Column: col("id").alias("item_id") inside select is SELECT id AS item_id, and as_ does the same job in Python.

    Joins need a way to say which DataFrame a column belongs to when both sides share a name. DataFrame.col creates a Column bound to a specific DataFrame. Take two small DataFrames that both have a key column, with value1 on the left and value2 on the right:

    Two DataFrames that share a key columnpython
    # Create two DataFrames to join
    df_lhs = session.create_dataframe([["a", 1], ["b", 2]], schema=["key", "value1"])
    df_rhs = session.create_dataframe([["a", 3], ["b", 4]], schema=["key", "value2"])

    Because key exists on both sides, each reference names its DataFrame, and == compares them. Selecting df_lhs["key"].as_("key") keeps a single key column in the output:

    Joining on a Column expression with DataFrame.colpython
    df_lhs.join(df_rhs, df_lhs.col("key") == df_rhs.col("key")).select(df_lhs["key"].as_("key"), "value1", "value2").show()

    When both DataFrames have the same column to join on, passing a list of column names is more convenient and needs no explicit Column comparison:

    The shortcut for joining on a shared column namepython
    df_lhs.join(df_rhs, ["key"]).show()

    Joining a DataFrame to itself needs one more step in Snowpark Java and Scala: the same DataFrame on both sides raises an error about ambiguous column references, so join it to a clone() of itself instead. Snowflake treats unquoted names as upper case, so col("id123") and col("ID123") refer to the same column.

    SQL built-in functions are available as Python functions in snowflake.snowpark.functions. They return Column objects, so they fit anywhere a column does. If a system function has no wrapper, call_function("radians", col("col1")) or function("radians") calls it by name and returns a Column that can go into select or filter.

    A system function wrapper (upper) applied inside select, with an alias, then evaluatedpython
    # Import the upper function from the functions module.
    from snowflake.snowpark.functions import upper, col
    session.table("sample_product_data").select(upper(col("name")).alias("upper_name")).collect()

    Checkpoint 6 of 9· Check yourself

    Consider this Snowpark Python code: df = session.table("sample_product_data") df.filter(col("id") == 1) df.show() What does df.show() print?

    Checkpoint 7 of 9· Exam question

    A data engineer needs to filter a Snowpark DataFrame named orders_df down to rows where the order_status column equals 'SHIPPED' and the order_total column is greater than 100. Which approach correctly expresses this filter using the Snowpark Python API?

    Sources47589

    5.Aggregating and triggering execution with actions

    Aggregation in Snowpark is a transformation like any other: you group a DataFrame, aggregate it, and Snowflake computes the grouped result only when an action runs. In Snowpark Python, group_by takes the grouping columns and returns a grouped DataFrame, and count() on it yields the row count of each group. SQL aggregate functions such as SUM, MIN and MAX have equivalents in snowflake.snowpark.functions, like every other system-defined function.

    A worksheet example shows the whole shape. It aggregates the TASK_HISTORY view in the ACCOUNT_USAGE schema by scheduled time and state. The chain first filters out rows whose state is SKIPPED, then groups:

    The grouping step of a filter, group and count chainpython
    .group_by(("SCHEDULED_TIME"), "STATE").count()

    The chain ends with .write.mode("overwrite").save_as_table(outputTableName). That final call is the action: nothing before it ran, and the grouped rows land in a Snowflake table instead of coming back to the client.

    Python users who prefer pandas syntax have a separate option, pandas on Snowflake, which runs pandas code directly on data in Snowflake. It is a different API from the Snowpark DataFrame. In the next snippet, train is the TITANIC table loaded with train = pd.read_snowflake('TITANIC'), and Sex and Survived are two of its columns.

    A groupby aggregation written with pandas on Snowflakepython
    # Perform groupby aggregation with Snowpark pandas
    survived_per_gender = train.groupby(['Sex','Survived']).agg(count_survived=('Survived', 'count')).reset_index()

    Actions are where the work gets done and paid for, and each one returns something different. Choose by what you need at the end. collect brings back every row, so it suits small results. count returns only the row count. show prints a 10-row preview by default, which is enough to check a transformation but is not a way to export data. save_as_table writes the result into Snowflake, so the rows never come back to the client. Snowpark Java and Scala add toLocalIterator, which returns an Iterator of Row objects so a large result need not sit in memory at once, and cacheResult, which puts the results into a temporary table. Those two languages can also run actions asynchronously through async, which returns a TypedAsyncJob to check status and fetch results.

    DataFrame action methods in Snowpark Python and what each evaluation returns
    ClassActionWhat it does
    DataFramecollectEvaluates the DataFrame and returns the resulting dataset as an list of Row objects
    DataFramecountEvaluates the DataFrame and returns the number of rows
    DataFrameshowPrints the rows to the console, limited to 10 rows by default
    DataFrameWritersave_as_tableSaves the data in the DataFrame to the specified table

    Checkpoint 8 of 9· Check yourself

    An engineer's Snowpark pipeline groups and aggregates sales into about 500 region-and-product rows. They then call show() and pass the console output on as the finished report. What is wrong with this approach?

    Checkpoint 9 of 9· Fill the gap

    This worksheet chain counts task-history rows per scheduled time and state. Which call groups the rows before they are counted?

    . ? (("SCHEDULED_TIME"), "STATE").count()

    Sources1041128

    Sources

    (11)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Support for pushdown for all operations, including Snowflake UDFs.”
      ↩︎ Where Snowpark code actually runs
      “Snowflake currently provides Snowpark libraries for three languages: Java, Python, and Scala.”
      ↩︎ Where Snowpark code actually runs
      “No requirement for a separate cluster outside of Snowflake for computations.”
      ↩︎ Where Snowpark code actually runs
      “The core abstraction in Snowpark is the DataFrame, which represents a set of data and provides methods to operate on that data.”
      ↩︎ Where Snowpark code actually runs
      “This reduces the amount of data transferred between your client and the Snowflake database.”
      ↩︎ Lazy evaluation: transformations build SQL, actions run it
      “No requirement for a separate cluster outside of Snowflake for computations.”
      ↩︎ Exam trap 2
      “Snowpark pushes down all data transformation and heavy lifting to the Snowflake data cloud, enabling you to efficiently work with data of any size.”
      ↩︎ Checkpoint
      “you can perform an action that evaluates the DataFrame objects and sends the corresponding SQL statements to the Snowflake database for execution.”
      ↩︎ Prediction
    2. 2.
      “You can also automate data transformation and processing by writing stored procedures and scheduling those procedures as tasks in Snowflake.”
      ↩︎ Where Snowpark code actually runs
      “Run your pandas code directly on your data in Snowflake.”
      ↩︎ Aggregating and triggering execution with actions
    3. 3.
      “the Snowpark library uploads the code for your function to an internal stage”
      ↩︎ Where Snowpark code actually runs
    4. 4.
      “A DataFrame represents a relational dataset that is evaluated lazily: it only executes when a specific action is triggered.”
      ↩︎ Lazy evaluation: transformations build SQL, actions run it
      “Although the DataFrame does not yet contain the data from the table, the object does contain the definitions of the columns in the table.”
      ↩︎ Lazy evaluation: transformations build SQL, actions run it
      “using the table method and read property offer better syntax highlighting, error highlighting, and intelligent code completion in development tools.”
      ↩︎ Creating a Session and constructing DataFrames
      “To identify columns in these methods, use the col function or an expression that evaluates to a column.”
      ↩︎ Filtering, selecting and joining with Column objects
      “If both DataFrames have the same column to join on, you can use the following example syntax:”
      ↩︎ Filtering, selecting and joining with Column objects
      “You can also use the & operator to connect join expressions:”
      ↩︎ Filtering, selecting and joining with Column objects
      “DataFrameWriter | save_as_table | Saves the data in the DataFrame to the specified table.”
      ↩︎ Aggregating and triggering execution with actions
      “A DataFrame represents a relational dataset that is evaluated lazily: it only executes when a specific action is triggered.”
      ↩︎ Key concept
      “using the table method and read property offer better syntax highlighting, error highlighting, and intelligent code completion in development tools.”
      ↩︎ Exam trap 4
      “To print out the first 10 rows, call df_table.show()”
      ↩︎ Checkpoint
    5. 5.
      “The transformation methods simply specify how the SQL statement should be constructed.”
      ↩︎ Lazy evaluation: transformations build SQL, actions run it
      “Joining a DataFrame to itself can lead to incorrect results due to ambiguity of column references.”
      ↩︎ Filtering, selecting and joining with Column objects
      “When you specify a name, Snowflake considers the name to be in upper case.”
      ↩︎ Filtering, selecting and joining with Column objects
      “The transformation methods simply specify how the SQL statement should be constructed.”
      ↩︎ Exam trap 1
    6. 6.
      “The first step in using the library is establishing a session with the Snowflake database.”
      ↩︎ Creating a Session and constructing DataFrames
      “Pass this dictionary to the Session.builder.configs method to return a builder object that has these connection parameters.”
      ↩︎ Creating a Session and constructing DataFrames
    7. 8.
      “Each method returns a new DataFrame object that has been transformed.”
      ↩︎ Filtering, selecting and joining with Column objects
      “When specifying a filter, projection, join condition, etc., you can use Column objects in an expression.”
      ↩︎ Filtering, selecting and joining with Column objects
      “Evaluates the DataFrame and returns the number of rows.”
      ↩︎ Aggregating and triggering execution with actions
      “Saves the data in the DataFrame to the specified table.”
      ↩︎ Aggregating and triggering execution with actions
      “Each method returns a new DataFrame object that has been transformed.”
      ↩︎ Exam trap 3
      “Evaluates the DataFrame and prints the rows to the console. Note that this method limits the number of rows to 10 (by default).”
      ↩︎ Exam trap 5
      “Each method returns a new DataFrame object that has been transformed. (The method does not affect the original DataFrame object.)”
      ↩︎ Checkpoint
    8. 9.
      “If you need to call system-defined SQL functions, use the equivalent functions in the snowflake.snowpark.functions module.”
      ↩︎ Filtering, selecting and joining with Column objects
    9. 10.
      “aggregates the entries in the TASK_HISTORY view in the ACCOUNT_USAGE schema of the SNOWFLAKE database by scheduled time and state”
      ↩︎ Aggregating and triggering execution with actions

    Ready to test yourself?

    Practise the 12 questions on this subdomain.

    Spotted a mistake, or was something unclear? Tell us.