finance-dbt/models/dw/dw.dim_time.sql

26 lines
646 B
MySQL
Raw Normal View History

2024-04-12 19:07:47 +08:00
{{
config(
materialized='table',
engine='MergeTree',
order_by='(date_id_str, full_time_str, time_id)'
2024-04-12 19:07:47 +08:00
)
}}
Select toYYYYMMDDhhmmss(`full_time`) As time_id
2024-04-12 19:07:47 +08:00
, `full_time`
, `date_id`
, hour(`full_time`) As `hour`
, minute(`full_time`) As `minute`
, formatDateTimeInJodaSyntax(`full_time`, 'yyyy-MM-dd HH:mm:ss') As full_time_str
, Cast(`date_id` As String) As date_id_str
2024-04-12 19:07:47 +08:00
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