이 항목에서는 기본 다자간 공동 작업을 생성하는 단계를 안내합니다. 템플릿과 데이터 오퍼링을 등록하는 방법, 공동 작업의 초기 버전에 데이터를 추가하는 방법, 공동 작업이 생성된 후 공동 작업자가 리소스를 추가하는 방법을 보여줍니다. 또한 공동 작업에서 템플릿과 데이터 리소스를 사용하여 쿼리를 실행하는 방법도 보여줍니다.
공동 작업자는 :ref:`공동 작업을 검토하고 참여 <label-dcr_collaboration_join_collaboration>`합니다.
그런 다음 공동 작업자는 선택적으로 공동 작업 역할에 따라 템플릿 및 데이터 오퍼링과 같은 추가 리소스를 공동 작업에 연결 합니다. 추가 리소스는 언제든지 공동 작업에 추가할 수 있습니다.
분석 실행자는 공동 작업에서 사용 가능한 모든 데이터를 사용하여 공동 작업에서 할당된 템플릿을 실행 할 수 있습니다. 분석 실행자는 분석 비용을 부담합니다. 템플릿은 쿼리 결과를 응답을 통해 반환하거나 호출자 또는 다른 공동 작업자에게 결과를 활성화 하도록 설계할 수 있습니다.
공동 작업을 생성하려면 모든 공동 작업자 및 해당 역할 을 정의하는 공동 작업 사양 을 설계합니다.
공동 작업이 생성되는 즉시 공동 작업에서 리소스를 사용할 수 있도록 하려는 경우, 공동 작업 소유자는 공동 작업을 생성하기 전에 해당 리소스를 등록 및 연결 하고 공동 작업 사양에 리소스 IDs를 포함합니다.
소유자가 공동 작업자의 리소스를 사용하고자 하는 경우, 해당 사용자에게 리소스를 등록하고 리소스 IDs를 소유자에게 전달하도록 요청하여 공동 작업 사양에 포함할 수 있습니다. 또한 소유자는 공동 작업 사양에서 현재 연결되어 있지 않지만 나중에 연결할 수 있는 리소스를 나타냅니다.
그런 다음 소유자는 INITIALIZE를 호출하여 공동 작업 생성을 시작합니다. 또한 INITIALIZE는 기본적으로 소유자를 자동으로 공동 작업에 조인합니다. 이는 비동기 프로세스이므로 소유자는 상태가 JOINED가 될 때까지 GET_STATUS를 호출해야 합니다.
다음 코드 조각은 공동 작업을 생성하고 조인하는 방법을 보여줍니다.
1CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.INITIALIZE( 2$$ 3api_version:2.0.0 4spec_type:collaboration 5name:my_first_collaboration 6owner:alice 7collaborator_identifier_aliases: 8alice:example_com.acct_abc 9bob:another_example.acct_xyz10analysis_runners:11bob:12data_providers:13alice:14data_offerings:[]-- alice has not provided data to bob, but can do so in the future.15bob:16data_offerings:[customers_v1]-- bob has registered a data offering and made it available to himself.17templates:[]-- No templates available yet for bob.18alice:19data_providers:20alice:21data_offerings:[]22bob:23data_offerings:[]24templates:[]25 $$,26'APP_WH'-- Use this warehouse for initialization.27);-- XSMALL or SMALL warehouses are recommended for initialization.28SETcollaboration_name='my_first_collaboration';2930-- INITIALIZE automatically joins the owner. Check status until JOINED.31CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.GET_STATUS($collaboration_name);3233-- Collaboration is visible here when it's joined.34CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.VIEW_COLLABORATIONS();
스크립트에 대한 참고 사항:
공동 작업은 별칭이 alice 및 bob 인 두 명의 공동 작업자로 구성됩니다. 별칭을 사용하는 모든 곳에서 전체 데이터 공유 ID를 사용할 수 있지만, 이는 사용자 친화적이지 않습니다.
alice 는 소유자입니다.
alice 및 bob 은 모두 분석 실행자입니다.
alice 및 bob 은 서로에게 데이터 공급자입니다.
데이터 공급자인 경우 data_offerings 필드를 포함해야 합니다. 이 필드는 채워지거나 비어 있을 수 있으며, 이는 현재 데이터 오퍼링이 없지만 나중에 추가할 수 있음을 나타냅니다.
alice 는 bob 또는 자신에게 데이터를 제공하지 않지만 나중에 제공할 수 있습니다(14행, 22행).
bob 은 이미 데이터 오퍼링을 등록했으며 초기 공동 작업에서 자신에게 제공했습니다(16행).
bob 은 alice 에게 데이터를 제공하지 않지만 나중에 제공할 수 있습니다(24행).
alice 및 bob 모두 아직 사용 가능한 템플릿이 없지만 나중에 할당될 수 있습니다(18, 25행). 참고로, templates 필드는 분석 실행자의 경우 선택 사항입니다. 초기화 중에 이 필드를 생략해도 공동 작업자는 나중에 이 분석 실행자에게 템플릿을 할당할 수 있습니다.
공동 작업자는 공동 작업 역할에 따라 리소스를 공동 작업에 연결하거나, 공동 작업에 연결한 리소스를 제거할 수 있습니다. 리소스를 공동 작업에 연결하는 두 단계는 다음과 같습니다.
리소스 소유자는 리소스에 대해 :doc:`리소스 정의 사양 </user-guide/cleanrooms/spec-reference>`을 생성하고 이를 사용하여 계정에 리소스를 등록합니다. 계정의 :doc:`기본 레지스트리 </user-guide/cleanrooms/registries>`에 리소스를 등록하거나 사용자 지정 레지스트리를 사용합니다.
공동 작업자는 리소스를 공동 작업에 연결합니다. 리소스는 공동 작업이 생성될 때 공동 작업을 생성하는 데 사용되는 YAML 정의에 리소스 ID를 하드코딩하거나 공동 작업이 생성되고 조인한 후에 리소스를 공동 작업에 연결하는 적절한 프로시저를 호출하여 공동 작업에 연결할 수 있습니다.
리소스가 연결되면 지정된 공동 작업자가 사용할 수 있습니다. 템플릿과 같은 일부 리소스 유형은 모든 공동 작업자가 연결할 수 있습니다. 데이터 오퍼링과 같은 기타 리소스는 데이터 공급자 공동 작업 역할의 사용자만 연결할 수 있습니다. 그러나 기여한 리소스를 공동 작업에 사용할 수 있으려면 먼저 공동 작업에 참여해야 합니다.
리소스 연결 또는 제거와 같은 기존 공동 작업에 대한 업데이트는 비동기적이며 완료하는 데 다소 시간이 걸립니다. 업데이트 상태를 확인하려면 VIEW_UPDATE_REQUESTS를 호출합니다. 리소스가 완전히 사용 가능하기 전에 사용하면 일관되지 않은 동작이 발생할 수 있습니다.
리소스는 버전 관리를 지원합니다. 그러나 새 버전으로 새 리소스를 생성해도 공동 작업에서 이전 버전이 제거되지는 않습니다. 리소스는 사용자가 제공한 이름과 버전(데이터 오퍼링의 경우 별칭)을 결합하여 고유하게 명명됩니다.
공동 작업에서 분석 실행자 역할을 맡은 경우 공동 작업에서 자신과 공유된 데이터 소스에 대해 분석을 실행할 수 있습니다.
공동 작업은 다음 두 가지 유형의 쿼리를 지원합니다.
템플릿 분석. 이러한 쿼리는 템플릿(템플릿화된 JinjaSQL 문)을 공동 작업에 연결합니다. 템플릿은 결과를 즉시 사용자에게 반환하는 분석 템플릿이거나 결과를 지정된 참여자의 Snowflake 계정에 저장하는 활성화 템플릿일 수 있습니다.
자유 형식 SQL 쿼리. 데이터 공급자가 허용하는 경우 공동 작업자 자격 증명으로 로그인하면 SQL을 사용하여 지정된 데이터 오퍼링에 액세스할 수 있습니다. 공동 작업을 통해 노출된 정규화된 뷰 이름에 액세스하여 Collaboration API 프로시저를 호출하지 않고 직접 SQL 쿼리를 실행합니다.
분석 실행자는 분석 실행 비용을 부담합니다.
공동 작업 사양에 따라 템플릿 실행, 결과 활성화, 자유 형식 SQL 쿼리 실행 가능 여부가 결정됩니다. 권한과 사용할 수 있는 데이터 및 템플릿은 공동 작업 사양에 설명되어 있습니다.
참고
데이터 소스의 열은 템플릿 또는 사용자에게 노출될 때 새 이름으로 바뀔 수 있습니다. 소스 열의 이름을 바꾸는 방법과 시기를 알아보려면 소스 열 이름 바꾸기 섹션을 참조하세요. 템플릿 및 사용자가 제공한 인자(예: 조인 열 이름)는 열 이름이 바뀐 경우 원래 이름이 아닌 최종 이름을 사용해야 합니다.
템플릿에서 분석을 실행하려면 실행할 수 있는 템플릿 목록을 보고, 사용할 수 있는 데이터 오퍼링 목록을 확인한 다음, 값을 개별 매개변수 또는 YAML 형식의 분석 사양으로 사용하여 RUN을 호출합니다.
실행 구성에서 source_tables 필드에 전달하는 테이블은 템플릿의 source_table 매개변수를 채웁니다. 템플릿의 my_table 매개 변수는 자체 데이터와 함께 Snowflake Standard Edition을 사용하지 않는 한 채워지거나 사용되지 않습니다.
참고
리소스 설치는 비동기식입니다. 템플릿을 방금 설치한 경우 템플릿을 실행할 수 있을 때까지 다소 시간이 걸릴 수 있습니다. 템플릿에 코드 번들이 포함된 경우 템플릿을 사용할 수 있을 때까지 시간이 더 걸릴 수 있습니다. 코드 번들을 사용할 수 있는지 확인하는 방법에 대해 알아보세요.
다음 예제에서는 사용자가 액세스할 수 있는 데이터 오퍼링 및 템플릿을 나열한 다음, sales_join_template 템플릿(VIEW_TEMPLATES에 나열되어 있다고 가정)을 사용하여 분석을 실행하고 5개의 명명된 인자를 템플릿에 전달합니다.
-- See which data offerings are available.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.VIEW_DATA_OFFERINGS($collaboration_name);-- See which templates you can run.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.VIEW_TEMPLATES($collaboration_name);-- Pass in the arguments in analysis YAML format.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.RUN($collaboration_name,$$api_version:2.0.0spec_type:analysisname:My_analysisdescription:Sales results Q2 2025template:sales_join_templatetemplate_configuration:view_mappings:source_tables:-user1_alias.data_offering_v1.table_1-user2_alias.another_data_offering_v1.table_2arguments:-- The template defines conv_purchase_id and the other four arguments.conv_purchase_id:PURCHASE_ID -- You must examine a template to see which arguments it supports.conv_purchase_amount:PURCHASE_AMOUNTpublisher_impression_id:IMPRESSION_IDpublisher_campaign_name:CAMPAIGN_NAMEpublisher_device_type:DEVICE_TYPE $$);
RUN의 매개 변수화된 버전을 사용하는 경우 데이터 오퍼링 IDs를 local_template_view_names 매개 변수에 전달합니다.
RUN의 YAML 버전을 사용하는 경우 요청의 local_view_mappings.my_tables 스탠자에 데이터 오퍼링 IDs를 제공합니다.
RUN의 매개 변수화된 버전을 사용하는 경우 데이터 오퍼링 IDs를 local_template_view_names 매개 변수에 전달합니다.
팁
local_template_view_names 및 local_view_mappings.my_tables 는 템플릿에서 my_table 매개 변수를 채웁니다.
다음 예제에서는 실행 프로시저의 YAML 형식 버전을 사용하여 템플릿을 실행하는 방법을 보여줍니다. 이 예제에는 LINK_LOCAL_DATA_OFFERING을 호출하여 채워지는 my_tables 필드가 포함되어 있습니다.
-- See what data offerings are available. Your own local data will be listed here as well.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.VIEW_DATA_OFFERINGS($collaboration_name);-- Pass in the arguments in analysis YAML format.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.RUN($collaboration_name,$$api_version:2.0.0spec_type:analysisname:my_analysisdescription:Cross-purchase results for Q4 2025template:mytemplate_v1template_configuration:view_mappings:source_tables:-ADVERTISER1.ADVERTISER_DATA_V1.CUSTOMERS-PUBLISHER.ADVERTISER_DATA_V1.CUSTOMERSlocal_view_mappings:my_tables:-PARTNER.MY_DATA_V1.MY_CUSTOMERS# Populate my_table array with my own table.arguments:# Template arguments, as name: value pairsconv_purchase_id:PURCHASE_IDconv_purchase_amount:PURCHASE_AMOUNTpublisher_impression_id:IMPRESSION_IDpublisher_campaign_name:CAMPAIGN_NAMEpublisher_device_type:DEVICE_TYPE $$);
-- Basic Snowflake Collaboration Data Clean Rooms example.-- This file represents user "alice" in a two-collaborator clean room example.-- Run this worksheet in a Snowflake account with access to the latest version of-- Snowflake Data Clean Rooms.-- This file demonstrates the following actions:-- * How to register a template and a dataset-- * How to create a collaboration with pre-registered resources.-- * How to add a template to a collaboration that has already been created, and the-- template approval flow.-- * How to run an analysis.-- This scenario involves two collaborators: bob and alice-- bob and alice each submits one data source-- bob and alice are data providers for themselves and each other-- bob submits one template that only alice can use-- alice submits one template that they can both use, and one template that only alice can use-- For more information, read docs.snowflake.com/user-guide/cleanrooms/overviewUSEWAREHOUSEAPP_WH;USEROLESAMOOHA_APP_ROLE;-- Secondary roles must be disabled to call link_data_offerings.USE SECONDARY ROLESNONE;CREATEDATABASEIFNOTEXISTSALICE_DB;CREATESCHEMAIFNOTEXISTSALICE_DB.ALICE_SCH;CREATEORREPLACETABLEALICE_DB.ALICE_SCH.ALICE_DATAASSELECT*FROMsamooha_sample_database.demo.customersLIMIT100;-- Register a data offering to use in the initial collaboration definition.CALLsamooha_by_snowflake_local_db.registry.register_data_offering($$api_version: 2.0.0spec_type: data_offeringversion: v1name:<alicedataofferingname>datasets:-alias: customer_listdata_object_fqn: ALICE_DB.ALICE_SCH.ALICE_DATAobject_class: customallowed_analyses: template_onlyschema_and_template_policies: hashed_email: category: join_standardcolumn_type: hashed_email_b64_encodedstatus: category: passthrough $$);-- Save the ID of the registered data offering. SETalice_data_offering_id='<data_offering_id>';CALLsamooha_by_snowflake_local_db.registry.view_registered_data_offerings();-- Register a template to use in the initial collaboration definition.CALLsamooha_by_snowflake_local_db.registry.register_template($$api_version: 2.0.0spec_type: templatename: alice_only_templateversion:<version_number>type: sql_analysisdescription: Atesttemplatetemplate: SELECTt1.status,COUNT(*)FROMIDENTIFIER({{source_table[0]}})ASt1JOINIDENTIFIER({{source_table[1]}})ASt2ONt1.hashed_email_b64_encoded=t2.hashed_email_b64_encodedGROUPBYt1.status;$$);-- Save the ID of the registered template.SETmy_template_id='<alice_only_template_id>';CALLsamooha_by_snowflake_local_db.registry.view_registered_templates();-- Create a collaboration with the previously registered template and data offering.-- The collaboration supports two collaborators, with aliases alice (this account) and bob.-- Owner: alice-- Analysis runners:-- * alice, using her own data, and the template you created and registered earlier.-- * bob, with no listed templates or data.-- Data providers:-- * alice and bob, for alice-- * alice and bob, for bob-- Resources added: The template and data offering alice registered earlier.-- You will add more templates and data offerings to these users later. Only these-- users are invited to the collaboration, and no additional users can be added later.-- Replace the <...> placeholders with the appropriate values.-- Account data sharing IDs are -- SELECT CURRENT_ORGANIZATION_NAME() || '.' || CURRENT_ACCOUNT_NAME();CALLsamooha_by_snowflake_local_db.collaboration.initialize($$api_version: 2.0.0spec_type: collaborationname: my_first_collaboration_1_0owner: alicecollaborator_identifier_aliases: alice:<myaccountdatasharingID>bob:<bobaccountdatasharingID>analysis_runners: bob: data_providers: alice: data_offerings:-id:<alicedataofferingID>bob: data_offerings:[]alice: data_providers: alice: data_offerings:-id:<alicedataofferingID>bob: data_offerings:[]templates:-id:<aliceonlytemplateID>$$,'APP_WH');SETcollaboration_name='<collaboration_name>';-- INITIALIZE automatically joins the owner. Check status until JOINED.CALLsamooha_by_snowflake_local_db.collaboration.get_status($collaboration_name);-- Collaboration is visible here when the owner has joined.CALLsamooha_by_snowflake_local_db.collaboration.view_collaborations();-- Auto-approve any template requests from other collaborators that affect you.CALLsamooha_by_snowflake_local_db.collaboration.enable_template_auto_approval($collaboration_name);-- SWITCH TO collaborator to join the collaboration and add a template-- The template will be auto-approved.-- Create a new template.CALLsamooha_by_snowflake_local_db.registry.register_template($$api_version: 2.0.0spec_type: templatename: both_use_templateversion: 2026_01_12_V1type: sql_analysisdescription: test_descriptiontemplate: select*fromidentifier({{source_table[0]}})limit5; $$);SETboth_use_template='<template ID>';-- Ask to add the template to the collaboration. You must ask bob, because you're-- including bob in the sharing list. When you share a template with yourself,-- you auto-approve it.CALLsamooha_by_snowflake_local_db.collaboration.add_template_request($collaboration_name,$both_use_template,['alice','bob']-- List of collaborators who can use this template.);-- SWITCH TO bob to approve the request. Request wasn't approved automatically-- because bob didn't enable auto-approve.-- See if bob approved the request.CALLsamooha_by_snowflake_local_db.collaboration.view_update_requests($collaboration_name);-- See what the collaboration spec looks like now, after all the resource updates.-- Collaboration updates are asynchronous, so if all changes that you made aren't present,-- wait a minute or two, and then try again.CALLsamooha_by_snowflake_local_db.collaboration.view_collaborations()->>SELECT"COLLABORATION_SPEC"FROM$1WHERE"SOURCE_NAME"=$collaboration_name;-- SWITCH TO bob to add a data offering.-- Run an analysis.-- Tables are scoped as <data_offering_id>.<alias>.CALLsamooha_by_snowflake_local_db.collaboration.view_data_offerings($collaboration_name);SET$bob_data_offering='<bob data offering ID>';CALLsamooha_by_snowflake_local_db.collaboration.view_templates($collaboration_name);-- Run bob's template.-- Replace the placeholders with your variables.CALLsamooha_by_snowflake_local_db.collaboration.run($collaboration_name,$$api_version: 2.0.0spec_type: analysisdescription:<optionaldescriptionoftheanalysis>template:'<alice_only_template>'template_configuration: view_mappings: source_tables:-'<alice_data_offering_view_name>'-'<bob_data_offering_view_name>' $$);-- Multi-step cleanup process to delete the collaborations.-- Doesn't delete registered resources.CALLsamooha_by_snowflake_local_db.collaboration.teardown($collaboration_name);CALLsamooha_by_snowflake_local_db.collaboration.get_status($collaboration_name);-- When get_status reports LOCAL_DROP_PENDING, call teardown again.CALLsamooha_by_snowflake_local_db.collaboration.teardown($collaboration_name);DROPDATABASEALICE_DB;
-- Basic Snowflake Collaboration Data Clean Rooms example.-- This file represents user "bob" in a two-collaborator clean room example.-- Run this worksheet in a Snowflake account with access to the latest version of-- Snowflake Data Clean Rooms.-- This file demonstrates the following actions:-- * Joining a collaboration-- * Registering and adding a template and a data offering to an existing collaboration.-- * Running an analysis.-- For more information, read docs.snowflake.com/user-guide/cleanrooms/overviewUSEWAREHOUSEAPP_WH;USEROLESAMOOHA_APP_ROLE;-- Secondary roles can't be active when calling join or link_data_offering.USE SECONDARY ROLESNONE;-- Create sample data.CREATEDATABASEIFNOTEXISTSBOB_DB;CREATESCHEMAIFNOTEXISTSBOB_DB.BOB_SCH;CREATEORREPLACETABLEBOB_DB.BOB_SCH.BOB_DATAASSELECT*FROMsamooha_sample_database.demo.customers_2LIMIT100;-- See which collaborations you are invited to, or have joined.CALLsamooha_by_snowflake_local_db.collaboration.view_collaborations();-- Use SOURCE_NAME column value from the response to view_collaborations().SETcollaboration_name='<collaboration name>';-- Use OWNER_ACCOUNT column value from the response to view_collaborations().SETcollaborator_data_sharing_id='<collaborator_id>';-- Review and join the collaboration.-- Joining is asynchronous, so you must call get_status until the status is JOINED before-- you can perform actions on the collaboration.CALLsamooha_by_snowflake_local_db.collaboration.review($collaboration_name,$collaborator_data_sharing_id);CALLsamooha_by_snowflake_local_db.collaboration.join($collaboration_name);CALLsamooha_by_snowflake_local_db.collaboration.get_status($collaboration_name);-- Demonstrate the auto-approve flow.-- Alice enabled auto-approve on her account, so this request will-- be auto-approved, and the template will be added immediately.-- Create a template.CALLsamooha_by_snowflake_local_db.registry.register_template($$api_version: 2.0.0spec_type: templatename: auto_approve_templateversion: V1type: sql_analysisdescription: test_descriptiontemplate: SELECT*FROMIDENTIFIER({{SOURCE_TABLE[0]}})LIMIT10; $$);SETauto_approve_template='<template_id>';CALLsamooha_by_snowflake_local_db.collaboration.add_template_request($collaboration_name,$auto_approve_template,['alice','bob']);CALLsamooha_by_snowflake_local_db.collaboration.view_update_requests($collaboration_name);-- SWITCH TO other account and request adding a template, and then come back to approve the request.-- You haven't enabled template auto-approve, so you must approve the request before the template is added.CALLsamooha_by_snowflake_local_db.collaboration.view_update_requests($collaboration_name);CALLsamooha_by_snowflake_local_db.collaboration.approve_update_request($collaboration_name,'<request_ID>');-- SWITCH TO bob to see the request status.-- Register your own data offering.CALLsamooha_by_snowflake_local_db.registry.register_data_offering($$api_version: 2.0.0spec_type: data_offeringversion: v3name: bob_datadatasets:-alias: my_customer_listdata_object_fqn: BOB_DB.BOB_SCH.BOB_DATAobject_class: customallowed_analyses: template_onlyschema_and_template_policies: hashed_email: category: join_standardcolumn_type: hashed_email_b64_encodedstatus: category: passthrough $$);SETmy_data_id='<data offering id>';-- Share the data offering with yourself and alice.CALLsamooha_by_snowflake_local_db.collaboration.link_data_offering($collaboration_name,$my_data_id,['alice','bob']);CALLsamooha_by_snowflake_local_db.collaboration.view_data_offerings($collaboration_name);-- View templates that you can use in this collaboration. You can run only templates that list you in the-- SHARED_WITH column.CALLsamooha_by_snowflake_local_db.collaboration.view_templates($collaboration_name);-- Run an analysis with your template.CALLsamooha_by_snowflake_local_db.collaboration.run($collaboration_name,$$api_version: 2.0.0spec_type: analysisdescription:<optionaldescriptionoftheanalysis>template:'<both_use_template>'template_configuration: view_mappings: source_tables:-'<my_data_offering_view_name>'-'<bob_data_offering_view_name>' $$);-- SWITCH TO other account to run an analysis.-- Try running an analysis using alice-only template.-- This will fail, because you aren't listed as an analysis-- runner for this template.CALLsamooha_by_snowflake_local_db.collaboration.run($collaboration_name,$$api_version: 2.0.0spec_type: analysisdescription:<optionaldescriptionoftheanalysis>template:'<alice_only_template>'template_configuration: view_mappings: source_tables:-'<my_data_offering_view_name>'-'<bob_data_offering_view_name>' $$);-- Clean up resources.DROPDATABASEBOB_DB;
-- ============================================================================-- Single-user Collaboration Clean Rooms demo-- ============================================================================-- This example demonstrates a basic Snowflake Data Clean Rooms collaboration-- using a single Snowflake account and a single role: SAMOOHA_APP_ROLE.-- One user acts as the owner, data provider, and analysis runner.---- The user creates two sample datasets, registers two data offerings and two-- templates, then creates a collaboration with one data offering and one template each.-- After the collaboration is created, the user links the remaining data offering and-- template, then runs an analysis with each template. Finally, the code-- cleans up all resources used.---- For more information, see:-- docs.snowflake.com/user-guide/cleanrooms/overview-- docs.snowflake.com/user-guide/cleanrooms/spec-reference-- ============================================================================-- ============================================================================-- SETUP: Create sample databases and data.-- ============================================================================USEROLESAMOOHA_APP_ROLE;USEWAREHOUSEAPP_WH;-- You can't use secondary roles with most collaboration procedures.USE SECONDARY ROLESNONE;CREATEDATABASEIFNOTEXISTSDEMO_DB;CREATESCHEMAIFNOTEXISTSDEMO_DB.DATA_SCH;-- Dataset 1: 300 rows from CUSTOMERS.CREATEORREPLACETABLEDEMO_DB.DATA_SCH.CUSTOMERS_1ASSELECTHASHED_EMAIL,STATUS,AGE_BANDFROMSAMOOHA_SAMPLE_DATABASE.DEMO.CUSTOMERSLIMIT300;-- Dataset 2: 300 rows from CUSTOMERS_2.CREATEORREPLACETABLEDEMO_DB.DATA_SCH.CUSTOMERS_2ASSELECTHASHED_EMAIL,STATUS,AGE_BANDFROMSAMOOHA_SAMPLE_DATABASE.DEMO.CUSTOMERS_2LIMIT300;-- ============================================================================-- Register data offerings and templates.-- ============================================================================-- Register the first data offering.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.REGISTRY.REGISTER_DATA_OFFERING($$api_version: 2.0.0spec_type: data_offeringversion: V1name: customers_1datasets:-alias: customers_1data_object_fqn: DEMO_DB.DATA_SCH.CUSTOMERS_1object_class: customallowed_analyses: template_onlyschema_and_template_policies: hashed_email: category: join_standardcolumn_type: hashed_email_b64_encodedstatus: category: passthroughage_band: category: passthrough $$);SETdata_offering_1_id='<data_offering_1_id>';-- Register the second data offering.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.REGISTRY.REGISTER_DATA_OFFERING($$api_version: 2.0.0spec_type: data_offeringversion: V1name: customers_2datasets:-alias: customers_2data_object_fqn: DEMO_DB.DATA_SCH.CUSTOMERS_2object_class: customallowed_analyses: template_onlyschema_and_template_policies: hashed_email: category: join_standardcolumn_type: hashed_email_b64_encodedstatus: category: passthroughage_band: category: passthrough $$);SETdata_offering_2_id='<data_offering_2_id>';-- Register a template that joins two tables on hashed_email and returns-- a count of rows grouped by age_band.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.REGISTRY.REGISTER_TEMPLATE($$api_version: 2.0.0spec_type: templatename: age_band_countversion: V1type: sql_analysisdescription: Joinstwotablesonhashed_emailandreturnsage_bandwithrowcounts.template: SELECTt1.age_band,COUNT(t1.age_band)ASage_band_countFROMIDENTIFIER({{source_table[0]}})ASt1JOINIDENTIFIER({{source_table[1]}})ASt2ONt1.hashed_email_b64_encoded=t2.hashed_email_b64_encodedGROUPBYt1.age_band;$$);SETage_band_template_id='<age_band_template_id>';-- Register a template that joins two tables on hashed_email and returns-- a count of rows grouped by status.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.REGISTRY.REGISTER_TEMPLATE($$api_version: 2.0.0spec_type: templatename: status_countversion: V1type: sql_analysisdescription: Joinstwotablesonhashed_emailandreturnsstatuswithrowcounts.template: SELECTt1.status,COUNT(t1.status)ASstatus_countFROMIDENTIFIER({{source_table[0]}})ASt1JOINIDENTIFIER({{source_table[1]}})ASt2ONt1.hashed_email_b64_encoded=t2.hashed_email_b64_encodedGROUPBYt1.status;$$);SETstatus_template_id='<status_template_id>';-- Confirm that both data offerings and both templates are registered.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.REGISTRY.VIEW_REGISTERED_DATA_OFFERINGS();CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.REGISTRY.VIEW_REGISTERED_TEMPLATES();-- ============================================================================-- Create the collaboration with one data offering and one template.-- ============================================================================-- Replace <account_data_sharing_id> with:-- SELECT CURRENT_ORGANIZATION_NAME() || '.' || CURRENT_ACCOUNT_NAME();CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.INITIALIZE($$api_version: 2.0.0spec_type: collaborationname: single_user_demoowner: mecollaborator_identifier_aliases: me:<account_data_sharing_id>analysis_runners: me: data_providers: me: data_offerings:-id:<data_offering_1_id>templates:-id:<age_band_template_id> $$,'APP_WH');SETcollaboration_name='<collaboration_name>';-- Verify that the owner has joined. Repeat until status is JOINED.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.GET_STATUS($collaboration_name);-- ============================================================================-- Link the remaining data offering and template into the collaboration.-- ============================================================================-- Link the second data offering.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.LINK_DATA_OFFERING($collaboration_name,$data_offering_2_id,['me']);-- Add the status_count template to the collaboration.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.ADD_TEMPLATE_REQUEST($collaboration_name,$status_template_id,['me']);-- ============================================================================-- List resources and run analyses.-- ============================================================================-- List all data offerings in the collaboration.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.VIEW_DATA_OFFERINGS($collaboration_name);-- List all templates in the collaboration.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.VIEW_TEMPLATES($collaboration_name);-- Run the age_band_count template.-- Replace placeholders with the template name/version and view names from-- VIEW_TEMPLATES and VIEW_DATA_OFFERINGS.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.RUN($collaboration_name,$$api_version: 2.0.0spec_type: analysisdescription: Countmatchingrowsgroupedbyage_band.template:'<age_band_count_template_name_and_version>'template_configuration: view_mappings: source_tables:-'<data_offering_view_1>'-'<data_offering_view_2>' $$);-- Run the status_count template.-- Replace placeholders with the template name/version and view names from-- VIEW_TEMPLATES and VIEW_DATA_OFFERINGS.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.RUN($collaboration_name,$$api_version: 2.0.0spec_type: analysisdescription: Countmatchingrowsgroupedbystatus.template:'<status_count_template_name_and_version>'template_configuration: view_mappings: source_tables:-'<data_offering_view_1>'-'<data_offering_view_2>' $$);-- ============================================================================-- CLEANUP: Delete the collaboration, registered resources, and sample data.-- ============================================================================-- Teardown is a multi-step process. Call TEARDOWN, then wait for GET_STATUS-- to report LOCAL_DROP_PENDING, then call TEARDOWN again.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.TEARDOWN($collaboration_name);CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.GET_STATUS($collaboration_name);-- When GET_STATUS reports LOCAL_DROP_PENDING, call TEARDOWN again to complete.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.COLLABORATION.TEARDOWN($collaboration_name);-- Unregister the data offerings and templates from the default registry.CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.REGISTRY.UNREGISTER_DATA_OFFERING($data_offering_1_id);CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.REGISTRY.UNREGISTER_DATA_OFFERING($data_offering_2_id);CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.REGISTRY.UNREGISTER_TEMPLATE($age_band_template_id);CALLSAMOOHA_BY_SNOWFLAKE_LOCAL_DB.REGISTRY.UNREGISTER_TEMPLATE($status_template_id);-- Drop the sample database.DROPDATABASEIFEXISTSDEMO_DB;