mirror of
https://github.com/FlipsideCrypto/flow-models.git
synced 2026-02-06 13:56:45 +00:00
* add: model to backfill * fix: node's string format * add tags * upd collection model * mainnet21 hardcoded collections history model * del tag * mainnet 21 getblock * tag for 21 * realtime models * alias num as height * realtime tags * add missing tag and newlines * backfiller * backfiller * move script to folder (renamed) python, upd test accordingly w dir name ch * upd script to accept model input, update jobs per method call * error w use_dev arg * add: silver mdoels * limit backfill job in python script * rename silver dbt models to streamline_ and move into silver/core * explicit casting to silver streamline models * add documentation to silver streamline models * run only current mainnet and history mainnet 22 first * activate schedule for gha * del hardcoded mainnet models * move history modes out of subdirs into history dir * fix GHA vars * del upstream 1+ from history step * del tag --------- Co-authored-by: Jack Forgash <jmfxyz@pm.me>
86 lines
1.5 KiB
SQL
86 lines
1.5 KiB
SQL
{{ config(
|
|
materialized = 'incremental',
|
|
cluster_by = ['_inserted_timestamp::DATE'],
|
|
unique_key = 'block_height',
|
|
incremental_strategy = 'delete+insert',
|
|
tags = ['scheduled']
|
|
) }}
|
|
|
|
WITH bronze_blocks AS (
|
|
|
|
SELECT
|
|
*
|
|
FROM
|
|
{{ ref('bronze__blocks') }}
|
|
|
|
{% if is_incremental() %}
|
|
WHERE
|
|
_inserted_timestamp >= (
|
|
SELECT
|
|
MAX(_inserted_timestamp)
|
|
FROM
|
|
{{ this }}
|
|
)
|
|
{% endif %}
|
|
|
|
qualify ROW_NUMBER() over (
|
|
PARTITION BY block_id
|
|
ORDER BY
|
|
_ingested_at DESC
|
|
) = 1
|
|
),
|
|
silver_blocks AS (
|
|
SELECT
|
|
block_id AS block_height,
|
|
block_timestamp,
|
|
network,
|
|
chain_id,
|
|
tx_count,
|
|
COALESCE(
|
|
header :block_id,
|
|
header :block_header :block_id,
|
|
header :id
|
|
) :: STRING AS id,
|
|
COALESCE(
|
|
header :parent_id,
|
|
header :parentId,
|
|
header :block_header :parent_id
|
|
) :: STRING AS parent_id,
|
|
_ingested_at,
|
|
_inserted_timestamp
|
|
FROM
|
|
bronze_blocks
|
|
),
|
|
network_version AS (
|
|
SELECT
|
|
root_height,
|
|
network_version,
|
|
COALESCE(LAG(root_height) over (
|
|
ORDER BY
|
|
network_version DESC) - 1, 'inf' :: FLOAT) AS end_height
|
|
FROM
|
|
{{ ref('seeds__network_version') }}
|
|
),
|
|
add_version AS (
|
|
SELECT
|
|
block_height,
|
|
block_timestamp,
|
|
network,
|
|
v.network_version,
|
|
chain_id,
|
|
tx_count,
|
|
id,
|
|
parent_id,
|
|
_ingested_at,
|
|
_inserted_timestamp
|
|
FROM
|
|
silver_blocks b
|
|
LEFT JOIN network_version v
|
|
ON b.block_height BETWEEN v.root_height
|
|
AND v.end_height
|
|
)
|
|
SELECT
|
|
*
|
|
FROM
|
|
add_version
|