solana-models/models/silver/silver__votes.sql

61 lines
1.7 KiB
MySQL
Raw Normal View History

2022-02-28 23:55:44 +00:00
{{ config(
materialized = 'incremental',
unique_key = "CONCAT_WS('-', block_id, tx_id)",
incremental_strategy = 'delete+insert',
cluster_by = ['block_timestamp::DATE','_inserted_timestamp::DATE'],
2022-02-28 23:55:44 +00:00
) }}
WITH base AS (
SELECT
block_timestamp,
block_id,
tx_id,
tx :transaction :message :recentBlockhash :: STRING AS recent_block_hash,
tx :meta :fee :: NUMBER AS fee,
2022-02-28 23:55:44 +00:00
CASE
WHEN IS_NULL_VALUE(
tx :meta :err
) THEN TRUE
2022-02-28 23:55:44 +00:00
ELSE FALSE
END AS succeeded,
tx :transaction :message :instructions [0] :parsed :info :voteAccount :: STRING AS vote_account,
tx :transaction :message :instructions [0] :parsed :info :voteAuthority :: STRING AS vote_authority,
tx :transaction :message :instructions [0] :parsed :info :vote :hash :: STRING AS vote_hash,
tx :transaction :message :instructions [0] :parsed :info :vote :slots :: ARRAY AS vote_slots,
ingested_at,
_inserted_timestamp
2022-02-28 23:55:44 +00:00
FROM
2022-03-01 22:51:37 +00:00
{{ ref('bronze__transactions') }}
2022-02-28 23:55:44 +00:00
t
WHERE
tx :transaction :message :instructions [0] :parsed :type :: STRING IS NOT NULL
AND tx :transaction :message :instructions [0] :programId :: STRING = 'Vote111111111111111111111111111111111111111'
2022-03-02 01:42:47 +00:00
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
2022-03-02 01:42:47 +00:00
{% endif %}
2022-02-28 23:55:44 +00:00
)
SELECT
block_timestamp,
block_id,
tx_id,
recent_block_hash,
2022-03-02 19:33:01 +00:00
fee,
2022-02-28 23:55:44 +00:00
succeeded,
vote_account,
vote_authority,
vote_hash,
vote_slots,
ingested_at,
_inserted_timestamp
2022-02-28 23:55:44 +00:00
FROM
2022-03-01 22:51:37 +00:00
base qualify(ROW_NUMBER() over(PARTITION BY block_id, tx_id
2022-02-28 23:55:44 +00:00
ORDER BY
_inserted_timestamp DESC)) = 1