merge into {user_share_table_name} as target
using 
(
    select 
        $1:id as id,
        $1:source as source,
        $1:platform as platform,
        $1:content_id as content_id,
        $1:content_type as content_type,
        $1:sharer_id as sharer_id,
        $1:created_at as created_at,
        $1:updated_at as updated_at,
        date(to_timestamp(created_at)) as p_date,
        hour(to_timestamp(created_at)) as p_hour,
        $1:content_owner_id as content_owner_id
    from {stage_path} (file_format => 'BASIC_PARQUET_LOADER', pattern => ('.*.parquet'))
) as source
on (target.id = source.id and target.p_date = source.p_date and target.p_hour = source.p_hour)
when matched then
    update set 
        target.source = source.source,
        target.platform = source.platform,
        target.content_id = source.content_id,
        target.content_type = source.content_type,
        target.sharer_id = source.sharer_id,
        target.created_at = source.created_at,
        target.updated_at = source.updated_at,
        target.p_date = source.p_date,
        target.p_hour = source.p_hour,
        target.content_owner_id = source.content_owner_id
when not matched then
    insert (id, source, platform, content_id, content_type, sharer_id, created_at, updated_at, p_date, p_hour, content_owner_id)
    values (source.id, source.source, source.platform, source.content_id, source.content_type, source.sharer_id, source.created_at, source.updated_at, source.p_date, source.p_hour, source.content_owner_id);

