-- Insert user stats data from RDS to Snowflake
-- This query inserts new records from S3 stage

INSERT INTO {user_stats_table_name}
SELECT 
    $1:id as id,
    $1:display_name as display_name,
    $1:total_clips as total_clips,
    $1:total_followers as total_followers,
    $1:total_following as total_following,
    $1:first_onebox as first_onebox,
    $1:first_custom as first_custom,
    $1:first_instrumental as first_instrumental,
    $1:last_login as last_login,
    $1:last_create as last_create,
    $1:user_id as user_id,
    $1:total_clips_public as total_clips_public,
    $1:last_monthly_update as last_monthly_update,
    $1:last_periodic_update as last_periodic_update,
    $1:total_likes as total_likes,
    $1:total_likes_received as total_likes_received,
    $1:total_likes_received_till_last_month as total_likes_received_till_last_month,
    $1:total_plays as total_plays,
    $1:total_plays_received as total_plays_received,
    $1:total_plays_received_till_last_month as total_plays_received_till_last_month,
    $1:total_playlists as total_playlists,
    $1:consecutive_days_active as consecutive_days_active,
    $1:longest_login_streak as longest_login_streak,
    $1:consecutive_creation_streak as consecutive_creation_streak,
    $1:longest_creation_streak as longest_creation_streak,
    '{partition_start_date}'::DATE as p_date
FROM {stage_path} (file_format => 'BASIC_PARQUET_LOADER', pattern => ('.*.parquet'));
