mirror of
https://github.com/FlipsideCrypto/near-models.git
synced 2026-02-06 11:47:00 +00:00
49 lines
1.0 KiB
SQL
49 lines
1.0 KiB
SQL
{{ config(
|
|
materialized = 'incremental',
|
|
incremental_strategy = 'delete+insert',
|
|
unique_key = 'complete_provider_prices_id',
|
|
cluster_by = ['recorded_hour::DATE'],
|
|
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(asset_id);",
|
|
tags = ['scheduled_non_core']
|
|
) }}
|
|
|
|
SELECT
|
|
p.asset_id,
|
|
recorded_hour,
|
|
OPEN,
|
|
high,
|
|
low,
|
|
CLOSE,
|
|
m.platform,
|
|
p.provider,
|
|
p.source,
|
|
p._inserted_timestamp,
|
|
p.inserted_timestamp,
|
|
p.modified_timestamp,
|
|
p.complete_provider_prices_id,
|
|
p._invocation_id
|
|
FROM
|
|
{{ ref(
|
|
'bronze__complete_provider_prices'
|
|
) }}
|
|
p
|
|
INNER JOIN {{ ref('bronze__complete_provider_asset_metadata') }}
|
|
m
|
|
ON p.asset_id = m.asset_id
|
|
|
|
{% if is_incremental() %}
|
|
WHERE
|
|
p.modified_timestamp >= (
|
|
SELECT
|
|
MAX(
|
|
modified_timestamp
|
|
)
|
|
FROM
|
|
{{ this }}
|
|
)
|
|
{% endif %}
|
|
|
|
qualify(ROW_NUMBER() over (PARTITION BY p.asset_id, recorded_hour, p.provider
|
|
ORDER BY
|
|
p.modified_timestamp DESC)) = 1
|