disregard unsealed current mainnet blocks (#175)

* disregard unsealed current mainnet blocks

* root height from seeds

* move alias
This commit is contained in:
Jack Forgash 2023-08-31 15:45:06 -06:00 committed by GitHub
parent caf9f4804c
commit feded0669f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 68 deletions

View File

@ -10,28 +10,38 @@
) }}
SELECT
data,
DATA,
block_number,
_partition_by_block_id,
_inserted_timestamp
FROM
{% if is_incremental() %}
{{ ref('bronze__streamline_blocks') }}
{{ ref('bronze__streamline_blocks') }}
WHERE
_inserted_timestamp >= COALESCE(
(
SELECT
MAX(_inserted_timestamp) _inserted_timestamp
MAX(_inserted_timestamp) _inserted_timestamp
FROM
{{ this }}
),
'1900-01-01'::timestamp_ntz
'1900-01-01' :: timestamp_ntz
)
{% else %}
{{ ref('bronze__streamline_fr_blocks') }}
WHERE
TRUE
{% endif %}
AND NOT (
DATA :status :: INT != 2
AND block_number >= (
SELECT
MAX(root_height)
FROM
{{ ref('seeds__network_version') }}
)
)
qualify(ROW_NUMBER() over (PARTITION BY block_number
ORDER BY
_inserted_timestamp DESC)) = 1
_inserted_timestamp DESC)) = 1

View File

@ -10,8 +10,9 @@
WITH last_3_days AS ({% if var('STREAMLINE_RUN_HISTORY') %}
SELECT
{# 55114467 is start of mainnet 23 #}
55114467 AS block_height
MAX(root_height) AS block_height
FROM
{{ ref('seeds__network_version') }}
{% else %}
SELECT
MAX(block_height) - 210000 AS block_height

View File

@ -8,11 +8,12 @@
) }}
WITH last_3_days AS ({% if var('STREAMLINE_RUN_HISTORY') %}
SELECT
{# 55114467 is start of mainnet 23 #}
55114467 AS block_height
{% else %}
SELECT
MAX(root_height) AS block_height
FROM
{{ ref('seeds__network_version') }}
{% else %}
SELECT
MAX(block_height) - 210000 AS block_height
FROM
@ -50,45 +51,49 @@ WITH last_3_days AS ({% if var('STREAMLINE_RUN_HISTORY') %}
AND block_height IS NOT NULL
),
collections AS (
SELECT
block_number AS block_height,
DATA
FROM
{{ ref('streamline__complete_get_blocks') }}
JOIN tbl
ON tbl.block_height = block_number
),
-- CTE to get all block_heights and their associated collection_ids from the complete_get_blocks table
block_collections AS (
SELECT
cb.block_number AS block_height,
collection_guarantee.value :collection_id AS collection_id
FROM
{{ ref("streamline__complete_get_blocks") }}
cb,
LATERAL FLATTEN(
input => cb.data :collection_guarantees
) AS collection_guarantee
),
-- CTE to identify collections that haven't been ingested yet
collections_to_ingest AS (
SELECT
bc.block_height,
bc.collection_id
FROM
block_collections bc
LEFT JOIN {{ ref("streamline__complete_get_collections") }} C
ON bc.block_height = C.block_number
AND bc.collection_id = C.id
WHERE
C.id IS NULL
)
SELECT
block_number AS block_height,
DATA
FROM
{{ ref('streamline__complete_get_blocks') }}
JOIN tbl
ON tbl.block_height = block_number
),
-- CTE to get all block_heights and their associated collection_ids from the complete_get_blocks table
block_collections AS (
SELECT
cb.block_number AS block_height,
collection_guarantee.value :collection_id AS collection_id
FROM
{{ ref("streamline__complete_get_blocks") }}
cb,
LATERAL FLATTEN(
input => cb.data :collection_guarantees
) AS collection_guarantee
),
-- CTE to identify collections that haven't been ingested yet
collections_to_ingest AS (
SELECT
bc.block_height,
bc.collection_id
FROM
block_collections bc
LEFT JOIN {{ ref("streamline__complete_get_collections") }} C
ON bc.block_height = C.block_number
AND bc.collection_id = C.id
WHERE
C.id IS NULL
)
SELECT
OBJECT_CONSTRUCT(
'grpc', 'proto3',
'method', 'get_collection_by_i_d',
'block_height', block_height :: INTEGER,
'method_params', OBJECT_CONSTRUCT(
'grpc',
'proto3',
'method',
'get_collection_by_i_d',
'block_height',
block_height :: INTEGER,
'method_params',
OBJECT_CONSTRUCT(
'id',
collection_id
)

View File

@ -8,11 +8,12 @@
) }}
WITH last_3_days AS ({% if var('STREAMLINE_RUN_HISTORY') %}
SELECT
{# 55114467 is start of mainnet 23 #}
55114467 AS block_height
{% else %}
SELECT
MAX(root_height) AS block_height
FROM
{{ ref('seeds__network_version') }}
{% else %}
SELECT
MAX(block_height) - 210000 AS block_height
FROM
@ -35,7 +36,7 @@ WITH last_3_days AS ({% if var('STREAMLINE_RUN_HISTORY') %}
AND block_height IS NOT NULL
EXCEPT
SELECT
block_number as block_height
block_number AS block_height
FROM
{{ ref('streamline__complete_get_transactions') }}
WHERE
@ -82,11 +83,16 @@ WITH last_3_days AS ({% if var('STREAMLINE_RUN_HISTORY') %}
) -- Generate the requests based on the missing transactions
SELECT
OBJECT_CONSTRUCT(
'grpc', 'proto3',
'method', 'get_transaction_result',
'block_height', block_height :: INTEGER,
'transaction_id', transaction_id :: STRING,
'method_params', OBJECT_CONSTRUCT(
'grpc',
'proto3',
'method',
'get_transaction_result',
'block_height',
block_height :: INTEGER,
'transaction_id',
transaction_id :: STRING,
'method_params',
OBJECT_CONSTRUCT(
'id',
transaction_id :: STRING
)

View File

@ -8,11 +8,12 @@
) }}
WITH last_3_days AS ({% if var('STREAMLINE_RUN_HISTORY') %}
SELECT
{# 55114467 is start of mainnet 23 #}
55114467 AS block_height
{% else %}
SELECT
MAX(root_height) AS block_height
FROM
{{ ref('seeds__network_version') }}
{% else %}
SELECT
MAX(block_height) - 210000 AS block_height
FROM
@ -82,11 +83,16 @@ WITH last_3_days AS ({% if var('STREAMLINE_RUN_HISTORY') %}
) -- Generate the requests based on the missing transactions
SELECT
OBJECT_CONSTRUCT(
'grpc', 'proto3',
'method', 'get_transaction',
'block_height', block_height :: INTEGER,
'transaction_id', transaction_id :: STRING,
'method_params', OBJECT_CONSTRUCT(
'grpc',
'proto3',
'method',
'get_transaction',
'block_height',
block_height :: INTEGER,
'transaction_id',
transaction_id :: STRING,
'method_params',
OBJECT_CONSTRUCT(
'id',
transaction_id :: STRING
)