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
