liveBook · Manning

Data frame

As explained in Snowflake Data Engineering

A data frame is a tabular data structure that represents a relational dataset and supports operations such as selection, filtering, ordering, grouping, and combining.

A Snowpark data frame is the core tabular abstraction for a relational data set. It is used to query and transform data with methods for selection, filtering, ordering, grouping, combining, and joins. Snowpark translates those operations into SQL for execution by Snowflake’s server-side SQL engine, so developers can choose data-frame methods or SQL according to their workflow. section 6.1 section 6.8

Data frames are lazily evaluated. Constructing one or chaining transformations does not immediately execute work; execution is triggered by an action such as collect(), count(), show(), save_as_table(), or copy_into_table(). Deferring execution lets a pipeline batch operations, generally reducing data transferred between client and server and improving performance. section 6.3.4 section 6.5

Create and use a data frame in a pipeline by:

  • Creating it from Python values with create_dataframe(), while declaring columns and types through StructType and StructField. section 6.5
  • Reading staged CSV data with read.schema(...).csv(...), supplying a schema when column control is required. section 6.6
  • Retrieving a Snowflake table with session.table() and combining data frames with join(). section 6.7
  • Materializing results as a table with save_as_table(), loading with copy_into_table(), or publishing a view with create_or_replace_view(). section 6.5 section 6.6 section 6.7

Add a holiday flag to staged orders

Load ORDERS_STG and DIM_DATE as data frames, then left-join ORDERS_STG.DELIVERY_DATE to DIM_DATE.DAY. The resulting data frame adds the date dimension’s holiday flag to each order. Rather than materializing another physical table, create the ORDERS_HOLIDAY_FLG view from that result and query it through SQL when needed. section 6.7

Construct and save a date dimension

Build a data frame from a Python list of holiday flags and an explicit two-column schema: day as DateType and holiday_flg as BooleanType. Call collect() to inspect rows, then write the result as DIM_DATE with overwrite mode. The action is required because printing the data-frame object alone does not return its rows. section 6.5

A data frame can also carry structured results from procedural work. CSV returned from an earlier operation can be split into rows and fields, converted with create_dataframe() using a declared schema, appended to a Snowflake table, and returned from a stored procedure for immediate inspection. This makes the data frame a boundary between transformed application output and relational storage. section 7.4.3 section 7.5

Figure 6.1 The Snowpark Python high-level architecture consists of the client API, which includes methods for querying and transforming data frames and defining functions and stored procedures. Data frame queries are internally translated to SQL and sent to the Snowflake server-side SQL engine for execution. Code that defines functions and stored procedures is serialized and sent to the Snowflake server, where it executes in a secure sandbox, using Python built-in packages if needed.
figure

Inspect the architecture to see the division between client-side data-frame methods and server-side SQL execution, alongside the separate path used for functions and stored procedures. section 6.1

How Snowflake Data Engineering covers it

How deep it goes
Explains construction, schemas, lazy actions, CSV ingestion, joins, tables, and views without detailing SQL translation internals.
Examples
Demonstrates holiday-date dimensions, staged bakery orders, an orders-date join, and CSV extracted from email output.
What it assumes
Assumes a Snowflake connection session and teaches data-frame construction from Python lists or staged CSV files.
What you can do after
Apply it via Snowpark Python to create, transform, inspect, join, and save relational data sets.
How it connects
Connects Snowpark data frames to SQL, sessions, schemas, Snowflake tables, views, CSV files, and stored procedures.

Also explained in

Compare how 19 books explain data frame →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Snowflake Data Engineering. The section links point to the parts of the book it draws on.