mirror of
https://github.com/FlipsideCrypto/kaia-models.git
synced 2026-02-06 11:01:46 +00:00
confirmed blocks
This commit is contained in:
parent
eb86487108
commit
eb03d05036
7
models/bronze/core/bronze__confirm_blocks.sql
Normal file
7
models/bronze/core/bronze__confirm_blocks.sql
Normal file
@ -0,0 +1,7 @@
|
||||
{{ config (
|
||||
materialized = 'view'
|
||||
) }}
|
||||
{{ fsc_evm.streamline_external_table_query(
|
||||
model = "confirm_blocks",
|
||||
partition_function = "CAST(SPLIT_PART(SPLIT_PART(file_name, '/', 4), '_', 1) AS INTEGER)"
|
||||
) }}
|
||||
7
models/bronze/core/fr/bronze__confirm_blocks_fr.sql
Normal file
7
models/bronze/core/fr/bronze__confirm_blocks_fr.sql
Normal file
@ -0,0 +1,7 @@
|
||||
{{ config (
|
||||
materialized = 'view'
|
||||
) }}
|
||||
{{ fsc_evm.streamline_external_table_fr_query(
|
||||
model = "confirm_blocks",
|
||||
partition_function = "CAST(SPLIT_PART(SPLIT_PART(file_name, '/', 4), '_', 1) AS INTEGER )"
|
||||
) }}
|
||||
@ -1,11 +1,61 @@
|
||||
{{ config(
|
||||
materialized = 'view'
|
||||
-- depends_on: {{ ref('bronze__confirm_blocks') }}
|
||||
{% set build_mode = var('SILVER_CONFIRM_BLOCKS_RELOAD', false) %}
|
||||
|
||||
{{ config (
|
||||
materialized = "incremental",
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['modified_timestamp::DATE'],
|
||||
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION on equality(block_number)",
|
||||
tags = ['non_realtime']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'klaytn_silver',
|
||||
'confirmed_blocks'
|
||||
) }}
|
||||
WITH bronze_confirm_blocks AS (
|
||||
SELECT
|
||||
block_number,
|
||||
partition_key,
|
||||
DATA:result AS block_json,
|
||||
block_json :hash :: STRING AS block_hash,
|
||||
block_json :transactions AS txs,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
{% if is_incremental() %}
|
||||
{% if build_mode %}
|
||||
{{ ref('bronze__confirm_blocks_fr') }}
|
||||
WHERE partition_key BETWEEN (
|
||||
SELECT ROUND(MAX(block_number), -3) FROM {{ this }}
|
||||
)
|
||||
AND (
|
||||
SELECT ROUND(MAX(block_number), -3) FROM {{ this }}
|
||||
) + 10000000
|
||||
AND DATA:result IS NOT NULL
|
||||
{% else %}
|
||||
{{ ref('bronze__confirm_blocks') }}
|
||||
WHERE _inserted_timestamp >= (
|
||||
SELECT COALESCE(MAX(_inserted_timestamp), '1900-01-01'::TIMESTAMP) AS _inserted_timestamp
|
||||
FROM {{ this }}
|
||||
) AND DATA:result IS NOT NULL
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{{ ref('bronze__confirm_blocks_fr') }}
|
||||
WHERE DATA:result IS NOT NULL
|
||||
and partition_key <= 10000000
|
||||
{% endif %}
|
||||
qualify(ROW_NUMBER() over (PARTITION BY block_number ORDER BY _inserted_timestamp DESC)) = 1
|
||||
)
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
partition_key,
|
||||
block_json,
|
||||
block_hash,
|
||||
VALUE :: STRING AS tx_hash,
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(['block_number','tx_hash']) }} AS confirm_blocks_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM bronze_confirm_blocks,
|
||||
LATERAL FLATTEN (
|
||||
input => txs
|
||||
)
|
||||
Loading…
Reference in New Issue
Block a user