CREATE TRANSIENT TABLE IF NOT EXISTS {{ rec_run_table_name }} (
    -- Core Identifiers
    REC_RUN_ID VARCHAR(100) COMMENT 'Unique identifier for the recommendation run',
    USER_ID BIGINT COMMENT 'ID of the user receiving recommendations',
    USER_UID VARCHAR(100) COMMENT 'UUID of the user receiving recommendations',
    
    -- Timestamps
    CREATED_AT TIMESTAMP_TZ COMMENT 'When the recommendation run was created',
    
    -- Configuration
    VERSION VARCHAR(10) COMMENT 'Version of the recommendation algorithm',
    SURFACE VARCHAR(50) COMMENT 'Surface where recommendations are displayed',
    EXPERIMENT_NAME VARCHAR(100) COMMENT 'Name of the experiment this run belongs to',
    
    -- Request Parameters
    NUM_RECOMMENDATIONS_REQUESTED INT COMMENT 'Number of recommendations requested',
    NUM_FOLLOWED_CREATORS INT COMMENT 'Number of creators the user follows',
    ELC_MODE BOOLEAN COMMENT 'Whether ELC mode is enabled',
    
    -- Algorithm Weights
    WEIGHT_FOLLOW FLOAT COMMENT 'Weight for following-based recommendations',
    WEIGHT_AUDIO_SIMILARITY FLOAT COMMENT 'Weight for audio similarity recommendations',
    WEIGHT_VIDEO_SIMILARITY FLOAT COMMENT 'Weight for video similarity recommendations',
    WEIGHT_GENRE_SIMILARITY FLOAT COMMENT 'Weight for genre similarity recommendations',
    WEIGHT_FRESH FLOAT COMMENT 'Weight for fresh content recommendations',
    WEIGHT_POPULAR FLOAT COMMENT 'Weight for popular content recommendations',
    WEIGHT_MANUAL_CHAMPION FLOAT COMMENT 'Weight for manually championed content',
    WEIGHT_CREATOR_CHAMPION FLOAT COMMENT 'Weight for creator championed content',
    WEIGHT_COLLABORATIVE_FILTERING FLOAT COMMENT 'Weight for collaborative filtering recommendations',
    
    -- Algorithm Parameters
    CREATOR_MIN_DISTANCE INT COMMENT 'Minimum distance between creators in recommendations',
    MAX_VIDEO_COVER_RATIO FLOAT COMMENT 'Maximum ratio of video covers allowed',
    RERANK_ENABLED_BUCKETS VARIANT COMMENT 'Array of buckets with reranking enabled',
    
    -- User History Counts
    LIKED_HOOKS_COUNT INT COMMENT 'Number of hooks the user has liked',
    LIKED_CLIPS_COUNT INT COMMENT 'Number of clips the user has liked',
    LISTENING_HISTORY_CLIPS_COUNT INT COMMENT 'Number of clips in user listening history',
    CREATION_TAGS_COUNT INT COMMENT 'Number of creation tags associated with user',
    WATCH_HISTORY_COUNT INT COMMENT 'Number of items in user watch history',
    NUM_HIDDEN_CREATORS INT COMMENT 'Number of creators hidden by the user',
    
    -- Seeds Information
    VIDEO_SEEDS_TOTAL INT COMMENT 'Total number of video seeds available',
    VIDEO_SEEDS_SELECTED INT COMMENT 'Number of video seeds selected',
    AUDIO_SEEDS_TOTAL INT COMMENT 'Total number of audio seeds available',
    AUDIO_SEEDS_SELECTED INT COMMENT 'Number of audio seeds selected',
    
    -- Retrieval Stats
    TOTAL_RETRIEVED INT COMMENT 'Total number of recommendations retrieved',
    TOTAL_UNIQUE INT COMMENT 'Total number of unique recommendations',
    RETRIEVED_POPULAR INT COMMENT 'Number of popular recommendations retrieved',
    RETRIEVED_CREATOR_CHAMPION INT COMMENT 'Number of creator champion recommendations retrieved',
    RETRIEVED_GENRE_SIMILARITY INT COMMENT 'Number of genre similarity recommendations retrieved',
    RETRIEVED_MANUAL_CHAMPION INT COMMENT 'Number of manual champion recommendations retrieved',
    RETRIEVED_COLLABORATIVE_FILTERING INT COMMENT 'Number of collaborative filtering recommendations retrieved',
    RETRIEVED_FOLLOW INT COMMENT 'Number of follow-based recommendations retrieved',
    RETRIEVED_FRESH INT COMMENT 'Number of fresh recommendations retrieved',
    RETRIEVED_VIDEO_SIMILARITY INT COMMENT 'Number of video similarity recommendations retrieved',
    RETRIEVED_AUDIO_SIMILARITY INT COMMENT 'Number of audio similarity recommendations retrieved',
    
    -- Filtering Stats
    TOTAL_CANDIDATES INT COMMENT 'Total number of candidate recommendations',
    TOTAL_FILTERED INT COMMENT 'Total number of recommendations filtered out',
    TOTAL_REMAINING INT COMMENT 'Total number of recommendations remaining after filtering',
    FILTERED_BY_WATCHED INT COMMENT 'Number of recommendations filtered by watched status',
    FILTERED_BY_LIKED INT COMMENT 'Number of recommendations filtered by liked status',
    FILTERED_BY_HIDDEN_CREATOR INT COMMENT 'Number of recommendations filtered by hidden creator',
    FILTERED_BY_OTHER INT COMMENT 'Number of recommendations filtered by other criteria',
    
    -- Reranking and Fusion
    RERANK_ENABLED BOOLEAN COMMENT 'Whether reranking is enabled',
    FUSION_METHOD VARCHAR(50) COMMENT 'Method used for recommendation fusion',
    
    -- Final Results
    NUM_RECOMMENDATIONS_RETURNED INT COMMENT 'Number of recommendations actually returned',
    UNIQUE_CREATORS INT COMMENT 'Number of unique creators in final recommendations',
    UNIQUE_SONGS INT COMMENT 'Number of unique songs in final recommendations',
    
    -- Content Source Distribution
    CONTENT_SOURCE_USER_UPLOAD INT COMMENT 'Number of recommendations from user uploads',
    CONTENT_SOURCE_BACKFILL_VIDEO_COVER INT COMMENT 'Number of recommendations from backfill video covers',
    CONTENT_SOURCE_OTHER INT COMMENT 'Number of recommendations from other sources',
    
    -- Performance Metrics
    PERF_TOTAL_MS FLOAT COMMENT 'Total performance time in milliseconds',
    
    -- Quality Metrics
    AVG_GEMINI_RATING FLOAT COMMENT 'Average Gemini rating of recommendations',
    GEMINI_RATING_0_COUNT INT COMMENT 'Count of recommendations with Gemini rating 0',
    GEMINI_RATING_1_COUNT INT COMMENT 'Count of recommendations with Gemini rating 1',
    GEMINI_RATING_2_COUNT INT COMMENT 'Count of recommendations with Gemini rating 2',
    GEMINI_RATING_3_COUNT INT COMMENT 'Count of recommendations with Gemini rating 3',
    GEMINI_RATING_4_COUNT INT COMMENT 'Count of recommendations with Gemini rating 4',
    
    -- Content Age and Engagement
    AGE_P50_HOURS FLOAT COMMENT 'Median age of recommended content in hours',
    AGE_LAST_24H_COUNT INT COMMENT 'Count of recommendations from last 24 hours',
    AVG_VIEW_COUNT FLOAT COMMENT 'Average view count of recommendations',
    AVG_LIKE_COUNT FLOAT COMMENT 'Average like count of recommendations',
    
    -- Final Algorithm Distribution
    FINAL_POPULAR_COUNT INT COMMENT 'Final count of popular recommendations',
    FINAL_CREATOR_CHAMPION_COUNT INT COMMENT 'Final count of creator champion recommendations',
    FINAL_FOLLOW_COUNT INT COMMENT 'Final count of follow-based recommendations',
    FINAL_MANUAL_CHAMPION_COUNT INT COMMENT 'Final count of manual champion recommendations',
    FINAL_AUDIO_SIMILARITY_COUNT INT COMMENT 'Final count of audio similarity recommendations',
    FINAL_VIDEO_SIMILARITY_COUNT INT COMMENT 'Final count of video similarity recommendations',
    FINAL_FRESH_COUNT INT COMMENT 'Final count of fresh recommendations',
    FINAL_GENRE_SIMILARITY_COUNT INT COMMENT 'Final count of genre similarity recommendations',
    FINAL_COLLABORATIVE_FILTERING_COUNT INT COMMENT 'Final count of collaborative filtering recommendations',
    
    -- Error and Warning Tracking
    WARNINGS_COUNT INT COMMENT 'Number of warnings during recommendation generation',
    ERRORS_COUNT INT COMMENT 'Number of errors during recommendation generation',
    
    -- Hook Signals
    HOOK_SIGNALS_LIKED_COUNT INT COMMENT 'Count of liked hook signals',
    HOOK_SIGNALS_OMNIPLAY_COUNT INT COMMENT 'Count of omniplay hook signals',
    HOOK_SIGNALS_LONG_WATCH_COUNT INT COMMENT 'Count of long watch hook signals',
    HOOK_SIGNALS_COMMENT_COUNT INT COMMENT 'Count of comment hook signals',
    HOOK_SIGNALS_COMMENT_VIEW_COUNT INT COMMENT 'Count of comment view hook signals',
    HOOK_SIGNALS_PROFILE_VIEW_COUNT INT COMMENT 'Count of profile view hook signals',
    
    -- Hook Signal Weights
    WEIGHT_HOOK_SIGNAL_LIKED FLOAT COMMENT 'Weight for liked hook signals',
    WEIGHT_HOOK_SIGNAL_OMNIPLAY FLOAT COMMENT 'Weight for omniplay hook signals',
    WEIGHT_HOOK_SIGNAL_LONG_WATCH FLOAT COMMENT 'Weight for long watch hook signals',
    WEIGHT_HOOK_SIGNAL_COMMENT FLOAT COMMENT 'Weight for comment hook signals',
    WEIGHT_HOOK_SIGNAL_COMMENT_VIEW FLOAT COMMENT 'Weight for comment view hook signals',
    WEIGHT_HOOK_SIGNAL_PROFILE_VIEW FLOAT COMMENT 'Weight for profile view hook signals',

    -- Partitioning columns
    P_DATE DATE NOT NULL COMMENT 'Partition date for the recommendation run',
    P_HOUR INT NOT NULL COMMENT 'Partition hour for the recommendation run'
) 
CLUSTER BY (P_DATE, P_HOUR); 
