-- ============================================================================
-- MARS-826 Export Step 06: FORECAST Tables
-- ============================================================================
-- Purpose: Export FORECAST table group to HIST bucket
-- Author: Grzegorz Michalski
-- Tables: 2 tables (~21.6M records total - VERY LARGE DATASET)
-- Target: mrds_hist_dev/ARCHIVE/LM/LM_FORECAST_*
-- ============================================================================

SET SERVEROUTPUT ON SIZE UNLIMITED

PROMPT
PROMPT ============================================================================
PROMPT Step 06: Exporting FORECAST Tables (2 tables, ~21.6M records)
PROMPT WARNING: LARGEST DATASET - this may take significant time
PROMPT ============================================================================

-- START TIMING
PROMPT
SELECT 'START_TIME: ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') AS TIMING FROM DUAL;

-- Table 1: LEGACY_FORECAST_HEADER (~42,504 records)
PROMPT
PROMPT Exporting OU_LM.LEGACY_FORECAST_HEADER...
BEGIN
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_LM',
        pTableName => 'LEGACY_FORECAST_HEADER',
        pKeyColumnName => 'A_ETL_LOAD_SET_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/LM/LM_FORECAST_HEADER',
        pParallelDegree => 4,
        pTemplateTableName => 'CT_ET_TEMPLATES.LM_FORECAST_HEADER',
        pJobClass => 'high'
    );
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_FORECAST_HEADER exported');
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('ERROR exporting FORECAST_HEADER: ' || SQLERRM);
        RAISE;
END;
/

-- Table 2: LEGACY_FORECAST_ITEM (~21,643,855 records - LARGEST TABLE)
PROMPT
PROMPT Exporting OU_LM.LEGACY_FORECAST_ITEM (LARGEST TABLE ~21.6M records)...
BEGIN
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_LM',
        pTableName => 'LEGACY_FORECAST_ITEM',
        pKeyColumnName => 'A_ETL_LOAD_SET_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/LM/LM_FORECAST_ITEM',
        pParallelDegree => 16,
        pTemplateTableName => 'CT_ET_TEMPLATES.LM_FORECAST_ITEM',
        pJobClass => 'high'
    );
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_FORECAST_ITEM exported');
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('ERROR exporting FORECAST_ITEM: ' || SQLERRM);
        RAISE;
END;
/

-- END TIMING
PROMPT
SELECT 'END_TIME: ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') AS TIMING FROM DUAL;

PROMPT
PROMPT Step 06 completed: All FORECAST tables exported
PROMPT
