-- Discount Redemption table for storing discount redemption data from RDS
-- This table is populated by the Glue job rds_to_s3_billing_discountredemption_hourly_upsert
-- which dumps data from RDS to S3 and then loads it into Snowflake
-- Clustered by partition date and hour for optimal query performance
CREATE TRANSIENT TABLE IF NOT EXISTS {discount_redemption_table_name} CLUSTER BY (p_date, p_hour) (
    -- Primary identifier
    ID VARCHAR(255),                                    -- Unique discount redemption identifier
    
    -- Timestamps
    CREATED_AT TIMESTAMP_TZ(9),                         -- When the redemption record was created
    UPDATED_AT TIMESTAMP_TZ(9),                         -- Last update timestamp
    REDEEMED_AT TIMESTAMP_TZ(9),                        -- When the discount was redeemed
    ACCEPTED_AT TIMESTAMP_TZ(9),                        -- When the discount was accepted
    
    -- References
    DISCOUNT_OFFER_ID VARCHAR(255),                     -- Associated discount offer identifier
    USER_ID NUMBER(38,0),                               -- User who redeemed the discount
    
    -- Partitioning columns for optimization
    P_DATE DATE,                                        -- Partition date based on created_at
    P_HOUR NUMBER(38,0)                                 -- Partition hour (0-23) based on created_at
);

