--=============================================================================================================================
-- MARS-835: Export Group 1 - HIST Only (DEBT, DEBT_DAILY)
--=============================================================================================================================
-- Purpose: Export ALL data to HIST bucket (Parquet with Hive-style partitioning)
--          Applies column mapping: A_ETL_LOAD_SET_FK to A_WORKFLOW_HISTORY_KEY
--          Excludes legacy columns not required in new structure
--          USES: DATA_EXPORTER v2.12.0 with pTemplateTableName for column order and date formats
-- Author: Grzegorz Michalski
-- Date: 2025-12-17
-- Updated: 2026-02-24 (Changed to HIST-only export, no DATA bucket split)
-- Related: MARS-835 - CSDB Data Export
--=============================================================================================================================

SET SERVEROUTPUT ON SIZE UNLIMITED
SET TIMING ON

PROMPT ========================================================================
PROMPT Exporting CSDB.DEBT - HIST Only
PROMPT ========================================================================
PROMPT ALL data to HIST bucket (Parquet with Hive-style partitioning)
PROMPT Column mapping: A_ETL_LOAD_SET_FK to A_WORKFLOW_HISTORY_KEY
PROMPT Excluded columns: IDIRDEPOSITORY, VA_BONDDURATION
PROMPT ========================================================================

-- Export ALL data to HIST bucket (Parquet)
-- NEW v2.12.0: Per-column date format handling with template table, full data range
BEGIN
    DBMS_OUTPUT.PUT_LINE('Exporting LEGACY_DEBT data to HIST bucket (ALL data)...');
    DBMS_OUTPUT.PUT_LINE('Using Template Table: CT_ET_TEMPLATES.CSDB_DEBT');
    
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_CSDB',
        pTableName => 'LEGACY_DEBT',
        pKeyColumnName => 'A_ETL_LOAD_SET_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/CSDB/CSDB_DEBT',
        pMinDate => DATE '1900-01-01',  -- Include all historical data
        pMaxDate => DATE '9999-12-31',  -- Include all future dates
        pParallelDegree => 16,
        pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_DEBT',
        pJobClass => 'high'  -- Oracle Scheduler job class for resource management
    );
    
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_DEBT exported to HIST bucket with template column order');
END;
/

PROMPT ========================================================================
PROMPT Exporting CSDB.LEGACY_DEBT_DAILY - HIST Only
PROMPT ========================================================================
PROMPT ALL data to HIST bucket (Parquet with Hive-style partitioning)
PROMPT Column mapping: A_ETL_LOAD_SET_FK to A_WORKFLOW_HISTORY_KEY
PROMPT Excluded columns: STEPID, PROGRAMNAME, PROGRAMCEILING, PROGRAMSTATUS,
PROMPT                   ISSUERNACE21SECTOR, INSTRUMENTQUOTATIONBASIS
PROMPT ========================================================================

-- Export ALL data to HIST bucket (Parquet)
-- NEW v2.12.0: Per-column date format handling with template table, full data range
BEGIN
    DBMS_OUTPUT.PUT_LINE('Exporting LEGACY_DEBT_DAILY data to HIST bucket (ALL data)...');
    DBMS_OUTPUT.PUT_LINE('Using Template Table: CT_ET_TEMPLATES.CSDB_DEBT_DAILY');
    
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_CSDB',
        pTableName => 'LEGACY_DEBT_DAILY',
        pKeyColumnName => 'A_ETL_LOAD_SET_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/CSDB/CSDB_DEBT_DAILY',
        pMinDate => DATE '1900-01-01',  -- Include all historical data
        pMaxDate => DATE '9999-12-31',  -- Include all future dates
        pParallelDegree => 16,
        pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_DEBT_DAILY',
        pJobClass => 'high'  -- Oracle Scheduler job class for resource management
    );
    
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_DEBT_DAILY exported to HIST bucket with template column order');
END;
/

PROMPT ========================================================================
PROMPT Group 1 Export Completed
PROMPT ========================================================================
PROMPT - LEGACY_DEBT: HIST exported (ALL data)
PROMPT - LEGACY_DEBT_DAILY: HIST exported (ALL data)
PROMPT ========================================================================

--=============================================================================================================================
-- End of Script
--=============================================================================================================================
