expand onchain metadata mapping

This commit is contained in:
Jack Forgash 2024-07-30 15:14:21 -06:00
parent 51607b2222
commit 2897909595
8 changed files with 100 additions and 198 deletions

View File

@ -24,40 +24,30 @@ WITH events AS (
{{ ref('silver__streamline_events') }}
WHERE
event_type = 'EditionCreated'
AND event_contract IN (
'A.e4cf4bdc1751c65d.AllDay',
'A.b715b81853fef53f.AllDay',
'A.87ca73a41bb50ad5.Golazos'
)
{% if is_incremental() %}
AND modified_timestamp >= (
SELECT
MAX(modified_timestamp)
MAX(modified_timestamp)
FROM
{{ this }}
)
{% endif %}
),
org AS (
SELECT
tx_id,
event_id,
block_timestamp,
event_contract,
event_data :id :: STRING AS edition_id,
event_data :maxMintSize :: STRING AS max_mint_size,
event_data :playID :: STRING AS play_id,
event_data :seriesID :: STRING AS series_id,
event_data :setID :: STRING AS set_id,
event_data :tier :: STRING AS tier,
_inserted_timestamp,
_partition_by_block_id
FROM
events
)
SELECT
*,
tx_id,
event_id,
block_timestamp,
event_contract,
event_data AS edition_data,
event_data :id :: STRING AS edition_id,
event_data :maxMintSize :: STRING AS max_mint_size,
event_data :playID :: STRING AS play_id,
event_data :seriesID :: STRING AS series_id,
event_data :setID :: STRING AS set_id,
event_data :tier :: STRING AS tier,
_inserted_timestamp,
_partition_by_block_id,
{{ dbt_utils.generate_surrogate_key(
['event_id']
) }} AS nft_moment_editions_id,
@ -65,4 +55,4 @@ SELECT
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
org
events

View File

@ -5,7 +5,7 @@
tags = ['nft', 'dapper', 'scheduled', 'streamline_scheduled', 'scheduled_non_core']
) }}
WITH moments AS (
WITH moments_minted AS (
SELECT
*
@ -30,7 +30,7 @@ series AS (
FROM
{{ ref('silver__nft_moment_series_s') }}
),
set_nm AS (
nft_sets AS (
SELECT
*
FROM
@ -38,47 +38,60 @@ set_nm AS (
),
FINAL AS (
SELECT
-- tx id and block timestamp don't matter for the final table
m.tx_id,
m.block_timestamp,
m.event_contract,
m.nft_id,
m.serial_number,
e.max_mint_size,
e.play_id,
e.series_id,
COALESCE(
m.play_id,
e.play_id
) AS play_id,
COALESCE(
m.series_id,
e.series_id
) AS series_id,
s.series_name,
e.set_id,
COALESCE(
m.set_id,
e.set_id
) AS set_id,
sn.set_name,
e.edition_id,
COALESCE(
m.edition_id,
e.edition_id
) AS edition_id,
e.tier,
pl.metadata,
set_data,
series_data,
edition_data,
m._inserted_timestamp,
sn._inserted_timestamp AS _inserted_timestamp_set
FROM
moments m
LEFT JOIN editions e USING (
event_contract,
edition_id
)
LEFT JOIN metadata pl USING (
event_contract,
play_id
)
LEFT JOIN series s USING (
event_contract,
series_id
)
LEFT JOIN set_nm sn USING (
event_contract,
set_id
)
moments_minted m
LEFT JOIN editions e
ON m.event_contract = e.event_contract
AND m.edition_id = e.edition_id
LEFT JOIN metadata pl
ON m.event_contract = pl.event_contract
AND COALESCE(
e.play_id,
m.play_id
) = pl.play_id
LEFT JOIN series s
ON m.event_contract = s.event_contract
AND e.series_id = s.series_id
LEFT JOIN nft_sets sn
ON m.event_contract = sn.event_contract
AND e.set_id = sn.set_id
)
SELECT
*,
{{ dbt_utils.generate_surrogate_key(
['event_contract','edition_id','nft_id']
) }} AS nft_moment_metadata_id,
['event_contract','nft_id', 'play_id']
) }} AS nft_moment_metadata_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id

View File

@ -1,61 +0,0 @@
{{ config(
materialized = 'incremental',
cluster_by = ['_inserted_timestamp'],
unique_key = "concat_ws('-', event_contract, moment_id)",
incremental_strategy = 'delete+insert',
tags = ['nft', 'dapper', 'scheduled', 'streamline_scheduled', 'scheduled_non_core']
) }}
WITH events AS (
SELECT
block_height,
block_timestamp,
tx_id,
event_id,
event_index,
event_type,
event_contract,
event_data,
_inserted_timestamp,
_partition_by_block_id,
modified_timestamp
FROM
{{ ref('silver__streamline_events') }}
WHERE
event_type = 'MomentMinted'
{% if is_incremental() %}
AND modified_timestamp >= (
SELECT
MAX(modified_timestamp)
FROM
{{ this }}
)
{% endif %}
),
org AS (
SELECT
tx_id,
event_id,
block_timestamp,
event_contract,
event_data :momentID :: STRING AS moment_id,
event_data :serialNumber :: STRING AS serial_number,
event_data :seriesID :: STRING AS series_id,
event_data :setID :: STRING AS set_id,
_inserted_timestamp,
_partition_by_block_id
FROM
events
)
SELECT
*,
{{ dbt_utils.generate_surrogate_key(
['event_id']
) }} AS nft_moment_minted_2_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
org

View File

@ -1,35 +0,0 @@
version: 2
models:
- name: silver__nft_moment_minted_2_s
description: |-
Cleaned MomentNFTMinted events.
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- event_contract
- moment_id
columns:
- name: tx_id
description: "{{ doc('tx_id') }}"
- name: block_timestamp
description: "{{ doc('block_timestamp') }}"
- name: event_contract
description: "{{ doc('event_contract') }}"
tests:
- accepted_values:
values:
- "A.c38aea683c0c4d38.Eternal"
- "A.d4ad4740ee426334.Moments"
- "A.67af7ecf76556cd3.ABD"
- "A.0b2a3299cc857e29.TopShot"
- name: moment_id
description: "{{ doc('moment_id') }}"
- name: serial_number
description: "{{ doc('serial_number') }}"
- name: set_id
description: "{{ doc('set_id') }}"
- name: series_id
description: "{{ doc('series_id') }}"
- name: _inserted_timestamp
description: "{{ doc('_inserted_timestamp') }}"

View File

@ -23,7 +23,10 @@ WITH events AS (
FROM
{{ ref('silver__streamline_events') }}
WHERE
event_type = 'MomentNFTMinted'
event_type IN (
'MomentNFTMinted',
'MomentMinted'
)
{% if is_incremental() %}
AND modified_timestamp >= (
@ -33,23 +36,27 @@ AND modified_timestamp >= (
{{ this }}
)
{% endif %}
),
org AS (
SELECT
tx_id,
event_id,
block_timestamp,
event_contract,
event_data :editionID :: STRING AS edition_id,
event_data :id :: STRING AS nft_id,
event_data :serialNumber :: STRING AS serial_number,
_inserted_timestamp,
_partition_by_block_id
FROM
events
)
SELECT
*,
tx_id,
event_id,
block_timestamp,
event_contract,
event_data,
event_data :editionID :: STRING AS edition_id,
event_data :subeditionID :: STRING AS subedition_id,
event_data :seriesID :: STRING AS series_id,
event_data :setID :: STRING AS set_id,
COALESCE(
event_data :id,
event_data :momentID
) :: STRING AS nft_id,
event_data :serialNumber :: STRING AS serial_number,
event_data :playID :: STRING AS play_id,
event_data :contentEditionID :: STRING AS content_edition_id,
event_data :contentID :: STRING AS content_id,
_inserted_timestamp,
_partition_by_block_id,
{{ dbt_utils.generate_surrogate_key(
['event_id']
) }} AS nft_moment_minted_id,
@ -57,4 +64,4 @@ SELECT
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
org
events

View File

@ -24,7 +24,6 @@ WITH events AS (
{{ ref('silver__streamline_events') }}
WHERE
event_type = 'SeriesCreated'
AND ARRAY_CONTAINS('name' :: variant, object_keys(event_data))
{% if is_incremental() %}
AND modified_timestamp >= (
@ -34,22 +33,17 @@ AND modified_timestamp >= (
{{ this }}
)
{% endif %}
),
org AS (
SELECT
tx_id,
event_id,
block_timestamp,
event_contract,
event_data :id :: STRING AS series_id,
event_data :name :: STRING AS series_name,
_inserted_timestamp,
_partition_by_block_id
FROM
events
)
SELECT
*,
tx_id,
event_id,
block_timestamp,
event_contract,
event_data AS series_data,
event_data :id :: STRING AS series_id,
event_data :name :: STRING AS series_name,
_inserted_timestamp,
_partition_by_block_id,
{{ dbt_utils.generate_surrogate_key(
['event_id']
) }} AS nft_moment_series_id,
@ -57,4 +51,4 @@ SELECT
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
org
events

View File

@ -24,7 +24,6 @@ WITH events AS (
{{ ref('silver__streamline_events') }}
WHERE
event_type = 'SetCreated'
AND ARRAY_CONTAINS('name' :: variant, object_keys(event_data))
{% if is_incremental() %}
AND modified_timestamp >= (
@ -34,24 +33,17 @@ AND modified_timestamp >= (
{{ this }}
)
{% endif %}
),
org AS (
SELECT
tx_id,
event_id,
block_timestamp,
event_contract,
event_data :id :: STRING AS set_id,
event_data :name :: STRING AS set_name,
_inserted_timestamp,
_partition_by_block_id
FROM
events
WHERE
set_id IS NOT NULL
)
SELECT
*,
tx_id,
event_id,
block_timestamp,
event_contract,
event_data AS set_data,
event_data :id :: STRING AS set_id,
event_data :name :: STRING AS set_name,
_inserted_timestamp,
_partition_by_block_id,
{{ dbt_utils.generate_surrogate_key(
['event_id']
) }} AS nft_moment_set_id,
@ -59,4 +51,6 @@ SELECT
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
org
events
WHERE
set_id IS NOT NULL