flow-models/models/silver/curated/silver__flow_evm_address_map.sql
Jack Forgash 45a68debed
Some checks failed
docs_update / run_dbt_jobs (push) Has been cancelled
dbt_run_streamline_evm_daily_realtime / run_dbt_jobs (push) Has been cancelled
dbt_run_moments_metadata / run_dbt_jobs (push) Has been cancelled
dbt_observability_models / run_dbt_jobs (push) Has been cancelled
dbt_run_streamline_evm_daily_silver / run_dbt_jobs (push) Has been cancelled
dbt_run_evm_decoded_logs / run_dbt_jobs (push) Has been cancelled
dbt_run_streamline_transactions / run_dbt_jobs (push) Has been cancelled
dbt_run_streamline_transaction_results / run_dbt_jobs (push) Has been cancelled
dbt_run_streamline_external_realtime / run_dbt_jobs (push) Has been cancelled
dbt_run_streamline_external_points_balances_realtime / run_dbt_jobs (push) Has been cancelled
dbt_run_streamline_evm_realtime / run_dbt_jobs (push) Has been cancelled
dbt_run_scheduled / run_dbt_jobs (push) Has been cancelled
dbt_run_streamline_blocks / run_dbt_jobs (push) Has been cancelled
dbt_run_evm / run_dbt_jobs (push) Has been cancelled
dbt_run_scheduled_non_core / run_dbt_jobs (push) Has been cancelled
dbt_run_streamline_collections / run_dbt_jobs (push) Has been cancelled
docs_update / notify-failure (push) Has been cancelled
dbt_run_streamline_evm_daily_realtime / notify-failure (push) Has been cancelled
dbt_run_moments_metadata / notify-failure (push) Has been cancelled
dbt_observability_models / notify-failure (push) Has been cancelled
dbt_run_streamline_evm_daily_silver / notify-failure (push) Has been cancelled
dbt_run_evm_decoded_logs / notify-failure (push) Has been cancelled
dbt_run_streamline_transactions / notify-failure (push) Has been cancelled
dbt_run_streamline_transaction_results / notify-failure (push) Has been cancelled
dbt_run_streamline_external_realtime / notify-failure (push) Has been cancelled
dbt_run_streamline_external_points_balances_realtime / notify-failure (push) Has been cancelled
dbt_run_streamline_evm_realtime / notify-failure (push) Has been cancelled
dbt_run_scheduled / notify-failure (push) Has been cancelled
dbt_run_streamline_blocks / notify-failure (push) Has been cancelled
dbt_run_evm / notify-failure (push) Has been cancelled
dbt_run_scheduled_non_core / notify-failure (push) Has been cancelled
dbt_run_streamline_collections / notify-failure (push) Has been cancelled
dbt_run_streamline_decoded_logs_history / run_dbt_jobs (push) Has been cancelled
dbt_run_streamline_decoded_logs_history / notify-failure (push) Has been cancelled
AN-6231/modernize incremental predicates (#442)
* upd incr predicate on silver core models

* upd rest of the models

* rm predicate from d+i model
2025-08-06 12:40:17 -04:00

125 lines
2.9 KiB
SQL

{{ config(
materialized = 'incremental',
incremental_predicates = ["dynamic_range_predicate", "block_timestamp::DATE"],
unique_key = 'flow_evm_address_map_id',
incremental_strategy = 'merge',
merge_exclude_columns = ['inserted_timestamp'],
cluster_by = ['block_timestamp::date', 'modified_timestamp::date'],
tags = ['scheduled_non_core']
) }}
WITH events AS (
SELECT
*
FROM
{{ ref('silver__streamline_events') }}
WHERE
block_timestamp :: DATE >= '2024-09-02'
{% if is_incremental() %}
AND modified_timestamp >= (
SELECT
MAX(modified_timestamp)
FROM
{{ this }}
)
{% endif %}
),
coa_creation AS (
SELECT
tx_id,
block_timestamp,
block_height,
event_index,
CONCAT(
'0x',
event_data :address :: STRING
) AS evm_address
FROM
events
WHERE
event_contract = 'A.e467b9dd11fa00df.EVM'
AND event_type = 'CadenceOwnedAccountCreated'
),
txs AS (
SELECT
tx_id,
block_height,
authorizers
FROM
{{ ref('silver__streamline_transactions_final') }}
WHERE
block_timestamp :: DATE >= '2024-09-02'
AND tx_id IN (
SELECT
tx_id
FROM
events
)
{% if is_incremental() %}
AND modified_timestamp >= (
SELECT
MAX(modified_timestamp)
FROM
{{ this }}
)
{% endif %}
),
get_flow_address AS (
SELECT
tx_id,
block_height,
event_index,
event_type,
event_data :address :: STRING AS flow_address
FROM
events
WHERE
event_contract = 'flow'
AND event_type = 'CapabilityPublished'
AND tx_id IN (
SELECT
tx_id
FROM
coa_creation
) -- a transaction may emit multiple CapabilityPublished events
qualify(ROW_NUMBER() over (PARTITION BY tx_id
ORDER BY
event_index) = 1)
),
map_addresses AS (
SELECT
A.tx_id,
A.block_timestamp,
A.block_height,
A.evm_address,
COALESCE(
b.flow_address,
C.authorizers [0] :: STRING
) AS flow_address,
b.flow_address IS NULL AS used_authorizer
FROM
coa_creation A
LEFT JOIN get_flow_address b
ON A.tx_id = b.tx_id
AND A.block_height = b.block_height
LEFT JOIN txs C
ON A.tx_id = C.tx_id
AND A.block_height = C.block_height
)
SELECT
tx_id,
block_timestamp,
block_height,
evm_address,
flow_address,
used_authorizer,
{{ dbt_utils.generate_surrogate_key(['evm_address', 'flow_address']) }} AS flow_evm_address_map_id,
SYSDATE() AS modified_timestamp,
SYSDATE() AS inserted_timestamp,
'{{ invocation_id }}' AS invocation_id
FROM
map_addresses