solana-models/models/silver/parser/silver__decoded_instructions.sql
desmond-hui f2f28ee9e4
An 4323/initial streamline 2.0 setup (#431)
* wip

* change udf name, fix surrogate key for inner instruct calls

* (wip) decoded instructions backfill helpers

* complete backfill helpers, clean up views with 0 requests

* rename

* revert

* temp change will revert

* rename

* use streamline 2.0 verify idl api endpoint

* this is placeholder model, will replace existing when ready

* reorg files

* add workflow for decode instructions real time

* use pip cache

* update with prod endpoints

* update sql limit to real value, should be union all

* use ref for model names

* remove placeholder, replace existing model logic

* add new decoder flow to gha

* temp disable incremental

* add inner index to core tables

* match existing behavior until we properly incorporate inner_instruction txs

* temp disable

* re-enable models

* remove unused comment

* properly handle inner_index null instances in unique key
2024-01-03 12:39:56 -08:00

61 lines
1.7 KiB
SQL

-- depends_on: {{ ref('bronze__streamline_decoded_instructions_2') }}
-- depends_on: {{ ref('bronze__streamline_FR_decoded_instructions_2') }}
{{ config(
materialized = 'incremental',
unique_key = "decoded_instructions_id",
cluster_by = ['block_timestamp::DATE','_inserted_timestamp::DATE','program_id'],
post_hook = enable_search_optimization('{{this.schema}}','{{this.identifier}}'),
merge_exclude_columns = ["inserted_timestamp"],
tags = ['scheduled_non_core'],
) }}
SELECT
b.block_timestamp,
A.block_id,
A.tx_id,
COALESCE(
A.index,
VALUE :data :data [0] [0],
VALUE :data [0] [0]
) :: INT AS INDEX,
A.inner_index,
A.program_id,
COALESCE(
A.value :data :data [0] [1],
A.value :data [1],
A.value :data
) AS decoded_instruction,
A._inserted_timestamp,
{{ dbt_utils.generate_surrogate_key(
['A.tx_id', 'A.index', 'A.inner_index']
) }} AS decoded_instructions_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
{% if is_incremental() %}
{{ ref('bronze__streamline_decoded_instructions_2') }} A
{% else %}
{{ ref('bronze__streamline_FR_decoded_instructions_2') }} A
{% endif %}
JOIN {{ ref('silver__blocks') }}
b
ON A.block_id = b.block_id
{% if is_incremental() %}
WHERE
A._inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
) _inserted_timestamp
FROM
{{ this }}
)
{% endif %}
qualify(ROW_NUMBER() over (PARTITION BY tx_id, INDEX, coalesce(inner_index,-1)
ORDER BY
A._inserted_timestamp DESC)) = 1