liveBook · Manning

StructType

As explained in Snowflake Data Engineering

StructType is a Snowpark type that represents the complete schema of a structured record or table.

StructType defines the complete schema for a Snowpark DataFrame or structured record. It groups StructField declarations, pairing column names with types such as StringType, DateType, IntegerType, DecimalType, or BooleanType. section 7.4.3 section 6.6

Use StructType when moving locally prepared or staged data into Snowflake:

  • Declare fields in the expected order and assign each field an explicit Snowpark type. section 6.6
  • Pass the schema to session.create_dataframe for parsed rows, or to session.read.schema when reading a staged CSV file. section 7.4.3 section 6.6
  • Write the resulting DataFrame to a Snowflake table, appending rows when the pipeline must preserve existing data. section 7.4.3
  • Prefer an explicit schema when controlling column definitions matters; staged files can alternatively use INFER_SCHEMA. section 6.6

Schema-driven CSV ingestion

A Snowpark pipeline can define Customer as StringType, Order_date and Delivery_date as DateType, Baked_good_type as StringType, and Quantity as DecimalType. It then reads @orders_stage with that StructType and copies the DataFrame into ORDERS_STG. The same pattern can transform CSV output from an LLM into rows and append them to COLLECTED_ORDERS_FROM_EMAIL. section 6.6 section 7.4.3

Listing 6.13 Defining the schema
# define the schema for the CSV file
schema_for_csv = StructType(
        [StructField("Customer", StringType()), 
         StructField("Order_date", DateType()),
         StructField("Delivery_date", DateType()),
         StructField("Baked_good_type", StringType()),
         StructField("Quantity", DecimalType())
        ])

Shows a runnable StructType declaration for a five-column CSV schema. section 6.6

How Snowflake Data Engineering covers it

How deep it goes
Explains field-level type declarations and their use in DataFrame creation and CSV reading, while deferring schema inference to INFER_SCHEMA.
Examples
Uses order CSV schemas, generated LLM CSV rows, and a date dimension with date and Boolean fields.
What it assumes
Assumes basic Python and Snowpark session usage while demonstrating required data types and schema construction.
What you can do after
Apply it via Snowpark to create typed DataFrames and persist their rows in Snowflake tables.
How it connects
Connects StructType with Snowpark, StructField, DataFrame, CSV ingestion, INFER_SCHEMA, and Snowflake tables.

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.