CREATE OR REPLACE PROCEDURE WEB_GENERAL_EVENT_MADLIB_DAILY_INSERT_PROC(
    file_name STRING, 
    p_date DATE, 
    geo_table_name STRING
)
RETURNS STRING
LANGUAGE SQL
AS 
$$
DECLARE 
    row_count INT;
    start_time TIMESTAMP;
    query_sql string;
BEGIN
    start_time := CURRENT_TIMESTAMP();
    query_sql := 'INSERT INTO WEB_GENERAL_EVENT_MADLIB(
        ACTION_NAME,
        TITLE_ID,
        TITLE,
        P_DATE,
        P_HOUR
    )	
    select
        $1:properties.actionName as ACTION_NAME,
        $1:properties.key as TITLE_ID,
        $1:properties.title as TITLE,
        DATE(IFNULL($1:server_timestamp, $1:timestamp)::TIMESTAMP) as p_date,
        HOUR(IFNULL($1:server_timestamp, $1:timestamp)::TIMESTAMP) as p_hour
    from ' || :file_name || ' (file_format => ''BASIC_JSON_LOADER'', pattern => (''.*''))
    where $1:properties.actionName = ''SuggestionClicked'' or  $1:properties.actionName = ''MadlibCreateClicked'';
    ';

    EXECUTE IMMEDIATE :query_sql;

    SELECT COUNT(*) 
        INTO :row_count 
    FROM WEB_GENERAL_EVENT_MADLIB 
    WHERE p_date = :p_date;

    -- IF (:row_count = 0) THEN
    --     select post_to_slack('#data-alerts', 'WEB_GENERAL_EVENT_MADLIB_DAILY_INSERT_have 0 data');
    -- END IF;
    call TASK_MONITOR_INSERT_PROC('WEB_GENERAL_EVENT_MADLIB_DAILY_INSERT', :start_time, :row_count, 'SUCCESS', 'DAILY');

    RETURN 'Data Inserted';
END;
$$;
