Nifi init

This commit is contained in:
2026-05-17 16:54:29 +02:00
parent 6203332841
commit 9cc58c20f4
15 changed files with 161 additions and 0 deletions

View 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;

View File

@@ -0,0 +1,2 @@
SELECT game_id, name, game_type, platform
FROM game;

View File

@@ -0,0 +1,2 @@
SELECT country_id, name, region
FROM country;

View 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;

View 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;

View 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;

View 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;

View 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}'
)

View 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);

View File

@@ -0,0 +1,7 @@
INSERT INTO DIM_GAME (game_id, name, game_type, platform)
VALUES (
${game_id},
'${name}',
'${game_type}',
'${platform}'
)

View File

@@ -0,0 +1,6 @@
INSERT INTO DIM_COUNTRY (country_id, name, region)
VALUES (
${country_id},
'${name}',
'${region}'
)

View 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})}
)

View 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

View 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

View 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