2024-04-12 19:07:47 +08:00
|
|
|
{{
|
|
|
|
config(
|
2024-07-05 17:54:16 +08:00
|
|
|
materialized='incremental',
|
2024-07-23 10:33:41 +08:00
|
|
|
engine='MergeTree',
|
2024-07-10 16:14:09 +08:00
|
|
|
order_by='(time_id, ts_code)',
|
|
|
|
unique_key=['time_id', 'ts_code'],
|
2024-07-25 19:01:46 +08:00
|
|
|
incremental_strategy='delete+insert',
|
2024-07-10 16:14:09 +08:00
|
|
|
partition_by=['toYYYYMM(toDateTime(time_id))'],
|
2024-05-06 23:54:05 +08:00
|
|
|
query_settings={
|
|
|
|
"join_algorithm": "'full_sorting_merge'",
|
|
|
|
}
|
2024-04-12 19:07:47 +08:00
|
|
|
)
|
|
|
|
}}
|
|
|
|
|
|
|
|
Select
|
2024-07-05 17:54:16 +08:00
|
|
|
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
|
2024-07-05 17:54:16 +08:00
|
|
|
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
|
2024-07-05 17:54:16 +08:00
|
|
|
{% if is_incremental() %}
|
2024-07-10 16:14:09 +08:00
|
|
|
And OdsMinutes.time_id >= (Select toYYYYMMDDhhmmss(toStartOfDay(YYYYMMDDhhmmssToDateTime(max(`time_id`)))) From {{ this }})
|
2024-07-05 17:54:16 +08:00
|
|
|
{% endif %}
|
2024-04-12 19:07:47 +08:00
|
|
|
{% if 'dev' in target.name %}
|
2024-07-05 17:54:16 +08:00
|
|
|
And OdsMinutes.time_id >= toYYYYMMDDhhmmss(dateAdd(Month,-1,today()))
|
2024-04-12 19:07:47 +08:00
|
|
|
{% elif target.name == 'test' %}
|
2024-07-05 17:54:16 +08:00
|
|
|
And OdsMinutes.time_id >= toYYYYMMDDhhmmss(dateAdd(Year,-1,today()))
|
2024-04-12 19:07:47 +08:00
|
|
|
{% endif %}
|