> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> Amazon Kinesis のデータソースを ClickHouse Cloud にシームレスに接続します。

# Amazon Kinesis と ClickHouse Cloud の統合

export const Image = ({img, alt, size = "lg"}) => {
  const normalizedSize = ["sm", "md", "lg"].includes(size) ? size : "lg";
  return <div className={`ch-image-${normalizedSize}`}>
      <Frame>
        <img src={img} alt={alt} />
      </Frame>
    </div>;
};

Kinesis ClickPipes は、ClickPipes UI を使用して手動でデプロイおよび管理できるほか、[OpenAPI](/docs/ja/integrations/clickpipes/programmatic-access/openapi) や [Terraform](/docs/ja/integrations/clickpipes/programmatic-access/terraform) を使用してプログラムによってデプロイおよび管理することもできます。

<div id="prerequisite">
  ## 前提条件
</div>

あらかじめ [ClickPipes の概要](/docs/ja/integrations/clickpipes/home)を確認し、[IAM 認証情報](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html)または [IAM ロール](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html)を設定しておいてください。ClickHouse Cloud で使用するロールの設定方法については、[Kinesis のロールベースアクセスガイド](/docs/ja/integrations/clickpipes/kinesis/auth)を参照してください。

<div id="creating-your-first-clickpipe">
  ## 最初の ClickPipe を作成する
</div>

1. ClickHouse Cloud サービスの SQL Console にアクセスします。

<Image img="https://mintcdn.com/private-7c7dfe99/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/cp_service.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=ba65ca18b8e032a9d412b779741717f5" alt="ClickPipes サービス" size="lg" border width="1184" height="482" data-path="images/integrations/data-ingestion/clickpipes/cp_service.webp" />

2. 左側のメニューで `Data Sources` ボタンを選択し、"Set up a ClickPipe" をクリックします。

<Image img="https://mintcdn.com/private-7c7dfe99/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/cp_step0.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=fb04bb07245be43cb784fa68cee62287" alt="インポートを選択" size="lg" border width="2606" height="790" data-path="images/integrations/data-ingestion/clickpipes/cp_step0.webp" />

3. データソースを選択します。

<Image img="https://mintcdn.com/private-7c7dfe99/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/cp_step1.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=43a323a7dbf7daf017f2b8498336363d" alt="データソースの種類を選択" size="lg" border width="2600" height="1890" data-path="images/integrations/data-ingestion/clickpipes/cp_step1.webp" />

4. ClickPipe の名前、説明 (任意) 、IAM ロールまたは認証情報、そのほかの接続情報を入力します。

<Image img="https://mintcdn.com/private-7c7dfe99/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/cp_step2_kinesis.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=18a6e7aaabeafbfbaad10b0f0b3ee755" alt="接続情報を入力" size="lg" border width="2266" height="1226" data-path="images/integrations/data-ingestion/clickpipes/cp_step2_kinesis.webp" />

5. Kinesis Stream と開始オフセットを選択します。UI には、選択したソース (Kafka topic など) のサンプルドキュメントが表示されます。また、Kinesis streams では Enhanced Fan-out を有効にして、ClickPipe のパフォーマンスと安定性を向上させることもできます (Enhanced Fan-out の詳細は[こちら](https://aws.amazon.com/blogs/aws/kds-enhanced-fanout)を参照してください) 。

<Image img="https://mintcdn.com/private-7c7dfe99/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/cp_step3_kinesis.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=1ed04438f21e16e971e2ed13fe96b86e" alt="データフォーマットと topic を設定" size="lg" border width="2274" height="1540" data-path="images/integrations/data-ingestion/clickpipes/cp_step3_kinesis.webp" />

6. 次のステップでは、データの取り込み先を新しい ClickHouse テーブルにするか、既存のテーブルを再利用するかを選択できます。画面の指示に従って、テーブル名、スキーマ、設定を変更してください。変更内容は、上部のサンプルテーブルでリアルタイムにプレビューできます。

<Image img="https://mintcdn.com/private-7c7dfe99/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/cp_step4a.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=e0cdb9469f6867e897cc77541af7f59b" alt="table、スキーマ、settings を設定" size="lg" border width="2734" height="1328" data-path="images/integrations/data-ingestion/clickpipes/cp_step4a.webp" />

用意されているコントロールを使って、高度な設定をカスタマイズすることもできます。

<Image img="https://mintcdn.com/private-7c7dfe99/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/cp_step4a3.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=db7cb839e136d26563b239937f029c7a" alt="高度な controls を設定" size="lg" border width="1592" height="338" data-path="images/integrations/data-ingestion/clickpipes/cp_step4a3.webp" />

7. また、既存の ClickHouse テーブルにデータを取り込むこともできます。その場合、UI ではソースのフィールドを、選択した宛先テーブル内の ClickHouse フィールドにマッピングできます。

<Image img="https://mintcdn.com/private-7c7dfe99/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/cp_step4b.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=a5cb66aa9b3855c5d53b340dbd89b108" alt="既存の table を使用" size="lg" border width="2738" height="1322" data-path="images/integrations/data-ingestion/clickpipes/cp_step4b.webp" />

8. 最後に、内部 ClickPipes ユーザーの権限を設定できます。

**Permissions:** ClickPipes は、宛先テーブルにデータを書き込むための専用ユーザーを作成します。カスタムロールまたは定義済みロールのいずれかを使って、この内部ユーザーに割り当てるロールを選択できます。

* `Full access`: クラスターへのフルアクセス権を持ちます。宛先テーブルで materialized view や Dictionary を使用する場合に便利です。
  * `Only destination table`: 宛先テーブルに対する `INSERT` 権限のみを持ちます。

<Image img="https://mintcdn.com/private-7c7dfe99/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/cp_step5.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=71ea5baaa2c38fcc83b160f4856264ab" alt="Permissions" border width="2736" height="1318" data-path="images/integrations/data-ingestion/clickpipes/cp_step5.webp" />

9. "Complete Setup" をクリックすると、システムに ClickPipe が登録され、サマリーテーブルに表示されるようになります。

<Image img="https://mintcdn.com/private-7c7dfe99/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/cp_success.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=ce045b4a85e7f294d23c03897e9ce11f" alt="成功通知" size="sm" border width="613" height="212" data-path="images/integrations/data-ingestion/clickpipes/cp_success.webp" />

<Image img="https://mintcdn.com/private-7c7dfe99/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/cp_remove.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=83b452ee5d8017da1b1c0d50cf8a491d" alt="削除通知" size="lg" border width="2756" height="1320" data-path="images/integrations/data-ingestion/clickpipes/cp_remove.webp" />

サマリーテーブルには、ソースまたは ClickHouse 内の宛先テーブルからサンプルデータを表示するためのコントロールがあります。

<Image img="https://mintcdn.com/private-7c7dfe99/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/cp_destination.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=cb3ebed0c324cb30c6cbf35726b3bec7" alt="宛先を表示" size="lg" border width="2758" height="1316" data-path="images/integrations/data-ingestion/clickpipes/cp_destination.webp" />

また、ClickPipe を削除したり、インジェストジョブの概要を表示したりするためのコントロールもあります。

<Image img="https://mintcdn.com/private-7c7dfe99/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/cp_overview.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=1ce91f5079842cfc66a4c88919f2e061" alt="概要を表示" size="lg" border width="3436" height="1076" data-path="images/integrations/data-ingestion/clickpipes/cp_overview.webp" />

10. **おめでとうございます！** 最初の ClickPipe の設定は正常に完了しました。これが streaming ClickPipe の場合は継続的に動作し、リモートデータソースからデータをリアルタイムで取り込み続けます。それ以外の場合は、バッチを取り込んで完了します。

<div id="supported-data-formats">
  ## 対応データフォーマット
</div>

対応フォーマットは以下のとおりです。

* [JSON](/docs/ja/reference/formats/JSON/JSON)

<div id="compression">
  ## 圧縮
</div>

ClickPipes for Kinesis は、圧縮されたレコードを自動的に検出して解凍します。Kafka ではクライアントライブラリが透過的に解凍を処理しますが、Kinesis は生のバイト列をそのまま配信するため、これは ClickPipes が設定不要で処理します。

サポートされている圧縮コーデックは次のとおりです。

* **gzip**
* **zstd**
* **lz4**
* **snappy** (フレーム形式)

圧縮は、各レコード内のマジックバイトによって自動的に検出されます。既知の圧縮シグネチャが見つからない場合、そのレコードは非圧縮として扱われます。検出された圧縮タイプはスキーマ推論時にも表示されるため、UI のサンプルデータプレビューでも解凍後のデータが正しく表示されます。

<Note>
  この自動検出は、JSON や CSV のようなテキストベースのフォーマットでも安全です。印字可能な ASCII 文字が圧縮のマジックバイトと衝突することはないためです。
</Note>

<div id="supported-data-types">
  ## サポートされているデータ型
</div>

<div id="standard-types-support">
  ### 標準型のサポート
</div>

現在、ClickPipes では以下の ClickHouse データ型がサポートされています。

* 基本的な数値型 - \[U]Int8/16/32/64、Float32/64、BFloat16
* 大きな整数型 - \[U]Int128/256
* Decimal 型
* Boolean
* String
* FixedString
* Date、Date32
* DateTime、DateTime64 (UTC タイムゾーンのみ)
* Enum8/Enum16
* UUID
* IPv4
* IPv6
* すべての ClickHouse LowCardinality 型
* 上記のいずれかの型をキーと値に使用する Map (Nullable を含む)
* 上記のいずれかの型を要素に使用する Tuple および Array (Nullable を含む、深さは 1 レベルのみ)
* SimpleAggregateFunction 型 (AggregatingMergeTree または SummingMergeTree の宛先向け)

<div id="variant-type-support">
  ### Variant 型のサポート
</div>

ソースデータストリーム内の任意の JSON フィールドに対して、Variant 型 (`Variant(String, Int64, DateTime)` など) を手動で指定できます。
ClickPipes では使用する適切な Variant 型を判定する仕組み上、Variant の定義で使用できる整数型または datetime
型は 1 つだけです。たとえば、`Variant(Int64, UInt32)` はサポートされていません。

<div id="json-type-support">
  ### JSON 型のサポート
</div>

常に JSON オブジェクトである JSON フィールドは、JSON の宛先カラムに割り当てることができます。固定パスやスキップするパスも含め、宛先カラムを目的の JSON 型に手動で変更する必要があります。

<div id="kinesis-virtual-columns">
  ## Kinesis 仮想カラム
</div>

Kinesis ストリームでは、以下の仮想カラムをサポートしています。新しい宛先テーブルを作成する際は、`Add Column` ボタンを使って仮想カラムを追加できます。

| Name               | Description                     | Recommended Data Type |
| ------------------ | ------------------------------- | --------------------- |
| \_key              | Kinesis Partition Key           | String                |
| \_timestamp        | Kinesis のおおよその到着タイムスタンプ (ミリ秒精度) | DateTime64(3)         |
| \_stream           | Kinesis Stream Name             | String                |
| \_sequence\_number | Kinesis Sequence Number         | String                |
| \_raw\_message     | Kinesis メッセージ全体                 | String                |

`_raw_message` フィールドは、Kinesis の JSON レコード全体だけが必要な場合に使用できます (たとえば、ClickHouse の [`JsonExtract*`](/docs/ja/reference/functions/regular-functions/json-functions#jsonextract-functions) 関数を使用して、下流の materialized view
ビューにデータを投入する場合) 。このようなパイプでは、「仮想カラムではない」カラムをすべて削除することで、ClickPipes のパフォーマンスが向上する場合があります。

<div id="limitations">
  ## 制限事項
</div>

* [DEFAULT](/docs/ja/reference/statements/create/table#default) はサポートされていません。
* 最小の (XS) レプリカサイズで実行する場合、個々のメッセージの上限はデフォルトで 16MB (非圧縮) 、より大きいレプリカでは 32MB (非圧縮) です。この上限を超えるメッセージは error となり、拒否されます。より大きいメッセージが必要な場合は、サポートにお問い合わせください。

<div id="performance">
  ## パフォーマンス
</div>

<div id="batching">
  ### バッチ処理
</div>

ClickPipes はデータをバッチ単位で ClickHouse に挿入します。これは、データベース内に過剰な数のパーツが作成されるのを防ぎ、クラスターのパフォーマンス低下を避けるためです。

バッチは、次のいずれかの条件を満たした時点で挿入されます。

* バッチサイズが上限に達した場合 (100,000 行、またはレプリカメモリ 1GB あたり 32MB)
* バッチの保持時間が上限に達した場合 (5 秒)

<div id="latency">
  ### レイテンシ
</div>

レイテンシ (Kinesis のメッセージがストリームに送信されてから、そのメッセージを ClickHouse で利用できるようになるまでの時間) は、さまざまな要因 (例: Kinesis のレイテンシ、ネットワークレイテンシ、メッセージのサイズ/フォーマット) に左右されます。上のセクションで説明した[バッチ処理](#batching)も、レイテンシに影響します。実際にどの程度のレイテンシになるかを把握するため、必ずご利用のユースケースに即してテストすることをお勧めします。

低レイテンシに関する特定の要件がある場合は、[お問い合わせください](https://clickhouse.com/company/contact?loc=clickpipes)。

<div id="active-shards">
  ### アクティブな分片
</div>

同時にアクティブにする分片数は、必要なスループットに合わせて制限することを強く推奨します。"On Demand" の Kinesis ストリームでは、AWS がスループットに応じた数の分片を自動的に割り当てますが、
"Provisioned" ストリームでは、後述のとおり、分片を過剰にプロビジョニングすると遅延の原因になるうえ、Kinesis の料金はこの種のストリームでは「分片ごと」に課金されるため、コストも増加します。

プロデューサーアプリケーションが多数のアクティブな分片に継続的に書き込んでいる場合、各分片を効率よく処理できるほどパイプが十分にスケールしていないと、遅延が発生する可能性があります。Kinesis のスループット制限に基づき、
ClickPipes は分片データを読み取るため、レプリカごとに一定数の "workers" を割り当てます。たとえば最小サイズでは、ClickPipes のレプリカにはこのワーカースレッドが 4 つあります。プロデューサーが
同時に 4 つを超える分片に書き込んでいる場合、ワーカースレッドが空くまで、それを超える分片のデータは処理されません。特に、パイプが "enhanced fanout" を使用している場合、各ワーカースレッドは
5 分間 1 つの分片を購読し、その間はほかの分片を読み取れません。その結果、5 分単位で遅延スパイクが発生することがあります。

<div id="scaling">
  ### スケーリング
</div>

ClickPipes for Kinesis は、水平方向と垂直方向の両方にスケールできるよう設計されています。デフォルトでは、1 つのコンシューマーを含むコンシューマグループが作成されます。これは ClickPipe の作成時、または作成後の任意のタイミングで **Settings** -> **Advanced Settings** -> **Scaling** から設定できます。

ClickPipes は、アベイラビリティゾーンに分散されたアーキテクチャによって高可用性を実現します。
そのため、少なくとも 2 つのコンシューマーまでスケールする必要があります。

実行中のコンシューマー数にかかわらず、耐障害性は設計上確保されています。
コンシューマーまたはその基盤となるインフラストラクチャで障害が発生した場合、
ClickPipe は自動的にコンシューマーを再起動し、メッセージの処理を継続します。

<div id="authentication">
  ## 認証
</div>

Amazon Kinesis ストリームにアクセスするには、[IAM認証情報](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html) または [IAM ロール](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html) を使用できます。IAM ロール の設定方法の詳細については、ClickHouse Cloud で利用できるロールの設定手順を説明した[こちらのガイド](/docs/ja/integrations/clickpipes/kinesis/auth)を参照してください
