Templates

Templates are JinjaSQL clean room templates that can be run by specified collaborators. Any collaborator can share a template with collaborators in a collaboration. You can request to add or remove only templates that your account has registered.

Continue reading to see how to register and add a template into a collaboration:

Register a template

Follow these steps to register a template:

  1. Design a template for the collaboration and embed it in a template specification.

  2. Register the template by calling REGISTER_TEMPLATE. This returns a template ID that you will use to link the template.

After the template is registered, it can be linked into a collaboration by anyone who has read access to that registry.

Add a template

The process to request template addition depends on whether the collaboration already exists.

  • To add a template before the collaboration is created, give the template ID to the collaboration owner, who includes it in the collaboration spec, specifying who can run the template. In the following collaboration snippet, alice is granted access to run template bob_template_v1.

    ...
    analysis_runners:
      alice:
        templates:
        - id: bob_template_v1
    ...
    
  • To add a template into an existing collaboration, you send a request to all prospective sharers by following these steps:

    1. Call ADD_TEMPLATE_REQUEST with the template ID to start the approval flow to add the template into a specific collaboration, for specific users.

      All collaborators affected by the template see the request when they call VIEW_UPDATE_REQUESTS.

    2. Collaborators who see the request with status PENDING_MY_APPROVAL should call APPROVE_UPDATE_REQUEST or REJECT_UPDATE_REQUEST.

      • If any collaborator rejects the request, the update request is rejected.

      • Collaborators can not later change an approval to a rejection, or a rejection to an approval.

      • The template would not be shared until all requested parties approve the request.

      • Collaborators can’t later change an approval to a rejection, or a rejection to an approval.

      • After you approve, the status changes to PENDING_PARTNER_APPROVAL if other collaborators still need to approve.

    3. When all required collaborators have approved, the status changes to APPROVED and the update is applied automatically. The terminal statuses for an update request are COMPLETED and FAILED. When the request status is COMPLETED, the template is available to the users specified in the add template request. If the request is FAILED, see the DETAILS column in VIEW_UPDATE_REQUESTS for failure details. If any collaborator rejects the request, the status is REJECTED and any reason supplied by the rejecting party is visible in the request report.

    4. There might be a short delay after a template is approved by all users before the template is available. Call VIEW_TEMPLATES to confirm that the template is available to use.

Tip

To see which templates you have registered, call VIEW_REGISTERED_TEMPLATES.

See Run an analysis to learn how to run an analysis.

Template design

Collaboration templates are the same as Provider and Consumer Clean Room templates, with a few special considerations:

  • The template’s source_table variable is populated by the collaboration’s data offerings. In most collaboration templates, source_table is the only data source variable used.

  • The template’s my_table is used only when an analysis runner is using Snowflake Standard Edition and can’t contribute data offerings to a collaboration.

  • Columns from the original data sources can be renamed when exposed to the template or user. See Source column renaming to learn how and when source columns are renamed. Templates and user-provided arguments (such as a join column name) should use the final name, not the original name, if the column is renamed.

  • Activation templates in a collaboration don’t need to be named activation_<template_name>. All other activation template requirements still apply.

For information about custom template syntax in Snowflake Data Clean Rooms, see Design custom templates.