finance-dbt/models/dw/dw.dim_time.sql
沈楠 f1efaf2c2e feat: use ReplacingMergeTree for ods/dw fact tables
! Have to optimize parts after dbt run incrementially
2024-07-10 16:14:09 +08:00

26 lines
617 B
SQL

{{
config(
materialized='table',
engine='MergeTree',
order_by='time_id',
)
}}
Select toYYYYMMDDhhmmss(`full_time`) As time_id
, `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
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