flow-models/models/silver/core/silver__streamline_collections.sql
Jack Forgash bd08ee7f8f
An 4015/streamline cutover (#200)
* core views

* defi schema

* bridge test upd

* gov schema

* nft schema

* price schema

* move tx count to blocks model

* add collection_count_agg to blocks

* upd core views to UNION ALL

* upd collections cluster_by

* upd dim moment metadata to qualify

* upd dim moment metadata test

* upd core dim contract labels to qualify and silver (cw) to incr

* upd str blocks lookback`
2023-10-12 16:23:20 -06:00

36 lines
894 B
SQL

-- depends_on: {{ ref('bronze__streamline_collections') }}
{{ config(
materialized = 'incremental',
unique_key = "collection_id",
cluster_by = ['_inserted_timestamp :: DATE', 'block_number'],
tags = ['streamline_load', 'core']
) }}
SELECT
block_number,
DATA: id :: STRING AS collection_id,
ARRAY_SIZE(
DATA :transaction_ids :: ARRAY
) AS tx_count,
DATA: transaction_ids :: ARRAY AS transaction_ids,
_partition_by_block_id,
_inserted_timestamp
FROM
{% if is_incremental() %}
{{ ref('bronze__streamline_collections') }}
WHERE
_inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) _inserted_timestamp
FROM
{{ this }}
)
{% else %}
{{ ref('bronze__streamline_fr_collections') }}
{% endif %}
qualify(ROW_NUMBER() over (PARTITION BY collection_id
ORDER BY
_inserted_timestamp DESC)) = 1