--=============================================================================================================================
-- MARS-835: Export Group 2 - HIST Only (4 tables)
--=============================================================================================================================
-- Purpose: Export all data to HIST bucket (Parquet with Hive partitioning)
--          Tables: INSTR_RAT_FULL, INSTR_DESC_FULL, ISSUER_RAT_FULL, ISSUER_DESC_FULL
--          Applies column mapping: A_ETL_LOAD_SET_FK to A_WORKFLOW_HISTORY_KEY
--          No column exclusions for these tables
--          USES: DATA_EXPORTER v2.4.0 with per-column date format handling
-- Author: Grzegorz Michalski
-- Date: 2025-12-17
-- Updated: 2026-01-11 (Updated to DATA_EXPORTER v2.4.0 with pTemplateTableName)
-- Related: MARS-835 - CSDB Data Export
--=============================================================================================================================

SET SERVEROUTPUT ON SIZE UNLIMITED
SET TIMING ON

PROMPT ========================================================================
PROMPT Exporting CSDB.LEGACY_INSTR_RAT_FULL - HIST Only
PROMPT ========================================================================
PROMPT All data to HIST bucket (Parquet with partitioning)
PROMPT Column mapping: A_ETL_LOAD_SET_FK to A_WORKFLOW_HISTORY_KEY
PROMPT ========================================================================

-- NEW v2.4.0: Per-column date format handling via pTemplateTableName
BEGIN
    DBMS_OUTPUT.PUT_LINE('Exporting LEGACY_INSTR_RAT_FULL data to HIST bucket...');
    DBMS_OUTPUT.PUT_LINE('Using Template Table: CT_ET_TEMPLATES.CSDB_INSTR_RAT_FULL');
    
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_CSDB',
        pTableName => 'LEGACY_INSTR_RAT_FULL',
        pKeyColumnName => 'A_ETL_LOAD_SET_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/CSDB/CSDB_INSTR_RAT_FULL',
        pMinDate => DATE '1900-01-01',  -- Explicit start date for clarity
        pMaxDate => DATE '9999-12-31',  -- Include future dates (MAX_LOAD_START can be beyond SYSDATE)
        pParallelDegree => 8,
        pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_INSTR_RAT_FULL',
        pJobClass => 'high'  -- Oracle Scheduler job class for resource management
    );
    
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_INSTR_RAT_FULL exported to HIST bucket with template column order');
END;
/

PROMPT ========================================================================
PROMPT Exporting CSDB.LEGACY_INSTR_DESC_FULL - HIST Only
PROMPT ========================================================================
PROMPT All data to HIST bucket (Parquet with partitioning)
PROMPT Column mapping: A_ETL_LOAD_SET_FK to A_WORKFLOW_HISTORY_KEY
PROMPT ========================================================================

-- NEW v2.4.0: Per-column date format handling via pTemplateTableName
BEGIN
    DBMS_OUTPUT.PUT_LINE('Exporting LEGACY_INSTR_DESC_FULL data to HIST bucket...');
    DBMS_OUTPUT.PUT_LINE('Using Template Table: CT_ET_TEMPLATES.CSDB_INSTR_DESC_FULL');
    
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_CSDB',
        pTableName => 'LEGACY_INSTR_DESC_FULL',
        pKeyColumnName => 'A_ETL_LOAD_SET_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/CSDB/CSDB_INSTR_DESC_FULL',
        pMinDate => DATE '1900-01-01',  -- Explicit start date for clarity
        pMaxDate => DATE '9999-12-31',  -- Include future dates (MAX_LOAD_START can be beyond SYSDATE)
        pParallelDegree => 8,
        pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_INSTR_DESC_FULL',
        pJobClass => 'high'  -- Oracle Scheduler job class for resource management
    );
    
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_INSTR_DESC_FULL exported to HIST bucket with template column order');
END;
/

PROMPT ========================================================================
PROMPT Exporting CSDB.LEGACY_ISSUER_RAT_FULL - HIST Only
PROMPT ========================================================================
PROMPT All data to HIST bucket (Parquet with partitioning)
PROMPT Column mapping: A_ETL_LOAD_SET_FK to A_WORKFLOW_HISTORY_KEY
PROMPT ========================================================================

-- NEW v2.4.0: Per-column date format handling via pTemplateTableName
BEGIN
    DBMS_OUTPUT.PUT_LINE('Exporting LEGACY_ISSUER_RAT_FULL data to HIST bucket...');
    DBMS_OUTPUT.PUT_LINE('Using Template Table: CT_ET_TEMPLATES.CSDB_ISSUER_RAT_FULL');
    
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_CSDB',
        pTableName => 'LEGACY_ISSUER_RAT_FULL',
        pKeyColumnName => 'A_ETL_LOAD_SET_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/CSDB/CSDB_ISSUER_RAT_FULL',
        pMinDate => DATE '1900-01-01',  -- Explicit start date for clarity
        pMaxDate => DATE '9999-12-31',  -- Include future dates (MAX_LOAD_START can be beyond SYSDATE)
        pParallelDegree => 8,
        pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_ISSUER_RAT_FULL',
        pJobClass => 'high'  -- Oracle Scheduler job class for resource management
    );
    
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_ISSUER_RAT_FULL exported to HIST bucket with template column order');
END;
/

PROMPT ========================================================================
PROMPT Exporting CSDB.LEGACY_ISSUER_DESC_FULL - HIST Only
PROMPT ========================================================================
PROMPT All data to HIST bucket (Parquet with partitioning)
PROMPT Column mapping: A_ETL_LOAD_SET_FK to A_WORKFLOW_HISTORY_KEY
PROMPT ========================================================================

-- NEW v2.4.0: Per-column date format handling via pTemplateTableName
BEGIN
    DBMS_OUTPUT.PUT_LINE('Exporting LEGACY_ISSUER_DESC_FULL data to HIST bucket...');
    DBMS_OUTPUT.PUT_LINE('Using Template Table: CT_ET_TEMPLATES.CSDB_ISSUER_DESC_FULL');
    
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_CSDB',
        pTableName => 'LEGACY_ISSUER_DESC_FULL',
        pKeyColumnName => 'A_ETL_LOAD_SET_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/CSDB/CSDB_ISSUER_DESC_FULL',
        pMinDate => DATE '1900-01-01',  -- Explicit start date for clarity
        pMaxDate => DATE '9999-12-31',  -- Include future dates (MAX_LOAD_START can be beyond SYSDATE)
        pParallelDegree => 8,
        pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_ISSUER_DESC_FULL',
        pJobClass => 'high'  -- Oracle Scheduler job class for resource management
    );
    
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_ISSUER_DESC_FULL exported to HIST bucket with template column order');
END;
/

PROMPT ========================================================================
PROMPT Group 2 Export Completed
PROMPT ========================================================================
PROMPT - LEGACY_INSTR_RAT_FULL: HIST exported
PROMPT - LEGACY_INSTR_DESC_FULL: HIST exported
PROMPT - LEGACY_ISSUER_RAT_FULL: HIST exported
PROMPT - LEGACY_ISSUER_DESC_FULL: HIST exported
PROMPT ========================================================================

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