liveBook · Manning

Date dimension

As explained in Snowflake Data Engineering

A date dimension is an analytical table containing one row per calendar date and associated descriptive or calendar attributes.

A date dimension is a Snowflake table built from consecutive dates and descriptive flags. In a demand-planning pipeline, it can be joined with order information so holiday periods can be considered when preparing for changing customer demand. section 6.2 section 6.4

Build a holiday-aware date dimension incrementally:

  • Generate consecutive dates from a chosen start date and number of days with Python date arithmetic. section 6.4
  • Evaluate each date against a country-specific holiday calendar and pair the date with a Boolean holiday flag. section 6.4
  • Create a Snowpark DataFrame with a typed schema: day as DateType and holiday_flg as BooleanType. section 6.5
  • Trigger an action such as collect() to inspect lazily evaluated data, then save the DataFrame as a Snowflake table. section 6.5

Five-day DIM_DATE output

Starting at 2023-01-01 produces rows for January 1 through January 5. The first two dates are flagged True for US holidays, while January 3 through January 5 are False. The resulting DataFrame is written to DIM_DATE with overwrite mode. section 6.4 section 6.5

Listing 6.9 Constructing a data frame and defining the data structure
# create a data frame from the holiday_flags list of lists 
# and define the schema as two columns:
# - column named "day" with data type DateType
# - column named "holiday_flg" with data type BooleanType
df = my_session.create_dataframe(
    holiday_flags, 
    schema = StructType(
        [StructField("day", DateType()), 
         StructField("holiday_flg", BooleanType())])
    )

This schema definition turns date-and-flag records into a typed Snowpark DataFrame before the dimension is persisted. section 6.5

How Snowflake Data Engineering covers it

How deep it goes
Builds the dimension step by step from generated dates through a typed DataFrame and persisted table.
Examples
Uses US holiday flags for January 1–5, 2023 and writes the rows to DIM_DATE.
What it assumes
Uses Python date handling, package installation, Snowflake connectivity, and Snowpark schema types.
What you can do after
Build it from scratch as a typed Snowpark table containing dates and country-specific holiday flags.
How it connects
Connects Snowpark Python, stored procedures, DataFrames, lazy execution, and the holidays library.

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.