finance-dbt/models/dw/dw.dim_date.sql
沈楠 0ffaacc353
All checks were successful
MJN/finance-dbt/pipeline/head This commit looks good
init: created
2024-04-12 19:07:47 +08:00

30 lines
686 B
SQL

/*
日期
*/
{{
config(
materialized='table',
engine='MergeTree',
order_by='date_id'
)
}}
SELECT
toUInt32(year(date) * 10000 + month(date) * 100 + day(date)) AS date_id,
date AS full_date,
toYear(date) AS year,
toUInt8(quarter(date)) AS quarter,
toUInt8(month(date)) AS month,
toUInt8(toDayOfMonth(date)) AS day,
toUInt8(week(date)) AS week_num_of_year,
toUInt8(toDayOfWeek(date)) AS day_num_of_week
FROM (
SELECT
arrayJoin(
arrayMap(
x -> toDate('1990-01-01') + x,
range(toUInt32(dateDiff('day', toDate('1990-01-01'), toDate('2031-01-01'))))
)
) AS date
)
ORDER BY date_id