AN-2632/liga play metadata (#83)

* liga

* incr

* typo
This commit is contained in:
Jack Forgash 2022-11-08 12:01:17 -07:00 committed by GitHub
parent b9d6ef2823
commit c29567fb36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 94 additions and 0 deletions

View 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

View 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