blast-models/models/silver/core/silver__confirmed_blocks.sql
xiuy001 5335c7bc05
Update blast model to release 1.2 (#35)
* updated the blast model to use release 1.2

* removed user.ymal

* chainhead history and package temp

* v1.22

* udf name

* package upgrade, config in dbt_project

* chainhead

* updates for quantum and standardization

* remove limits

* removed the 2nd param in the receipts model

* if data_call_function v2

* block number column adj

* removed param

---------

Co-authored-by: drethereum <trevor.wenokur@gmail.com>
Co-authored-by: drethereum <71602799+drethereum@users.noreply.github.com>
2024-05-02 14:21:55 -04:00

54 lines
1.2 KiB
SQL

-- depends_on: {{ ref('bronze__streamline_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
IFNULL(
VALUE :BLOCK_NUMBER :: INT,
metadata :request :"data" :id :: INT
) AS block_number,
DATA :result :hash :: STRING AS block_hash,
DATA :result :transactions txs,
_inserted_timestamp
FROM
{% if is_incremental() %}
{{ ref('bronze__streamline_confirm_blocks') }}
WHERE
_inserted_timestamp >= (
SELECT
IFNULL(
MAX(
_inserted_timestamp
),
'1970-01-01' :: TIMESTAMP
) _inserted_timestamp
FROM
{{ this }}
)
{% else %}
{{ ref('bronze__streamline_FR_confirm_blocks') }}
{% 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
)