finance-dbt/models/dw/dw.dim_time.sql
2024-04-08 12:01:58 +08:00

24 lines
516 B
SQL

{{
config(
materialized='table',
engine='MergeTree',
order_by='time_id'
)
}}
Select cast(formatDateTime(`full_time`, '%Y%m%d%H%i') As Int64) As time_id
, `full_time`
, `date_id`
, hour(`full_time`) As `hour`
, minute(`full_time`) As `minute`
From(
SELECT
arrayJoin(
arrayMap(
x -> toStartOfMinute(toDateTime(toDate(`full_date`)) + x * 60),
range(0, 24 * 60)
)
) AS `full_time`
, `date_id`
From {{ ref("dw.dim_date") }}
Where `date_id` >= 20090101
) As T