create or replace task SUNO_PROD.PROD.USER_SESSION_STATE_HOURLY_INSERT
	warehouse=SUNO_PROD_OTHER_HOURLY_X_SMALL
	schedule='USING CRON 30 * * * * UTC'
    -- this task in fact depends on bk_auth_event and rds_session_history should be migreated to dagster in the future
	as DECLARE
        geo_table_name string;
        p_date date;
        p_hour number;
    BEGIN
        p_date := Date(SYSDATE() - INTERVAL '1 HOUR');
        p_hour := HOUR(SYSDATE() - INTERVAL '1 HOUR');
        geo_table_name := CONCAT('USER_SESSION_STATE', YEAR(SYSDATE() - INTERVAL '1 HOUR'), '_', MONTH(SYSDATE() - INTERVAL '1 HOUR'), '_', DAY(SYSDATE() - INTERVAL '1 HOUR'), '_', HOUR(SYSDATE() - INTERVAL '1 HOUR'));
        CALL USER_SESSION_STATE_HOURLY_INSERT_PROC(
            :p_date,
            :p_hour,
            :geo_table_name
        );
    END;