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
