Nifi init
This commit is contained in:
18
nifi/sql/extract/01_dim_date.sql
Normal file
18
nifi/sql/extract/01_dim_date.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
-- Generates one row per calendar date covering the full EWC 2025 event window.
|
||||
-- Run on MySQL source DB.
|
||||
WITH RECURSIVE dates AS (
|
||||
SELECT DATE('2025-07-08') AS d
|
||||
UNION ALL
|
||||
SELECT DATE_ADD(d, INTERVAL 1 DAY) FROM dates WHERE d < '2025-08-24'
|
||||
)
|
||||
SELECT
|
||||
CAST(DATE_FORMAT(d, '%Y%m%d') AS UNSIGNED) AS date_key,
|
||||
d AS full_date,
|
||||
YEAR(d) AS year,
|
||||
QUARTER(d) AS quarter,
|
||||
MONTH(d) AS month,
|
||||
MONTHNAME(d) AS month_name,
|
||||
WEEK(d, 1) AS week_number,
|
||||
DAYOFMONTH(d) AS day_of_month,
|
||||
DAYNAME(d) AS day_name
|
||||
FROM dates;
|
||||
2
nifi/sql/extract/02_dim_game.sql
Normal file
2
nifi/sql/extract/02_dim_game.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
SELECT game_id, name, game_type, platform
|
||||
FROM game;
|
||||
2
nifi/sql/extract/03_dim_country.sql
Normal file
2
nifi/sql/extract/03_dim_country.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
SELECT country_id, name, region
|
||||
FROM country;
|
||||
10
nifi/sql/extract/04_dim_organization.sql
Normal file
10
nifi/sql/extract/04_dim_organization.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
SELECT
|
||||
o.organization_id,
|
||||
o.name,
|
||||
o.region,
|
||||
c.name AS country,
|
||||
o.club_partner_status,
|
||||
o.founded_year,
|
||||
o.social_media_followers_m
|
||||
FROM organization o
|
||||
LEFT JOIN country c ON o.country_id = c.country_id;
|
||||
18
nifi/sql/extract/05_fact_tournament.sql
Normal file
18
nifi/sql/extract/05_fact_tournament.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
-- Returns one row per tournament with all natural keys needed for Oracle DIM lookups.
|
||||
-- winner_org_id is NULL when the winner is an individual (Chess, StarCraft II, etc.)
|
||||
SELECT
|
||||
t.game_id,
|
||||
CAST(DATE_FORMAT(t.start_date, '%Y%m%d') AS UNSIGNED) AS start_date_key,
|
||||
CAST(DATE_FORMAT(t.end_date, '%Y%m%d') AS UNSIGNED) AS end_date_key,
|
||||
o.organization_id AS winner_org_id,
|
||||
t.event_name,
|
||||
t.gender,
|
||||
t.prize_pool_usd,
|
||||
t.num_participants,
|
||||
COALESCE(s.duration_days,
|
||||
DATEDIFF(t.end_date, t.start_date) + 1) AS duration_days,
|
||||
CASE WHEN t.club_championship_points = 1 THEN 1 ELSE 0
|
||||
END AS has_club_points
|
||||
FROM tournament t
|
||||
LEFT JOIN schedule s ON t.tournament_id = s.tournament_id
|
||||
LEFT JOIN organization o ON o.name = t.winner;
|
||||
16
nifi/sql/extract/06_fact_medal_award.sql
Normal file
16
nifi/sql/extract/06_fact_medal_award.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
-- Returns one row per player-medal with natural keys and pre-computed measures.
|
||||
SELECT
|
||||
t.game_id,
|
||||
m.country_id,
|
||||
m.organization_id,
|
||||
m.medal AS medal_type,
|
||||
CAST(DATE_FORMAT(t.start_date, '%Y%m%d') AS UNSIGNED) AS date_key,
|
||||
m.player_name,
|
||||
1 AS medal_count,
|
||||
CASE m.medal
|
||||
WHEN 'Gold' THEN 3
|
||||
WHEN 'Silver' THEN 2
|
||||
ELSE 1
|
||||
END AS medal_points
|
||||
FROM medalist m
|
||||
JOIN tournament t ON m.tournament_id = t.tournament_id;
|
||||
9
nifi/sql/extract/07_fact_club_standing.sql
Normal file
9
nifi/sql/extract/07_fact_club_standing.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
SELECT
|
||||
organization_id,
|
||||
`rank` AS final_rank,
|
||||
total_points,
|
||||
prize_money_usd,
|
||||
tournament_wins,
|
||||
top_8_finishes,
|
||||
CASE WHEN eligible_to_win = 1 THEN 1 ELSE 0 END AS eligible_to_win
|
||||
FROM club_championship_standing;
|
||||
12
nifi/sql/load/01_dim_date.sql
Normal file
12
nifi/sql/load/01_dim_date.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
INSERT INTO DIM_DATE (date_key, full_date, year, quarter, month, month_name, week_number, day_of_month, day_name)
|
||||
VALUES (
|
||||
${date_key},
|
||||
TO_DATE('${full_date}', 'YYYY-MM-DD'),
|
||||
${year},
|
||||
${quarter},
|
||||
${month},
|
||||
'${month_name}',
|
||||
${week_number},
|
||||
${day_of_month},
|
||||
'${day_name}'
|
||||
)
|
||||
4
nifi/sql/load/02_dim_medal.sql
Normal file
4
nifi/sql/load/02_dim_medal.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
-- Static seed — run once via ExecuteSQL on Oracle, no extract needed.
|
||||
INSERT INTO DIM_MEDAL (medal_type, medal_rank) VALUES ('Gold', 1);
|
||||
INSERT INTO DIM_MEDAL (medal_type, medal_rank) VALUES ('Silver', 2);
|
||||
INSERT INTO DIM_MEDAL (medal_type, medal_rank) VALUES ('Bronze', 3);
|
||||
7
nifi/sql/load/03_dim_game.sql
Normal file
7
nifi/sql/load/03_dim_game.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
INSERT INTO DIM_GAME (game_id, name, game_type, platform)
|
||||
VALUES (
|
||||
${game_id},
|
||||
'${name}',
|
||||
'${game_type}',
|
||||
'${platform}'
|
||||
)
|
||||
6
nifi/sql/load/04_dim_country.sql
Normal file
6
nifi/sql/load/04_dim_country.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
INSERT INTO DIM_COUNTRY (country_id, name, region)
|
||||
VALUES (
|
||||
${country_id},
|
||||
'${name}',
|
||||
'${region}'
|
||||
)
|
||||
10
nifi/sql/load/05_dim_organization.sql
Normal file
10
nifi/sql/load/05_dim_organization.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
INSERT INTO DIM_ORGANIZATION (org_id, name, region, country, club_partner_status, founded_year, social_media_followers_m)
|
||||
VALUES (
|
||||
${organization_id},
|
||||
'${name}',
|
||||
${region:isEmpty():ifElse('NULL', concat("'", ${region}, "'"))},
|
||||
${country:isEmpty():ifElse('NULL', concat("'", ${country}, "'"))},
|
||||
${club_partner_status:isEmpty():ifElse('NULL', concat("'", ${club_partner_status}, "'"))},
|
||||
${founded_year:isEmpty():ifElse('NULL', ${founded_year})},
|
||||
${social_media_followers_m:isEmpty():ifElse('NULL', ${social_media_followers_m})}
|
||||
)
|
||||
18
nifi/sql/load/06_fact_tournament.sql
Normal file
18
nifi/sql/load/06_fact_tournament.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
-- Sub-SELECTs resolve natural keys to surrogate keys already loaded in DIM tables.
|
||||
INSERT INTO FACT_TOURNAMENT (
|
||||
game_key, start_date_key, end_date_key, winner_org_key,
|
||||
event_name, gender, prize_pool_usd, num_participants, duration_days, has_club_points
|
||||
)
|
||||
SELECT
|
||||
(SELECT game_key FROM DIM_GAME WHERE game_id = ${game_id}),
|
||||
${start_date_key},
|
||||
${end_date_key},
|
||||
${winner_org_id:isEmpty():ifElse('NULL',
|
||||
concat('(SELECT org_key FROM DIM_ORGANIZATION WHERE org_id = ', ${winner_org_id}, ')'))},
|
||||
'${event_name}',
|
||||
'${gender}',
|
||||
${prize_pool_usd},
|
||||
${num_participants},
|
||||
${duration_days},
|
||||
${has_club_points}
|
||||
FROM DUAL
|
||||
16
nifi/sql/load/07_fact_medal_award.sql
Normal file
16
nifi/sql/load/07_fact_medal_award.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
INSERT INTO FACT_MEDAL_AWARD (
|
||||
game_key, medal_key, country_key, org_key, date_key,
|
||||
player_name, medal_count, medal_points
|
||||
)
|
||||
SELECT
|
||||
(SELECT game_key FROM DIM_GAME WHERE game_id = ${game_id}),
|
||||
(SELECT medal_key FROM DIM_MEDAL WHERE medal_type = '${medal_type}'),
|
||||
${country_id:isEmpty():ifElse('NULL',
|
||||
concat('(SELECT country_key FROM DIM_COUNTRY WHERE country_id = ', ${country_id}, ')'))},
|
||||
${organization_id:isEmpty():ifElse('NULL',
|
||||
concat('(SELECT org_key FROM DIM_ORGANIZATION WHERE org_id = ', ${organization_id}, ')'))},
|
||||
${date_key},
|
||||
'${player_name}',
|
||||
${medal_count},
|
||||
${medal_points}
|
||||
FROM DUAL
|
||||
13
nifi/sql/load/08_fact_club_standing.sql
Normal file
13
nifi/sql/load/08_fact_club_standing.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
INSERT INTO FACT_CLUB_STANDING (
|
||||
org_key, final_rank, total_points, prize_money_usd,
|
||||
tournament_wins, top_8_finishes, eligible_to_win
|
||||
)
|
||||
SELECT
|
||||
(SELECT org_key FROM DIM_ORGANIZATION WHERE org_id = ${organization_id}),
|
||||
${final_rank},
|
||||
${total_points},
|
||||
${prize_money_usd},
|
||||
${tournament_wins},
|
||||
${top_8_finishes},
|
||||
${eligible_to_win}
|
||||
FROM DUAL
|
||||
Reference in New Issue
Block a user