Snowflake Data Clean Rooms 開発者ガイド

This topic provides guidelines for users who want to create or manage Snowflake Data Clean Rooms programmatically.

Snowflake exposes an API of stored procedures for creating and controlling clean rooms. These stored procedures can be run in any interface that can access the Snowflake account associated with your clean room environment, including Snowsight notebooks and worksheets, as well as the Snowflake CLI. These procedures can be called in SQL or in any language supported by your Snowflake environment.

環境のセットアップ

開発ツール

clean room用の主な開発ツールを以下に示します:

  • コーディング環境: Snowflakeアカウントでストアドプロシージャを実行できる環境であれば、どのようなコーディング環境でもかまいません。ほとんどの開発者は、Snowsight(ブラウザベースのツール)または Snowflake CLI を使用しています。

  • The clean rooms UI: Use the clean rooms UI to configure, manage, or create clean rooms. Most clean room analysts use the UI rather than code, so it's important to see and test the experience of your clean rooms in the UI. Additionally, there are a handful of features that are available only in the clean rooms UI.

  • Snowsight は、データベースやその他のオブジェクトを探索したり、検索したりするのに便利です。

  • Clean rooms API: API documentation is divided into provider and consumer topic pages.

コーディング設定

必要なロールとウェアハウス

The clean rooms API requires the SAMOOHA_APP_ROLE role for full API access. Ask your clean rooms administrator to grant you full API access. Clean rooms also supports creating roles with access to a subset of API procedures.

SAMOOHA_APP_ROLE を使用できるウェアハウスでクリーンルーム API を使用する必要があります。app_wh は API へのアクセス権がある 多くのウェアハウス のうちのひとつです。ニーズに合わせて適切なウェアハウスを選択してください。

-- Set up environment.
USE ROLE SAMOOHA_APP_ROLE;
USE WAREHOUSE app_wh;

-- Call your clean rooms API functions.
...
Copy

他のウェアハウスを使用する場合は、必ずそのウェアハウスに SAMOOHA_APP_ROLE の使用を許可してください:

GRANT USAGE ON WAREHOUSE <your_warehouse> TO SAMOOHA_APP_ROLE;`
Copy

clean room API について

Snowflake Data Clean Rooms exposes a set of stored procedures that let a provider create, configure, and share a clean room. These procedures can be called in any command-line environment that supports Snowflake procedures, including notebooks, worksheets, and the Snowflake CLI. The documentation here shows SQL usage, but you can also use Python or any other supported Snowflake language.

プロシージャは以下のスキーマ内に存在します。

  • samooha_by_snowflake_local_db.provider - プロバイダー固有のプロシージャ.これらのプロシージャは、現在のアカウントによって作成されたclean roomに対してのみ呼び出すことができます。

  • samooha_by_snowflake_local_db.consumer - コンシューマー固有のプロシージャ.これらのプロシージャは、現在のアカウントがコンシューマーとして招待されたクリーンルームに対してのみ呼び出すことができます。

  • samooha_by_snowflake_local_db.library - General procedures called by either the clean room creator (provider) or a clean room collaborator (consumer). These procedures are documented in both the provider and consumer reference pages.

Some procedures have both provider and consumer versions. The results are appropriate to the schema: for example, provider.view_cleanrooms lists all clean rooms in the current account for which you are a provider, and consumer.view_cleanrooms lists all clean rooms in the current account for which you are a consumer. Be sure to call the procedure in the namespace that you need.

API プロシージャのclean roomの名称について

clean room API プロシージャの多くは cleanroom_name 引数を取ります。

  • クリーンルームが** API を使用して作成された**ものである場合、クリーンルーム :emph:` 名 `を使用します。パッケージ名の一部として使用する場合は、スペースをアンダースコアに置き換えます。

    -- Spaces work here:
    CALL samooha_by_snowflake_local_db.provider.describe_cleanroom('my code created clean room');
    
    -- Underscores required here:
    SHOW VERSIONS IN APPLICATION PACKAGE SAMOOHA_CLEANROOM_my_code_created_clean_room;
    
    Copy
  • クリーンルームが**クリーンルーム UI を使用して作成された**ものである場合、クリーンルーム ID を使用します。

describe_cleanroom または view_cleanrooms を呼び出すと、クリーンルーム名と ID が表示されます。

Clean rooms created using the API are labeled in the clean rooms UI as Supported with Developer APIs.

アカウント、ユーザー、ロールのセットアップ

You aren't required to use the clean rooms UI to develop clean rooms: most clean room functionality is available by calling the API. However, a few features are available only in the UI, and some are faster to perform in the UI. And because many users use the UI exclusively, it's important to see how your clean room behaves in the UI. Therefore, you should ask a clean room administrator to add you as a clean room manager or higher in the appropriate clean room accounts.

ユースケースに応じて、異なるウェブホスティング地域に追加のSnowflakeアカウントを設定し、 クロスクラウドの動作 をテストしてもよいかもしれません。

Name your test Snowflake accounts meaningfully to indicate their typical usage: for example, "Consumer account," "Provider account," and "Cross-cloud account." This can help when you have multiple test accounts and must choose an account on the clean rooms login page.

内部テストクリーンルーム

You can test a clean room during development by sharing the clean room with yourself. Such a clean room is called an internal testing clean room. Using a single account for both provider and consumer is convenient for quick feature testing.

To create an internal testing clean room, simply pass the provider account information to provider.add_consumers as the sole consumer.

Internal testing clean rooms have the following restrictions:

  • An internal testing clean room cannot later be shared with other accounts. An internal testing clean room always is an internal testing clean room.

  • 以下の機能は内部テストクリーンルームではサポートされていません。

    • プロバイダーのアクティベーション

    • プロバイダー実行の分析

    • リクエストログのマウントまたは表示(provider.mount_request_logs_for_all_consumers または provider.view_request_logs

    • コンシューマー定義のテンプレート

    • マルチプロバイダー分析

    • 差分プライバシー

    内部テストルームでサポートされていない機能をテストしたい場合は、クリーンルームの両側をテストするために、プロバイダーとコンシューマーのSnowflakeアカウントを別々に設定する必要があります。

Download a sample worksheet that demonstrates using a clean room in a single account for both provider and consumer.

クリーンルーム環境でインストールされたものを見る

Snowflake Data Clean Roomsは、インストール時に多くのローカルデータベースを作成します。クリーンルームパッケージで実行またはインストールされるタスクとオブジェクトの詳細は、Snowflake Data Clean Rooms: インストールされたオブジェクト で確認できます。

サンプルデータ

クリーンルーム環境は、使用できる いくつかのサンプルデータセット をインストールします。

また、Snowflakeを使用して 合成テストデータを生成 できます。

ガイドラインと推奨事項

clean room UI とコードで同じアカウントを使用していることを確認する

同じSnowflakeアカウントでコーディング環境とclean room UI を開くことも少なくありません(たとえば、コードでclean roomを作成し、その表示をclean room UI で確認する場合など)。その場合は、同じSnowflakeアカウントをそれぞれに使用しているかを確認することが重要です。

Snowsight does not have a shortcut to open the clean rooms UI for the same account, or the reverse, so you must be sure to log in to the same account in each environment.

Clean roomの名前とclean roomの ID

When using the API, for procedures that take a clean room name argument, determine whether to use the clean room name or the clean room ID as follows:

  • API を使用してclean roomを作成した場合は、clean roomの 名前 を使用します。

  • クリーンルームがクリーンルーム UI 内に作成された場合はクリーンルーム**ID**を使用します。provider.view_cleanrooms または provider.describe_cleanroom を呼び出すと、クリーンルーム名と ID の両方を見ることができます。

Update your clean room whenever you make UI changes

When you change any clean room properties that affect the UI, call provider.create_or_update_cleanroom_listing to propagate the changes.

コードまたは UI で作成されたclean roomの相互運用性

When you create a clean room using the API, some features are not modifiable in the clean rooms UI. For example, you cannot add additional templates, even stock Snowflake templates, in code for a UI-created clean room. You also cannot change the differential privacy settings.

トラブルシューティング

コンシューマーは、結合済みクリーンルームで結合ポリシーを設定したり、他の基本的なアクションを実行したりすることはできません。

clean roomが適切なロール (SAMOOHA_APP_ROLE) でインストールされたことを確認してください。clean roomをインストールする際に SAMOOHA_APP_ROLE を使用していない場合、アクセス許可のエラーをはじめとする多くの問題が発生します。そのの場合は consumer.uninstall_cleanroom までもがエラーになり、clean roomをアンインストールしてから正しいロールで再インストールするという面倒な手間が必要になります。

-- Who owns the clean room?
SHOW SHARES LIKE 'SAMOOHA_CLEANROOM_REQUESTS_<cleanroom_name>';

-- If the owner role is not SAMOOHA_APP_ROLE, you must drop the share, then
-- uninstall the clean room.
DROP SHARE SAMOOHA_CLEANROOM_REQUESTS_<cleanroom_name>;
CALL samooha_by_snowflake_local_db.consumer.uninstall_cleanroom($cleanroom_name);
USE ROLE SAMOOHA_APP_ROLE;
CALL samooha_by_snowflake_local_db.consumer.install_cleanroom($cleanroom_name, '<provider_locator>');
Copy

自分で作ったclean roomが見つからない

アカウントでclean roomを作成したのに、コラボレーターのアカウントで表示されない場合、以下の理由が考えられます:

  • clean roomが別のクラウドホスティングリージョンで作成され、 クロスクラウド自動フルフィルメント を有効にしていない。

  • provider.create_or_update_cleanroom_listing を呼び出してclean roomを公開していない。

  • provider.view_cleanrooms() ではなく、 consumer.view_cleanrooms() を呼び出している(またはその逆)。

  • clean roomを共有していないか、間違ったアカウントでclean roomを共有しているか、またはSnowsight/Clean roomの UI/CLI を間違ったコラボレーターアカウントで開いている。clean roomが表示されるアカウントが、clean roomを共有したアカウントであり、その共有アカウントでサインインしたことを確認してください。

  • clean roomを公開した後、それがコラボレーターに表示されるまで多少時間がかかります。

不明な関数

プロシージャを呼び出して、次のスニペットのようなエラーが発生した場合。

Unknown user-defined function SAMOOHA_BY_SNOWFLAKE_LOCAL_DB.CONSUMER.<procedure name>

考えられる原因はいくつかあります。

間違った名前空間を入力してしまった。

プロシージャのバージョン( consumer または provider )を正しく判断して呼び出してください。多くのプロシージャには、プロバイダーとコンシューマーの両方のバージョンがあります。

関数の名前を誤入力してしまった。

適切な名前については、リファレンスガイドを確認してください。

制限付きアクセス実行ロールが付与されていますが、呼び出した関数はあなたのロールで許可されていません。

次の SQL コードを実行してこれをテストします。

USE DATABASE samooha_by_snowflake_local_db;
CALL IS_DATABASE_ROLE_IN_SESSION('samooha_run_role');
Copy

コードスニペットが TRUE を返す場合、クリーンルーム API での制限付きアクセス 実行ロール 権限があります。より広範囲なアクセスが必要な場合は、クリーンルーム管理者にフルアクセスを依頼してください。許可された実行ロールプロシージャのリストは、consumer.grant_run_on_cleanrooms_to_role ドキュメント をご参照ください。

SAMOOHA_APP_ROLE がない

SAMOOHA_APP_ROLE が使用できるかどうかを確認するには、次のコマンドを実行します。

-- Get current user name.
SELECT current_user();

-- Add current user name in place as indicated.
SHOW GRANTS TO USER <current_user_name> ->> select * from $1 where "role" = 'SAMOOHA_APP_ROLE';
Copy

結果が得られない場合は、管理者に API クリーンルームへのアクセス付与を依頼してください。

ユーザーがクリーンルームをインストールしているかどうかを確認する

指定したユーザーが指定したクリーンルームをインストールしているかどうかは、以下の SQL コードを実行することで確認できます。$consumer_locator および $cleanroom_name をコンシューマーロケーターとクリーンルーム名に置き換えます。

SELECT * FROM snowflake.data_sharing_usage.application_state
  WHERE consumer_account_locator = $consumer_locator
    AND CONTAINS(package_name, UPPER(REPLACE($cleanroom_name, ' ', '_')));
Copy

クエリや分析履歴の確認

UI またはコードで実行した分析のクエリ履歴を確認できます。これらの履歴は個別に保存され、チェックされます。

UI 分析履歴

クリーンルーム UI は、このアカウントの Analyses & Queries ページにある以前の分析リストをすべて表示します。これらは、UI で実行されたクエリの結果に限られます。

クリーンルームを変更または削除すると、そのクリーンルームに対する UI の分析レポートは、以下のテンプレートを使用しない限り削除されます。

  • Audience Overlap & Segmentation

  • SQL Query

  • カスタムテンプレート。

上記のテンプレートのクエリ履歴は、クリーンルームが変更または削除されても保持されます。

API のクエリ履歴

テンプレート分析を含む、API を使用して実行されたすべての呼び出しのアカウント履歴を確認するには、以下を実行します。

  1. Snowsight にサインインします。

  2. ナビゲーションメニューで Monitoring » Query History を選択します。

  3. フィルターを使用して、分析に関連付けられたクエリを見つけ、クエリまたは分析を選択します。

拡張例

To help you understand how to use various features of the Developer APIs, you can refer to the examples in the Use cases and Features sections of the clean rooms documentation.