Skip to main content

Run match requests asynchronously

Overview

Translate can run INSERT match queries asynchronously. When you submit an asynchronous request, Translate returns a request ID immediately and runs the match in the background using a warehouse in your account. Results are written to the same output table used by a synchronous INSERT query.

Use asynchronous execution when you are matching large datasets or want to submit multiple requests without waiting for each request to finish.

Asynchronous execution is available only for INSERT queries that use _to_table templates. SELECT queries must be run with allowed_sprocs.run. For more information about running SELECT and INSERT queries, see Match data with the Translate app.

Before you begin

Complete the following requirements before submitting an asynchronous request:

  • Complete the steps in Configure the Translate app, including activating the app and granting access to the consumer data.
  • Run the configuration statements as INSTALLER_ROLE or USER_ROLE.
  • Replace values marked as <application_name> or <consumer_defined_*> before running a statement. Do not run the examples as written.

Grant the EXECUTE TASK privilege

The application requests the EXECUTE TASK privilege during installation. If the privilege was not granted at that time, run the following statement:

GRANT EXECUTE TASK ON ACCOUNT
TO APPLICATION <application_name>;

Grant access to the warehouse

Grant the application permission to use the warehouse that will run asynchronous requests:

GRANT USAGE
ON WAREHOUSE <consumer_defined_warehouse>
TO APPLICATION <application_name>;

Specify the asynchronous warehouse

You can specify a warehouse when you submit a request or configure one in user_settings.

To use the same warehouse for all asynchronous templates, add the consumer_async_warehouse setting:

MERGE INTO <application_name>.local.user_settings settings
USING (
    SELECT *
    FROM (
        VALUES
            (
                'consumer_async_warehouse',
                '<consumer_defined_warehouse>',
                'DEFAULT'
            )
    ) src (
        setting_name,
        setting_value,
        setting_profile
    )
) input
ON settings.setting_name = input.setting_name
AND IFNULL(settings.setting_profile, '') =
    IFNULL(input.setting_profile, '')
WHEN NOT MATCHED THEN
    INSERT (
        setting_name,
        setting_value,
        setting_profile
    )
    VALUES (
        input.setting_name,
        input.setting_value,
        input.setting_profile
    )
WHEN MATCHED THEN
    UPDATE SET
        settings.setting_value = input.setting_value;

To use a different warehouse for a specific template, add the corresponding template-specific setting:

Template Warehouse setting
Clear email match consumer_clear_email_async_warehouse
Device ID match consumer_devices_async_warehouse
Hashed email match consumer_hashed_emails_async_warehouse
HMID match consumer_hmid_async_warehouse
IP match consumer_ip_async_warehouse
Phone match consumer_phone_async_warehouse
Waterfall match consumer_waterfall_async_warehouse

How Translate selects a warehouse

Translate selects the warehouse in the following order:

  1. The consumer_async_warehouse runtime parameter supplied with the request
  2. The template-specific warehouse setting in user_settings
  3. The general consumer_async_warehouse setting in user_settings

Settings are read from the request’s setting_profile. If a profile is not specified, Translate uses the DEFAULT profile. The request is rejected if Translate cannot find a configured warehouse.

Submit an asynchronous request

Call app_public.run_async with a _to_table template and the parameters required by that template.

The INSERT ASYNC example for each template in Match data with the Translate app provides the complete parameter list.

For example, the following statement submits a clear email match request:

CALL <application_name>.app_public.run_async(
    'clear_email_match_to_table',
    PARSE_JSON('{
        "dimensions": [
            "p.clear_email",
            "p.hmid"
        ],
        "consumer_async_warehouse":
            "<consumer_defined_warehouse>",
        "setting_profile":
            "<consumer_defined_profile>",
        "consumer_resource":
            "<consumer_defined_fully_qualified_dataset_location>",
        "consumer_join_field":
            "<consumer_defined_column_name>"
    }')
);

The consumer_async_warehouse, setting_profile, consumer_resource, and consumer_join_field parameters shown in this example are optional when their values have already been configured or can be determined from the selected template.

A successfully submitted request returns the following information:

Column Description
request_id The ID used to track the request.
status The request’s initial status. A value of SUBMITTED means the request was queued.
location The table where Translate will write the results.

If Translate cannot submit the request, the response includes an error column that explains the reason. A request might not be submitted when:

  • No asynchronous warehouse is configured.
  • The warehouse does not exist or the application has not been granted USAGE on it.
  • The specified template is not a _to_table template.

Check the request status

Save the request_id returned when you submit the request. Use that ID to query app_public.request_status:

SELECT
    date_updated,
    request_id,
    template_name,
    status:status::STRING AS status,
    status:status_message::STRING AS status_message,
    request_options:dentsu_client_key::STRING
        AS dentsu_client_key,
    request_options:kb_build_id::STRING
        AS kb_build_id,
    request_options:output_location::STRING
        AS output_location
FROM <application_name>.app_public.request_status
WHERE request_id = '<request_id_from_response>'
ORDER BY date_updated DESC;

The response includes the following information:

Column Description
status The current state of the request.
status_message Additional information about the current state.
dentsu_client_key The Client Key under which the request is running.
kb_build_id The dentsu knowledge base build used for the match.
output_location The schema and table where the results will be written.

A successful request progresses through the following statuses:

SUBMITTED → ACCEPTED → PROCESSING → COMPLETED

A request can also have one of the following statuses:

Status Description
REJECTED The request did not pass validation. Review status_message for the reason.
FAILED An error occurred while the request was running. Review status_message for more information.
CANCELLED The request was cancelled using cancel_job.

Retrieve the results

When the latest request status is COMPLETED, query the table identified by output_location.

Results are written to the following location:

client_<dentsu_client_key>.<template>_match_output

Use the results query provided for the template in Match data with the Translate app.

For example, the following statement retrieves the results of a clear email match request:

SELECT
    request_id,
    ts,
    result:clear_email::STRING AS clear_email,
    result:hmid::STRING AS hmid
FROM <application_name>.client_<dentsu_client_key>.
    clear_email_match_output
WHERE request_id = '<request_id_from_response>';

Replace <request_id_from_response> with the request ID returned by run_async.

Cancel a request

You can cancel a request that is queued or being processed:

CALL <application_name>.app_public.cancel_job(
    '<request_id_from_response>'
);

The call returns a confirmation message. The request’s status changes to CANCELLED.

Cancelling a request that is already completed, failed, or cancelled does not change the request.

Run multiple requests at the same time

Each call to run_async receives a separate request_id and runs independently. You can submit multiple requests using the same template or different templates without waiting for an earlier request to finish. Track each request using its corresponding ID.

Requests assigned to the same warehouse share that warehouse’s compute capacity. As a result, total processing time depends on the warehouse size and concurrency settings. For workloads that require substantial parallel processing, consider using a larger warehouse or configuring separate warehouses for individual templates.