-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add query nft trades labels #1513
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5fb108b
add nft query labels
soispoke 8d6c07f
Update dbt_project.yml
soispoke 6663919
fix created at to correct (past date)
soispoke 688f4e5
remove ?
soispoke 3d413ed
Merge branch 'main' into Add-query-NFT-trades-labels
soispoke 4fdb79b
Merge branch 'main' into Add-query-NFT-trades-labels
soispoke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,7 @@ | ||
{{config(alias='nft')}} | ||
|
||
SELECT * FROM {{ ref('labels_nft_traders_transactions') }} | ||
UNION | ||
SELECT * FROM {{ ref('labels_nft_traders_volume_usd') }} | ||
UNION | ||
SELECT * FROM {{ ref('labels_nft_users_platforms') }} |
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,113 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: labels_nft | ||
meta: | ||
blockchain: ethereum, solana | ||
sector: labels | ||
category: nft | ||
project: ['opensea', 'looksrare', 'x2y2', 'magiceden'] | ||
contibutors: soispoke | ||
config: | ||
tags: ['labels', 'nft', 'ethereum', 'solana', 'opensea', 'looksrare', 'x2y2', 'magiceden'] | ||
description: "NFT query labels" | ||
columns: | ||
- name: blockchain | ||
description: "Blockchain on which NFT trades have been made" | ||
- name: address | ||
description: "Address of NFT traders" | ||
- name: name | ||
description: "Label name NFT trader (Top 1, 5, 10% or simply NFT Trader when an address has traded NFTs but is not in top top 10 or above)" | ||
- name: category | ||
description: "Label category (NFT here)" | ||
- name: contributor | ||
description: "Wizard(s) contributing to labels" | ||
- name: source | ||
description: "How were labels generated (could be static or query)" | ||
- name: created_at | ||
description: "When were labels created" | ||
- name: updated_at | ||
description: "When were labels updated for the last time" | ||
|
||
- name: labels_nft_users_platforms | ||
meta: | ||
blockchain: ethereum, solana | ||
sector: labels | ||
category: nft | ||
project: ['labels','opensea', 'looksrare', 'x2y2', 'magiceden'] | ||
contibutors: soispoke | ||
config: | ||
tags: ['labels', 'nft_traders', 'ethereum', 'solana', 'opensea', 'looksrare', 'x2y2', 'magiceden'] | ||
description: "NFT Platforms users across chains" | ||
columns: | ||
- name: blockchain | ||
description: "Blockchain" | ||
- name: address | ||
description: "Address of NFT platforms users" | ||
- name: name | ||
description: "Label name (NFT Platform User)" | ||
- name: category | ||
description: "Label category (NFT here)" | ||
- name: contributor | ||
description: "Wizard(s) contributing to labels" | ||
- name: source | ||
description: "How were labels generated (could be static or query)" | ||
- name: created_at | ||
description: "When were labels created" | ||
- name: updated_at | ||
description: "When were labels updated for the last time" | ||
|
||
- name: labels_nft_traders_transactions | ||
meta: | ||
blockchain: ethereum, solana | ||
sector: labels | ||
category: nft | ||
project: ['labels','opensea', 'looksrare', 'x2y2', 'magiceden'] | ||
contibutors: soispoke | ||
config: | ||
tags: ['labels', 'nft_traders', 'ethereum', 'solana', 'opensea', 'looksrare', 'x2y2', 'magiceden'] | ||
description: "Top NFT traders based on the number of transactions across chains" | ||
columns: | ||
- name: blockchain | ||
description: "Blockchain on which NFT trades have been made" | ||
- name: address | ||
description: "Address of NFT traders" | ||
- name: name | ||
description: "Label name NFT trader (Top 1, 5, 10% or simply NFT Trader when an address has traded NFTs but is not in top top 10 or above)" | ||
- name: category | ||
description: "Label category (NFT here)" | ||
- name: contributor | ||
description: "Wizard(s) contributing to labels" | ||
- name: source | ||
description: "How were labels generated (could be static or query)" | ||
- name: created_at | ||
description: "When were labels created" | ||
- name: updated_at | ||
description: "When were labels updated for the last time" | ||
|
||
- name: labels_nft_traders_volume_usd | ||
meta: | ||
blockchain: ethereum, solana | ||
sector: labels | ||
project: ['labels','opensea', 'looksrare', 'x2y2', 'magiceden'] | ||
contibutors: soispoke | ||
config: | ||
tags: ['labels', 'nft_traders', 'ethereum', 'solana', 'opensea', 'looksrare', 'x2y2', 'magiceden'] | ||
description: "Top NFT traders based on volume in USD across chains" | ||
columns: | ||
- name: blockchain | ||
description: "Blockchain on which NFT trades have been made" | ||
- name: address | ||
description: "Address of NFT traders" | ||
- name: name | ||
description: "Label name NFT trader (Top 1, 5, 10% or simply NFT Trader when an address has traded NFTs but is not in top top 10 or above)" | ||
- name: category | ||
description: "Label category (NFT here)" | ||
- name: contributor | ||
description: "Wizard(s) contributing to labels" | ||
- name: source | ||
description: "How were labels generated (could be static or query)" | ||
- name: created_at | ||
description: "When were labels created" | ||
- name: updated_at | ||
description: "When were labels updated for the last time" |
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,45 @@ | ||
|
||
{{config(alias='nft_traders_transactions')}} | ||
|
||
WITH nft_trades AS ( | ||
SELECT | ||
blockchain, | ||
tx_hash, | ||
buyer AS address | ||
FROM {{ ref('nft_trades') }} | ||
UNION | ||
SELECT | ||
blockchain, | ||
tx_hash, | ||
seller AS address | ||
FROM {{ ref('nft_trades') }} | ||
), | ||
|
||
total as ( | ||
SELECT | ||
address, | ||
COUNT(tx_hash) AS total_count | ||
FROM nft_trades | ||
GROUP BY 1 | ||
) | ||
|
||
SELECT | ||
collect_set(nft_trades.blockchain) as blockchain, | ||
nft_trades.address, | ||
CASE WHEN ((ROW_NUMBER() OVER(ORDER BY COUNT(tx_hash) DESC)) / total_count * 100) <= 10 | ||
AND ((ROW_NUMBER() OVER(ORDER BY COUNT(tx_hash) DESC)) / total_count * 100) > 5 | ||
THEN 'Top 10% NFT Trader (Transaction)' | ||
WHEN ((ROW_NUMBER() OVER(ORDER BY COUNT(tx_hash) DESC)) / total_count * 100) <= 5 | ||
AND ((ROW_NUMBER() OVER(ORDER BY COUNT(tx_hash) DESC)) / total_count * 100) > 1 | ||
THEN 'Top 5% NFT Trader (Transactions)' | ||
WHEN ((ROW_NUMBER() OVER(ORDER BY COUNT(tx_hash) DESC)) / total_count * 100) <= 1 | ||
THEN 'Top 1% NFT Trader (Transactions)' END AS name, | ||
'nft' AS category, | ||
'soispoke' AS contributor, | ||
'query' AS source, | ||
timestamp('2022-08-24') as created_at, | ||
now() as updated_at | ||
FROM nft_trades | ||
JOIN total on total.address = nft_trades.address | ||
WHERE nft_trades.address is not null | ||
GROUP BY nft_trades.address, total_count |
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,44 @@ | ||
{{config(alias='nft_traders_volume_usd')}} | ||
|
||
WITH nft_trades AS ( | ||
SELECT | ||
blockchain, | ||
amount_usd, | ||
buyer AS address | ||
FROM {{ ref('nft_trades') }} | ||
UNION | ||
SELECT | ||
blockchain, | ||
amount_usd, | ||
seller AS address | ||
FROM {{ ref('nft_trades') }} | ||
), | ||
|
||
total as ( | ||
SELECT | ||
address, | ||
SUM(amount_usd) AS total_count | ||
FROM nft_trades | ||
GROUP BY 1 | ||
) | ||
|
||
SELECT | ||
collect_set(nft_trades.blockchain) as blockchain, | ||
nft_trades.address, | ||
CASE WHEN ((ROW_NUMBER() OVER(ORDER BY SUM(amount_usd) DESC)) / total_count * 100) <= 10 | ||
AND ((ROW_NUMBER() OVER(ORDER BY SUM(amount_usd) DESC)) / total_count * 100) > 5 | ||
THEN 'Top 10% NFT Trader (Volume in $USD)' | ||
WHEN ((ROW_NUMBER() OVER(ORDER BY SUM(amount_usd) DESC)) / total_count * 100) <= 5 | ||
AND ((ROW_NUMBER() OVER(ORDER BY SUM(amount_usd) DESC)) / total_count * 100) > 1 | ||
THEN 'Top 5% NFT Trader (Volume in $USD)' | ||
WHEN ((ROW_NUMBER() OVER(ORDER BY SUM(amount_usd) DESC)) / total_count * 100) <= 1 | ||
THEN 'Top 1% NFT Trader (Volume in $USD)' END AS name, | ||
'nft' AS category, | ||
'soispoke' AS contributor, | ||
'query' AS source, | ||
timestamp('2022-08-24') as created_at, | ||
now() as updated_at | ||
FROM nft_trades | ||
JOIN total on total.address = nft_trades.address | ||
WHERE nft_trades.address is not null and amount_usd is not null | ||
GROUP BY nft_trades.address, total_count |
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,28 @@ | ||
{{config(alias='nft_users_platforms')}} | ||
|
||
WITH nft_trades AS ( | ||
SELECT | ||
blockchain, | ||
project, | ||
buyer AS address | ||
FROM {{ ref('nft_trades') }} | ||
UNION | ||
SELECT | ||
blockchain, | ||
project, | ||
seller AS address | ||
FROM {{ ref('nft_trades') }} | ||
) | ||
|
||
SELECT | ||
collect_set(blockchain) as blockchain, | ||
address, | ||
array_join(collect_set(concat(upper(substring(project,1,1)),substring(project,2))), ', ') ||' User' as name, | ||
'nft' AS category, | ||
'soispoke' AS contributor, | ||
'query' AS source, | ||
timestamp('2022-09-03') as created_at, | ||
now() as updated_at | ||
FROM nft_trades | ||
WHERE address is not null | ||
GROUP BY address |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to also add an alter table statement for this. Could you try adding it to
post_hook
here, would be interesting to see if it works. Because then we can keep those things in the files and not forget.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I initially didn't want to expose the labels yet, until we have added a couple more queries/static labels. I also don't really want to add alter table statements as post hook as I've done this before and it ended up being extremely long and messy in the dbt_project.yml file. I think the most promising avenue is to alter table properties in the models directly (databricks/dbt-databricks#33), but we have to wait until the databricks adapter is supported by dbt cloud.
In any case, maybe we could open another PR/discussion around this ?