bsc-models/models/silver/core/silver__confirmed_blocks.sql
drethereum 7fcba6822f
AN-5777/sl2-migration-bsc (do not merge) (#315)
* initial build pt1

* decoder changes

* dbt project

* global node url

* commit with testing params

* comments

* remove macro

* data :result

* partition key

* prod uri
2025-02-20 08:17:33 -07:00

51 lines
1.1 KiB
SQL

-- depends_on: {{ ref('bronze__confirm_blocks') }}
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = "round(block_number,-3)",
tags = ['non_realtime']
) }}
WITH base AS (
SELECT
block_number,
DATA :result :hash :: STRING AS block_hash,
DATA :result :transactions txs,
_inserted_timestamp
FROM
{% if is_incremental() %}
{{ ref('bronze__confirm_blocks') }}
WHERE
_inserted_timestamp >= (
SELECT
IFNULL(
MAX(
_inserted_timestamp
),
'1970-01-01' :: TIMESTAMP
) _inserted_timestamp
FROM
{{ this }}
)
{% else %}
{{ ref('bronze__confirm_blocks_fr') }}
{% endif %}
qualify(ROW_NUMBER() over (PARTITION BY block_number
ORDER BY
_inserted_timestamp DESC)) = 1
)
SELECT
block_number,
block_hash,
VALUE :: STRING AS tx_hash,
_inserted_timestamp
FROM
base,
LATERAL FLATTEN (
input => txs
)