solana-models/models/silver/silver__decoded_instructions_data.sql
desmond-hui 8a00a94959
An 2134/migrate external tables (#103)
* reference new external table location

* delete line

* change warehouse
2022-09-15 07:38:07 -07:00

36 lines
745 B
SQL

{{ config(
materialized = 'incremental',
unique_key = "CONCAT_WS('-', tx_id, event_index)",
incremental_strategy = 'delete+insert',
cluster_by = ['program_id'],
) }}
SELECT
tx_id,
event_index,
program_id,
instruction_type,
DATA,
TO_TIMESTAMP_NTZ(
SUBSTR(SPLIT_PART(metadata$filename, '/', 4), 1, 10) :: NUMBER,
0
) AS _inserted_timestamp
FROM
{{ source(
'bronze_streamline',
'decoded_instructions_data_api'
) }}
{% if is_incremental() %}
WHERE _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% endif %}
qualify(ROW_NUMBER() over (PARTITION BY tx_id, event_index
ORDER BY
_inserted_timestamp DESC)) = 1