INSERT INTO {app_event_table_name}(
    CATEGORY,
    ACTION_NAME,
    ACTION_TYPE,
    ELEMENT_TYPE,
    ELEMENT_ID,
    ELEMENT_TEXT,
    X_INDEX,
    Y_INDEX,
    METHOD,
    CONDITION,
    CONTEXT,
    DIRECTION,
    CREATED_ID,
    USER_ID,
    ANONYMOUS_ID,
    SESSION_ID,
    SCREEN_NAME,
    SCREEN_ELEMENT_ID,
    SOURCE,
    CLIENT_TIMESTAMP,
    SERVER_TIMESTAMP,
    USER_AGENT,
    LOCALE,
    TIMEZONE,
    P_DATE,
    P_HOUR,
    CLIENT_IP,
    APP_NAMESPACE,
    APP_VERSION,
    OS_NAME,
    OS_VERSION,
    COUNTRY,
    CITY
)
WITH total_data AS (
    SELECT *
    FROM {file_path} (file_format => 'BASIC_JSON_LOADER', pattern => ('.*'))
)
SELECT
    total_data.$1:properties.category AS category,
    total_data.$1:properties.actionName AS action_name,
    total_data.$1:properties.actionType AS action_type,
    total_data.$1:properties.elementType AS element_type,
    total_data.$1:properties.elementId AS element_id,
    total_data.$1:properties.elementText AS element_text,
    total_data.$1:properties.xIndex AS x_index,
    total_data.$1:properties.yIndex AS y_index,
    total_data.$1:properties.method AS method,
    total_data.$1:properties.condition AS condition,
    total_data.$1:properties.context AS context,
    total_data.$1:properties.direction AS direction,
    total_data.$1:properties.createdId AS created_id,
    total_data.$1:properties.userId AS user_id,
    total_data.$1:properties.anonymousId AS anonymous_id,
    total_data.$1:properties.sessionId AS session_id,
    total_data.$1:properties.screenName AS screen_name,
    total_data.$1:properties.screenElementId AS screen_element_id,
    total_data.$1:properties.source AS source,
    total_data.$1:timestamp AS client_timestamp,
    IFNULL(total_data.$1:server_timestamp, total_data.$1:timestamp) AS server_timestamp,
    total_data.$1:context.userAgent AS user_agent,
    total_data.$1:context.locale AS locale,
    total_data.$1:context.timezone AS timezone,
    '{partition_date}'::DATE AS p_date,
    {partition_hour} AS p_hour,
    IFNULL(total_data.$1:client_ip, '') AS client_ip,
    total_data.$1:context.app.namespace AS app_namespace,
    total_data.$1:context.app.version AS app_version,
    total_data.$1:context.os.name AS os_name,
    total_data.$1:context.os.version AS os_version,
    '' AS country,
    '' AS city
FROM total_data;

