diff --git a/nifi/sql/extract/01_dim_date.sql b/nifi/sql/extract/01_dim_date.sql new file mode 100644 index 0000000..1481607 --- /dev/null +++ b/nifi/sql/extract/01_dim_date.sql @@ -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; diff --git a/nifi/sql/extract/02_dim_game.sql b/nifi/sql/extract/02_dim_game.sql new file mode 100644 index 0000000..aad5a63 --- /dev/null +++ b/nifi/sql/extract/02_dim_game.sql @@ -0,0 +1,2 @@ +SELECT game_id, name, game_type, platform +FROM game; diff --git a/nifi/sql/extract/03_dim_country.sql b/nifi/sql/extract/03_dim_country.sql new file mode 100644 index 0000000..b38abc1 --- /dev/null +++ b/nifi/sql/extract/03_dim_country.sql @@ -0,0 +1,2 @@ +SELECT country_id, name, region +FROM country; diff --git a/nifi/sql/extract/04_dim_organization.sql b/nifi/sql/extract/04_dim_organization.sql new file mode 100644 index 0000000..765076d --- /dev/null +++ b/nifi/sql/extract/04_dim_organization.sql @@ -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; diff --git a/nifi/sql/extract/05_fact_tournament.sql b/nifi/sql/extract/05_fact_tournament.sql new file mode 100644 index 0000000..b636c43 --- /dev/null +++ b/nifi/sql/extract/05_fact_tournament.sql @@ -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; diff --git a/nifi/sql/extract/06_fact_medal_award.sql b/nifi/sql/extract/06_fact_medal_award.sql new file mode 100644 index 0000000..038aa48 --- /dev/null +++ b/nifi/sql/extract/06_fact_medal_award.sql @@ -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; diff --git a/nifi/sql/extract/07_fact_club_standing.sql b/nifi/sql/extract/07_fact_club_standing.sql new file mode 100644 index 0000000..9013032 --- /dev/null +++ b/nifi/sql/extract/07_fact_club_standing.sql @@ -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; diff --git a/nifi/sql/load/01_dim_date.sql b/nifi/sql/load/01_dim_date.sql new file mode 100644 index 0000000..0e864e7 --- /dev/null +++ b/nifi/sql/load/01_dim_date.sql @@ -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}' +) diff --git a/nifi/sql/load/02_dim_medal.sql b/nifi/sql/load/02_dim_medal.sql new file mode 100644 index 0000000..c91085f --- /dev/null +++ b/nifi/sql/load/02_dim_medal.sql @@ -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); diff --git a/nifi/sql/load/03_dim_game.sql b/nifi/sql/load/03_dim_game.sql new file mode 100644 index 0000000..6e484f1 --- /dev/null +++ b/nifi/sql/load/03_dim_game.sql @@ -0,0 +1,7 @@ +INSERT INTO DIM_GAME (game_id, name, game_type, platform) +VALUES ( + ${game_id}, + '${name}', + '${game_type}', + '${platform}' +) diff --git a/nifi/sql/load/04_dim_country.sql b/nifi/sql/load/04_dim_country.sql new file mode 100644 index 0000000..cf02b1d --- /dev/null +++ b/nifi/sql/load/04_dim_country.sql @@ -0,0 +1,6 @@ +INSERT INTO DIM_COUNTRY (country_id, name, region) +VALUES ( + ${country_id}, + '${name}', + '${region}' +) diff --git a/nifi/sql/load/05_dim_organization.sql b/nifi/sql/load/05_dim_organization.sql new file mode 100644 index 0000000..3a4f809 --- /dev/null +++ b/nifi/sql/load/05_dim_organization.sql @@ -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})} +) diff --git a/nifi/sql/load/06_fact_tournament.sql b/nifi/sql/load/06_fact_tournament.sql new file mode 100644 index 0000000..90eba5f --- /dev/null +++ b/nifi/sql/load/06_fact_tournament.sql @@ -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 diff --git a/nifi/sql/load/07_fact_medal_award.sql b/nifi/sql/load/07_fact_medal_award.sql new file mode 100644 index 0000000..0d087b9 --- /dev/null +++ b/nifi/sql/load/07_fact_medal_award.sql @@ -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 diff --git a/nifi/sql/load/08_fact_club_standing.sql b/nifi/sql/load/08_fact_club_standing.sql new file mode 100644 index 0000000..7164ec8 --- /dev/null +++ b/nifi/sql/load/08_fact_club_standing.sql @@ -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