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

42 lines
1.4 KiB
MySQL
Raw Normal View History

2024-04-12 19:07:47 +08:00
{{
config(
materialized='incremental',
2024-04-12 19:07:47 +08:00
engine='MergeTree',
order_by='ts_code, time_id',
unique_key=['ts_code', 'time_id'],
incremental_strategy='delete+insert',
2024-04-12 19:07:47 +08:00
partition_by=['cast(floor(time_id / 1000000) As Int32)'],
query_settings={
"join_algorithm": "'full_sorting_merge'",
"max_bytes_before_external_sort": "'1000M'",
"max_bytes_before_external_group_by":"'1000M'",
}
2024-04-12 19:07:47 +08:00
)
}}
Select
OdsMinutes.ts_code As ts_code,
OdsMinutes.time_id As time_id,
OdsMinutes.close As close,
OdsMinutes.open As open,
OdsMinutes.high As high,
OdsMinutes.low As low,
OdsMinutes.vol As vol,
OdsMinutes.amount As amount,
OdsAdjFactor.adj_factor As adj_factor,
2024-04-12 19:07:47 +08:00
now() As dt
From {{ ref('ods.tushare_minutes') }} As OdsMinutes
Any Left Join {{ ref('dw.dim_time') }} As DimTime
On OdsMinutes.time_id = DimTime.time_id
Any Left Join {{ ref('ods.tushare_adj_factor') }} As OdsAdjFactor
On OdsMinutes.ts_code = OdsAdjFactor.ts_code
And OdsAdjFactor.date_id = DimTime.date_id
2024-04-12 19:07:47 +08:00
where 1 = 1
{% if is_incremental() %}
And OdsMinutes.time_id >= (Select max(`time_id`) From {{ this }})
{% endif %}
2024-04-12 19:07:47 +08:00
{% if 'dev' in target.name %}
And OdsMinutes.time_id >= toYYYYMMDDhhmmss(dateAdd(Month,-1,today()))
2024-04-12 19:07:47 +08:00
{% elif target.name == 'test' %}
And OdsMinutes.time_id >= toYYYYMMDDhhmmss(dateAdd(Year,-1,today()))
2024-04-12 19:07:47 +08:00
{% endif %}