Skip to content

Commit

Permalink
final silver cnft sales model (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
desmond-hui authored Apr 26, 2024
1 parent 0d1c268 commit 63c8647
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 0 deletions.
69 changes: 69 additions & 0 deletions models/silver/nfts/silver__nft_sales_magic_eden_cnft.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{{ config(
materialized = 'incremental',
unique_key = ['nft_sales_magic_eden_cnft_id'],
incremental_strategy = 'delete+insert',
merge_exclude_columns = ["inserted_timestamp"],
tags = ['scheduled_non_core']
) }}

WITH mint_addresses AS (

SELECT
r.value :tx_id :: STRING AS tx_id,
COALESCE(
r.value :mint :: STRING,
''
) AS mint,
r.value :index :: INTEGER AS mint_index,
r.value :inner_index :: INTEGER AS mint_inner_index,
_inserted_timestamp AS mint_inserted_timestamp
FROM
{{ ref('bronze_api__parse_compressed_nft_sales_magic_eden') }},
TABLE(FLATTEN(responses)) AS r
WHERE
mint <> ''
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(mint_inserted_timestamp)
FROM
{{ this }}
)
{% endif %}
qualify(ROW_NUMBER() over (PARTITION BY tx_id, mint
ORDER BY
_inserted_timestamp DESC)) = 1
)
SELECT
A.block_id,
A.block_timestamp,
A.program_id,
A.tx_id,
A.succeeded,
A.purchaser,
A.seller,
A.tree_authority,
A.merkle_tree,
A.leaf_index,
b.mint,
b.mint_inserted_timestamp,
A.sales_amount,
A._inserted_timestamp,
{{ dbt_utils.generate_surrogate_key(
['a.tx_id','b.mint']
) }} AS nft_sales_magic_eden_cnft_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp
FROM
{{ ref('silver__nft_sales_magic_eden_cnft_onchain') }} A
INNER JOIN mint_addresses b
ON A.tx_id = b.tx_id

{% if is_incremental() %}
WHERE A._inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% endif %}
64 changes: 64 additions & 0 deletions models/silver/nfts/silver__nft_sales_magic_eden_cnft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
version: 2
models:
- name: silver__nft_sales_magic_eden_cnft
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_ID
- MINT
columns:
- name: BLOCK_TIMESTAMP
description: "{{ doc('block_timestamp') }}"
tests:
- not_null
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 2
- name: BLOCK_ID
description: "{{ doc('block_id') }}"
tests:
- not_null
- name: TX_ID
description: "{{ doc('tx_id') }}"
tests:
- not_null
- name: SUCCEEDED
description: "{{ doc('tx_succeeded') }}"
tests:
- not_null
- name: PROGRAM_ID
description: "{{ doc('program_id') }}"
tests:
- not_null
- name: PURCHASER
description: "{{ doc('purchaser') }}"
tests:
- not_null
- name: SELLER
description: "{{ doc('seller') }}"
tests:
- not_null
- name: SALES_AMOUNT
description: "{{ doc('sales_amount') }}"
tests:
- not_null
- name: TREE_AUTHORITY
description: "{{ doc('tree_authority') }}"
tests:
- not_null
- name: MERKLE_TREE
description: "{{ doc('merkle_tree') }}"
tests:
- not_null
- name: LEAF_INDEX
description: "{{ doc('leaf_index') }}"
tests:
- not_null
- name: MINT
description: "{{ doc('mint') }}"
tests:
- not_null
- name: _INSERTED_TIMESTAMP
description: "{{ doc('_inserted_timestamp') }}"
tests:
- not_null
69 changes: 69 additions & 0 deletions models/silver/nfts/silver__nft_sales_solsniper_cnft.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{{ config(
materialized = 'incremental',
unique_key = ['nft_sales_solsniper_cnft_id'],
incremental_strategy = 'delete+insert',
merge_exclude_columns = ["inserted_timestamp"],
tags = ['scheduled_non_core']
) }}

WITH mint_addresses AS (

SELECT
r.value :tx_id :: STRING AS tx_id,
COALESCE(
r.value :mint :: STRING,
''
) AS mint,
r.value :index :: INTEGER AS mint_index,
r.value :inner_index :: INTEGER AS mint_inner_index,
_inserted_timestamp AS mint_inserted_timestamp
FROM
{{ ref('bronze_api__parse_compressed_nft_sales_solsniper') }},
TABLE(FLATTEN(responses)) AS r
WHERE
mint <> ''
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(mint_inserted_timestamp)
FROM
{{ this }}
)
{% endif %}
qualify(ROW_NUMBER() over (PARTITION BY tx_id, mint
ORDER BY
_inserted_timestamp DESC)) = 1
)
SELECT
A.block_id,
A.block_timestamp,
A.program_id,
A.tx_id,
A.succeeded,
A.purchaser,
A.seller,
A.tree_authority,
A.merkle_tree,
A.leaf_index,
b.mint,
b.mint_inserted_timestamp,
A.sales_amount,
A._inserted_timestamp,
{{ dbt_utils.generate_surrogate_key(
['a.tx_id','b.mint']
) }} AS nft_sales_solsniper_cnft_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp
FROM
{{ ref('silver__nft_sales_solsniper_cnft_onchain') }} A
INNER JOIN mint_addresses b
ON A.tx_id = b.tx_id

{% if is_incremental() %}
WHERE A._inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% endif %}
64 changes: 64 additions & 0 deletions models/silver/nfts/silver__nft_sales_solsniper_cnft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
version: 2
models:
- name: silver__nft_sales_solsniper_cnft
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_ID
- MINT
columns:
- name: BLOCK_TIMESTAMP
description: "{{ doc('block_timestamp') }}"
tests:
- not_null
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 2
- name: BLOCK_ID
description: "{{ doc('block_id') }}"
tests:
- not_null
- name: TX_ID
description: "{{ doc('tx_id') }}"
tests:
- not_null
- name: SUCCEEDED
description: "{{ doc('tx_succeeded') }}"
tests:
- not_null
- name: PROGRAM_ID
description: "{{ doc('program_id') }}"
tests:
- not_null
- name: PURCHASER
description: "{{ doc('purchaser') }}"
tests:
- not_null
- name: SELLER
description: "{{ doc('seller') }}"
tests:
- not_null
- name: SALES_AMOUNT
description: "{{ doc('sales_amount') }}"
tests:
- not_null
- name: TREE_AUTHORITY
description: "{{ doc('tree_authority') }}"
tests:
- not_null
- name: MERKLE_TREE
description: "{{ doc('merkle_tree') }}"
tests:
- not_null
- name: LEAF_INDEX
description: "{{ doc('leaf_index') }}"
tests:
- not_null
- name: MINT
description: "{{ doc('mint') }}"
tests:
- not_null
- name: _INSERTED_TIMESTAMP
description: "{{ doc('_inserted_timestamp') }}"
tests:
- not_null

0 comments on commit 63c8647

Please sign in to comment.