チュートリアル:Snowpipeストリーミング・ハイパフォーマンス・アーキテクチャ SDK の使用を始める

このチュートリアルでは、新しいハイパフォーマンスアーキテクチャを利用したデモアプリケーションのセットアップと実行について、 snowpipe-streaming SDK で手順を説明します。

前提条件

デモを実行する前に、以下の前提条件を満たしていることを確認してください。

  • Snowflakeアカウント:Snowflakeアカウントにアクセスできることを確認します。ステップ1:Snowflakeオブジェクトの構成 に詳述されている専用ユーザーとカスタムロールを作成するには、十分な権限(例えば、初期セットアップには ACCOUNTADMIN または USERADMIN)を持つユーザーが必要です。

  • ネットワークアクセス:ネットワークがSnowflakeおよび AWSS3 へのアウトバウンド接続を許可していることを確認します。必要に応じて ファイアウォールルールを調整します。これは、 SDK が Snowflakeと AWS S3 にRESTAPI コールをするからです。

  • Java開発環境Java 11以降と、依存関係管理のためのMavenをインストールします。

  • Python:Pythonバージョン3.9以降をインストールします。

  • Snowpipe Streaming SDKs and the sample code: Obtain the Java SDK or Python SDK and download the sample code for your preferred language from the Snowpipe Streaming SDK examples in the GitHub repository.

始めましょう

このセクションでは、デモアプリケーションのセットアップと実行に必要な手順の概要を説明します。

ステップ1:Snowflakeオブジェクトの構成

Before you can use the snowpipe-streaming SDK, you must create a target table within your Snowflake environment. Unlike the classic architecture, the high-performance architecture requires a PIPE object for data ingestion. This tutorial uses the default pipe that is automatically created at ingest time for your target table. If you require additional features, such as in-flight transformations or clustering at ingest time, see CREATE PIPE.

認証用キーペアの生成

OpenSSL を使って認証用の秘密キーと公開キーのキーペアを生成します。詳細については、 キーペア認証とキーペアローテーション をご参照ください。

ターミナルで以下のコマンドを実行し、キーを生成します。

openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8 -nocrypt
openssl rsa -in rsa_key.p8 -pubout -out rsa_key.pub
Copy
PUBK=$(cat ./rsa_key.pub | grep -v KEY- | tr -d '\012')
echo "ALTER USER MY_USER SET RSA_PUBLIC_KEY='$PUBK';"
Copy

重要

Save the generated rsa_key.p8 (private key) and rsa_key.pub (public key) files securely. You will use these keys in subsequent authentication steps.

Create database, schema, table, and configure user authentication

Run the following SQL commands in your Snowflake account; for example, by using Snowsight or Snowflake CLI). You must have a role with permissions to create users, roles, and databases --- such as ACCOUNTADMIN or USERADMIN for the first few lines, and then switching to the new role. Replace placeholders like MY_USER, MY_ROLE, MY_DATABASE, and so on, with the names that you want.

-- 1. Create a dedicated role and user (Run with a highly-privileged role)
CREATE OR REPLACE USER MY_USER;
CREATE ROLE IF NOT EXISTS MY_ROLE;
GRANT ROLE MY_ROLE TO USER MY_USER;

-- 2. Set the public key for key-pair authentication
-- NOTE: Replace 'YOUR_FORMATTED_PUBLIC_KEY' with the output of the PUBK variable from the key generation step.
ALTER USER MY_USER SET RSA_PUBLIC_KEY='YOUR_FORMATTED_PUBLIC_KEY';

-- 3. Set the default role (Recommended)
ALTER USER MY_USER SET DEFAULT_ROLE=MY_ROLE;

-- 4. Switch to the new role and create objects
USE ROLE MY_ROLE;
-- NOTE: You may also need to run USE WAREHOUSE YOUR_WH; here if a default warehouse isn't set.

-- Create database and schema
CREATE OR REPLACE DATABASE MY_DATABASE;
CREATE OR REPLACE SCHEMA MY_SCHEMA;

-- Create a target table
CREATE OR REPLACE TABLE MY_TABLE (
    data VARIANT,
    c1 NUMBER,
    c2 STRING
);

-- 5. Configure authentication policy (Optional, but recommended for explicit control)
CREATE OR REPLACE AUTHENTICATION POLICY testing_auth_policy
  AUTHENTICATION_METHODS = ('KEYPAIR')
  CLIENT_TYPES = ('DRIVERS');

-- Apply authentication policy (if created)
ALTER USER MY_USER SET AUTHENTICATION POLICY testing_auth_policy;
Copy

ステップ2:認証プロファイルの構成

デモアプリケーションでは、認証の詳細を含む接続設定を保存するために profile.json ファイルが必要です。SDK は、キーペア認証を使用して安全な接続を行います。

プロファイル構成ファイルの作成

デモプロジェクトのルートディレクトリで profile.json ファイルを作成または更新します。

profile.jsonテンプレート

{
    "user": "MY_USER",
    "account": "your_account_identifier",
    "url": "https://your_account_identifier.snowflakecomputing.com:443",
    "private_key_file": "rsa_key.p8",
    "role": "MY_ROLE"
}
Copy

プレースホルダーを置き換えます。

ステップ3:デモプロジェクトのセットアップ

Download: Sample Java code

JAR 依存関係の追加

Snowpipe Streaming SDKを含めるには、Maven :code:`pom.xml`に以下の依存関係を追加します。Maven はパブリックリポジトリから JAR を自動的にダウンロードします。

<dependency>
    <groupId>com.snowflake</groupId>
    <artifactId>snowpipe-streaming</artifactId>
    <version>YOUR_SDK_VERSION</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.18.1</version>
</dependency>
Copy

重要

YOUR_SDK_VERSIONMaven Central で利用できる特定のバージョンに置き換えます。

プロファイルファイルの配置

ステップ2:認証プロファイルの構成 で構成した profile.json ファイルが、プロジェクトのルートディレクトリにあることを確認してください。

ステップ4:提供されたコード例を使用した、デモアプリケーションの実行

ターミナルで、プロジェクトのルートディレクトリにナビゲートします。

ビルドと実行

  • プロジェクトの構築:

    mvn clean install
    
    Copy
  • メインクラスを実行します。

    mvn exec:java -Dexec.mainClass="com.snowflake.snowpipestreaming.demo.Main"
    
    Copy

ステップ5:データの検証

デモを実行した後、Snowflakeで取り込まれたデータを確認します:

SELECT COUNT(*) FROM MY_DATABASE.MY_SCHEMA.MY_TABLE;
SELECT * FROM MY_DATABASE.MY_SCHEMA.MY_TABLE LIMIT 10;
Copy