-- 핵심 Gold 테이블의 upstream이 제시간에 업데이트되었는지 확인
WITH gold_tables AS (
SELECT 'production.ecommerce.gold_daily_revenue' AS table_name, 6 AS sla_hour
UNION ALL
SELECT 'production.ecommerce.gold_customer_360', 8
),
upstream_freshness AS (
SELECT
g.table_name AS gold_table,
g.sla_hour,
l.source_table_full_name,
MAX(h.timestamp) AS last_update
FROM gold_tables g
JOIN system.lineage.table_lineage l
ON g.table_name = l.target_table_full_name
JOIN (
-- 각 소스 테이블의 마지막 업데이트 시간 (DESCRIBE HISTORY 대용)
SELECT table_full_name, MAX(event_time) AS timestamp
FROM system.lineage.table_lineage
GROUP BY table_full_name
) h ON l.source_table_full_name = h.table_full_name
GROUP BY g.table_name, g.sla_hour, l.source_table_full_name
)
SELECT
gold_table,
source_table_full_name,
last_update,
CASE
WHEN last_update < DATEADD(hour, -sla_hour, CURRENT_TIMESTAMP())
THEN '🔴 SLA 위반'
ELSE '🟢 정상'
END AS sla_status
FROM upstream_freshness;