-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
final silver cnft sales model (#545)
- Loading branch information
1 parent
0d1c268
commit 63c8647
Showing
4 changed files
with
266 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |