2022-02-28 23:55:44 +00:00
|
|
|
{{ config(
|
|
|
|
|
materialized = 'incremental',
|
2022-10-13 18:19:41 +00:00
|
|
|
unique_key = "tx_id",
|
2022-11-09 20:37:50 +00:00
|
|
|
merge_predicates = ['DBT_INTERNAL_DEST.block_timestamp::date >= LEAST(current_date-7,(select min(block_timestamp)::date from {{ this }}__dbt_tmp))'],
|
2022-10-13 18:19:41 +00:00
|
|
|
cluster_by = ['block_timestamp::DATE','block_id','_inserted_timestamp::DATE'],
|
|
|
|
|
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION",
|
2023-01-09 21:24:10 +00:00
|
|
|
full_refresh = false
|
2022-02-28 23:55:44 +00:00
|
|
|
) }}
|
|
|
|
|
|
2022-10-13 18:19:41 +00:00
|
|
|
WITH pre_final AS (
|
2022-02-28 23:55:44 +00:00
|
|
|
SELECT
|
2022-10-13 18:19:41 +00:00
|
|
|
COALESCE(TO_TIMESTAMP_NTZ(t.value :block_time), b.block_timestamp) AS block_timestamp,
|
|
|
|
|
t.block_id,
|
|
|
|
|
t.tx_id,
|
|
|
|
|
t.data :transaction :message :recentBlockhash :: STRING AS recent_block_hash,
|
|
|
|
|
t.data :meta :fee :: NUMBER AS fee,
|
2022-02-28 23:55:44 +00:00
|
|
|
CASE
|
2022-06-23 16:46:56 +00:00
|
|
|
WHEN IS_NULL_VALUE(
|
2022-10-13 18:19:41 +00:00
|
|
|
t.data :meta :err
|
2022-06-23 16:46:56 +00:00
|
|
|
) THEN TRUE
|
2022-02-28 23:55:44 +00:00
|
|
|
ELSE FALSE
|
|
|
|
|
END AS succeeded,
|
2022-10-13 18:19:41 +00:00
|
|
|
t.data :transaction :message :accountKeys :: ARRAY AS account_keys,
|
|
|
|
|
t.data :transaction :message :instructions [0] :parsed :info :voteAccount :: STRING AS vote_account,
|
|
|
|
|
t.data :transaction :message :instructions [0] :parsed :info :voteAuthority :: STRING AS vote_authority,
|
|
|
|
|
t.data :transaction :message :instructions [0] :parsed :info :vote :hash :: STRING AS vote_hash,
|
|
|
|
|
t.data :transaction :message :instructions [0] :parsed :info :vote :slots :: ARRAY AS vote_slots,
|
|
|
|
|
t._partition_id,
|
|
|
|
|
t._inserted_timestamp
|
2022-02-28 23:55:44 +00:00
|
|
|
FROM
|
2022-10-13 23:09:13 +00:00
|
|
|
{{ ref('bronze__transactions2') }} t
|
2022-10-13 18:19:41 +00:00
|
|
|
LEFT OUTER JOIN
|
|
|
|
|
{{ ref('silver__blocks') }} b on b.block_id = t.block_id
|
2022-02-28 23:55:44 +00:00
|
|
|
WHERE
|
2022-10-13 18:19:41 +00:00
|
|
|
tx_id is not null
|
|
|
|
|
AND
|
|
|
|
|
COALESCE(
|
|
|
|
|
t.data :transaction :message :instructions [0] :programId :: STRING,
|
|
|
|
|
''
|
|
|
|
|
) = 'Vote111111111111111111111111111111111111111'
|
|
|
|
|
{% if is_incremental() %}
|
|
|
|
|
AND
|
|
|
|
|
_partition_id >= (
|
2023-01-11 16:42:11 +00:00
|
|
|
select max(_partition_id)-3
|
2022-10-13 18:19:41 +00:00
|
|
|
from {{this}}
|
|
|
|
|
)
|
|
|
|
|
AND
|
|
|
|
|
_partition_id <= (
|
2023-01-11 17:08:38 +00:00
|
|
|
SELECT
|
|
|
|
|
MAX(_partition_id)
|
|
|
|
|
FROM
|
|
|
|
|
{{ ref('streamline__complete_block_txs') }}
|
2022-10-13 18:19:41 +00:00
|
|
|
)
|
2023-01-11 14:58:26 +00:00
|
|
|
-- AND
|
|
|
|
|
-- t._inserted_timestamp > (
|
|
|
|
|
-- select max(_inserted_timestamp)
|
|
|
|
|
-- from {{this}}
|
|
|
|
|
-- )
|
2022-10-13 18:19:41 +00:00
|
|
|
{% else %}
|
|
|
|
|
AND
|
|
|
|
|
_partition_id in (1,2)
|
|
|
|
|
{% endif %}
|
|
|
|
|
)
|
2022-03-02 01:42:47 +00:00
|
|
|
{% if is_incremental() %}
|
2022-10-13 18:19:41 +00:00
|
|
|
, prev_null_block_timestamp_txs as (
|
|
|
|
|
select
|
|
|
|
|
b.block_timestamp,
|
|
|
|
|
t.block_id,
|
|
|
|
|
t.tx_id,
|
|
|
|
|
t.recent_block_hash,
|
|
|
|
|
t.signers,
|
|
|
|
|
t.fee,
|
|
|
|
|
t.succeeded,
|
|
|
|
|
t.account_keys,
|
|
|
|
|
t.vote_account,
|
|
|
|
|
t.vote_authority,
|
|
|
|
|
t.vote_hash,
|
|
|
|
|
t.vote_slots,
|
|
|
|
|
t._partition_id,
|
|
|
|
|
greatest(t._inserted_timestamp,b._inserted_timestamp) as _inserted_timestamp
|
|
|
|
|
from {{ this }} t
|
|
|
|
|
inner join {{ ref('silver__blocks') }} b on b.block_id = t.block_id
|
|
|
|
|
where t.block_timestamp::date is null
|
|
|
|
|
and t.block_id > 39824213
|
2022-06-23 16:46:56 +00:00
|
|
|
)
|
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-10-13 18:19:41 +00:00
|
|
|
silver.udf_ordered_signers(account_keys) AS signers,
|
2022-03-02 19:33:01 +00:00
|
|
|
fee,
|
2022-02-28 23:55:44 +00:00
|
|
|
succeeded,
|
2022-10-13 18:19:41 +00:00
|
|
|
account_keys,
|
2022-02-28 23:55:44 +00:00
|
|
|
vote_account,
|
|
|
|
|
vote_authority,
|
|
|
|
|
vote_hash,
|
|
|
|
|
vote_slots,
|
2022-10-13 18:19:41 +00:00
|
|
|
_partition_id,
|
2022-06-22 13:13:44 +00:00
|
|
|
_inserted_timestamp
|
2022-02-28 23:55:44 +00:00
|
|
|
FROM
|
2022-10-13 18:19:41 +00:00
|
|
|
pre_final b
|
|
|
|
|
qualify(ROW_NUMBER() over(PARTITION BY block_id, tx_id
|
2022-02-28 23:55:44 +00:00
|
|
|
ORDER BY
|
2022-06-23 16:46:56 +00:00
|
|
|
_inserted_timestamp DESC)) = 1
|
2022-10-13 18:19:41 +00:00
|
|
|
{% if is_incremental() %}
|
|
|
|
|
union
|
|
|
|
|
select *
|
|
|
|
|
from prev_null_block_timestamp_txs
|
|
|
|
|
{% endif %}
|