mirror of
https://github.com/FlipsideCrypto/flow-models.git
synced 2026-02-06 15:51:48 +00:00
parent
b9d6ef2823
commit
c29567fb36
35
models/silver/silver__nft_la_liga_events.sql
Normal file
35
models/silver/silver__nft_la_liga_events.sql
Normal file
@ -0,0 +1,35 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
cluster_by = ['_inserted_timestamp::DATE'],
|
||||
unique_key = 'tx_id',
|
||||
incremental_strategy = 'delete+insert'
|
||||
) }}
|
||||
|
||||
WITH la_liga AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__events_final') }}
|
||||
WHERE
|
||||
event_contract ILIKE '%87ca73a41bb50ad5%'
|
||||
AND event_type IN (
|
||||
'PlayCreated',
|
||||
'EditionCreated',
|
||||
'SetCreated',
|
||||
'SeriesCreated'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
la_liga
|
||||
59
models/silver/silver__nft_la_liga_play_metadata.sql
Normal file
59
models/silver/silver__nft_la_liga_play_metadata.sql
Normal file
@ -0,0 +1,59 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
cluster_by = ['nft_id'],
|
||||
unique_key = 'nft_id',
|
||||
incremental_strategy = 'delete+insert'
|
||||
) }}
|
||||
|
||||
WITH liga_plays AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__nft_la_liga_events') }}
|
||||
WHERE
|
||||
event_type = 'PlayCreated'
|
||||
),
|
||||
play_metadata AS (
|
||||
SELECT
|
||||
event_data :id :: NUMBER AS nft_id_raw,
|
||||
VALUE :key :value :: STRING AS column_header,
|
||||
VALUE :value :value :: STRING AS column_value
|
||||
FROM
|
||||
liga_plays,
|
||||
LATERAL FLATTEN(input => TRY_PARSE_JSON(event_data :metadata))
|
||||
WHERE
|
||||
event_type = 'PlayCreated'
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
play_metadata pivot(MAX(column_value) for column_header IN ('PlayerCountry', 'MatchHighlightedTeam', 'MatchSeason', 'PlayerPosition', 'PlayType', 'MatchDate', 'PlayerLastName', 'PlayDataID', 'MatchDay', 'PlayTime', 'PlayerNumber', 'PlayerFirstName', 'PlayerKnownName', 'MatchHomeTeam', 'MatchAwayTeam', 'MatchHomeScore', 'MatchAwayScore', 'PlayerJerseyName', 'PlayHalf', 'PlayerDataID')) AS p (
|
||||
nft_id,
|
||||
player_country,
|
||||
match_highlighted_team,
|
||||
match_season,
|
||||
player_position,
|
||||
play_type,
|
||||
match_date,
|
||||
player_last_name,
|
||||
play_data_id,
|
||||
match_day,
|
||||
play_time,
|
||||
player_number,
|
||||
player_first_name,
|
||||
player_known_name,
|
||||
match_home_team,
|
||||
match_away_team,
|
||||
match_home_score,
|
||||
match_away_score,
|
||||
player_jersey_name,
|
||||
play_half,
|
||||
player_data_id
|
||||
)
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
FINAL
|
||||
Loading…
Reference in New Issue
Block a user