-- STACK 4: 15,000-LINE ORACLE PL/SQL STORED PROCEDURES TO SNOWFLAKE DBT + SNOWPARK PYTHON
-- Extracts undocumented cursor loops and implicit triggers into versioned, testable data models
-- Elatre Differential Data Parity Gate (Executed Automatically in CI/CD):
WITH legacy_oracle_snapshot AS (
SELECT account_id, fiscal_period, ROUND(net_exposure_usd, 4) AS exposure
FROM raw_migration_audit.oracle_plsql_baseline_202611
),
modern_snowflake_dbt AS (
SELECT account_id, fiscal_period, ROUND(net_exposure_usd, 4) AS exposure
FROM prod_Gold_finops.fct_account_exposure_dbt
)
, legacy_row_counts AS (
SELECT account_id, fiscal_period, exposure, COUNT(*) AS occurrences
FROM legacy_oracle_snapshot
GROUP BY account_id, fiscal_period, exposure
), modern_row_counts AS (
SELECT account_id, fiscal_period, exposure, COUNT(*) AS occurrences
FROM modern_snowflake_dbt
GROUP BY account_id, fiscal_period, exposure
)
SELECT COALESCE(SUM(ABS(COALESCE(l.occurrences, 0)
- COALESCE(m.occurrences, 0))), 0) AS row_discrepancies
FROM legacy_row_counts l
FULL OUTER JOIN modern_row_counts m
ON l.account_id IS NOT DISTINCT FROM m.account_id
AND l.fiscal_period IS NOT DISTINCT FROM m.fiscal_period
AND l.exposure IS NOT DISTINCT FROM m.exposure;
-- Release Gate Requirement: row_discrepancies MUST EQUAL 0 across 50M+ historical ledger rows.