> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-3a82795f.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 通过 Airbyte 数据管道将流数据导入 ClickHouse

# 将 Airbyte 连接到 ClickHouse

export const PartnerBadge = () => {
  return <div className="PartnerBadge">
            <div className="PartnerBadgeIcon">
                <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <polyline points="12.5 9.5 10 12 6 11 2.5 8.5" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1" />
                    <polyline points="4.54 4.41 8 3.5 11.46 4.41" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1" />
                    <path d="M2.15,3.78 L0.55,6.95 A0.5,0.5 0,0,0 0.77,7.62 L2.5,8.5 L4.54,4.41 L2.82,3.55 A0.5,0.5 0,0,0 2.15,3.78 Z" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1" />
                    <path d="M13.5,8.5 L15.23,7.62 A0.5,0.5 0,0,0 15.45,6.95 L13.85,3.78 A0.5,0.5 0,0,0 13.18,3.55 L11.46,4.41 Z" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1" />
                    <path d="M11.5,4.5 L9,4.5 L6.15,7.27 A0.5,0.5 0,0,0 6.24,8.05 C7.33,8.74 8.81,8.72 10,7.5 L12.5,9.5 L13.5,8.5" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1" />
                    <polyline points="7.75 13.5 5.15 12.85 3.5 11.67" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1" />
                </svg>
            </div>
            Partner Integration
        </div>;
};

export const Image = ({img, alt, size}) => {
  return <Frame>
      <img src={img} alt={alt} />
    </Frame>;
};

<Note>
  请注意，Airbyte 面向 ClickHouse 的 source 和目标端目前处于 Alpha 状态，不适合移动大型数据集 (> 1000 万行) 。
</Note>

<a href="https://www.airbyte.com/" target="_blank">Airbyte</a> 是一个开源数据集成平台，支持创建 <a href="https://airbyte.com/blog/why-the-future-of-etl-is-not-elt-but-el" target="_blank">ELT</a> 数据管道，并开箱即用地提供 140 多个 connector。本分步教程将介绍如何将 Airbyte 连接到 ClickHouse 作为目标端，并加载一个样本数据集。

<Steps>
  <Step>
    ## 下载并运行 Airbyte

    1. Airbyte 运行在 Docker 上，并使用 `docker-compose`。请确保下载并安装最新版 Docker。

    2. 通过克隆官方 GitHub 仓库，并在你常用的终端中运行 `docker-compose up` 来部署 Airbyte：

       ```bash theme={null}
       git clone https://github.com/airbytehq/airbyte.git --depth=1
       cd airbyte
       ./run-ab-platform.sh
       ```

    3. 当你在终端中看到 Airbyte 标识后，即可连接到 <a href="http://localhost:8000" target="_blank">localhost:8000</a>

           <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/5--Fjp5JBoBextmb/images/integrations/data-ingestion/etl-tools/airbyte_01.png?fit=max&auto=format&n=5--Fjp5JBoBextmb&q=85&s=4766f338c2532fd0cdfd3361127799d9" size="lg" border alt="Airbyte 标识" width="1400" height="386" data-path="images/integrations/data-ingestion/etl-tools/airbyte_01.png" />

    <Note>
      或者，你也可以注册并使用 <a href="https://docs.airbyte.com/deploying-airbyte/on-cloud" target="_blank">Airbyte Cloud</a>
    </Note>
  </Step>

  <Step>
    ## 将 ClickHouse 添加为目标端

    在本节中，我们将演示如何将 ClickHouse 实例添加为目标端。

    1. 启动 ClickHouse server (Airbyte 与 `21.8.10.19` 或更高版本的 ClickHouse 兼容) ，或登录你的 ClickHouse Cloud 账户：

       ```bash theme={null}
       clickhouse-server start
       ```

    2. 在 Airbyte 中，选择 "Destinations" 页面并添加新的目标端：

           <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/5--Fjp5JBoBextmb/images/integrations/data-ingestion/etl-tools/airbyte_02.png?fit=max&auto=format&n=5--Fjp5JBoBextmb&q=85&s=4dc13879fadac29fcadcc1ff1dff2fc4" size="lg" border alt="在 Airbyte 中添加目标端" width="1132" height="896" data-path="images/integrations/data-ingestion/etl-tools/airbyte_02.png" />

    3. 在 "Destination type" 下拉列表中选择 ClickHouse，然后填写 "Set up the destination" 表单，提供 ClickHouse 主机名和端口、数据库名称、用户名和密码，并选择是否使用 SSL 连接 (相当于 `clickhouse-client` 中的 `--secure` 标志) ：

           <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/5--Fjp5JBoBextmb/images/integrations/data-ingestion/etl-tools/airbyte_03.png?fit=max&auto=format&n=5--Fjp5JBoBextmb&q=85&s=83e5b30479f48acb8da994c5f4a39f45" size="lg" border alt="在 Airbyte 中创建 ClickHouse 目标端" width="807" height="1050" data-path="images/integrations/data-ingestion/etl-tools/airbyte_03.png" />

    4. 恭喜！你现在已经在 Airbyte 中将 ClickHouse 添加为目标端。

    <Note>
      要将 ClickHouse 用作目标端，你使用的用户需要具备创建数据库、表以及插入行的权限。我们建议为 Airbyte 创建一个专用用户 (例如 `my_airbyte_user`) ，并授予以下权限：

      ```sql theme={null}
      CREATE USER 'my_airbyte_user'@'%' IDENTIFIED BY 'your_password_here';

      GRANT CREATE ON * TO my_airbyte_user;
      ```
    </Note>
  </Step>

  <Step>
    ## 将数据集添加为数据源

    我们将使用的示例数据集是 <a href="/zh/get-started/sample-datasets/nyc-taxi" target="_blank">纽约市出租车数据</a> (位于 <a href="https://github.com/toddwschneider/nyc-taxi-data" target="_blank">GitHub</a>) 。在本教程中，我们将使用该数据集的一个子集，即 2022 年 1 月的数据。

    1. 在 Airbyte 中，选择 "Sources" 页面，并添加一个新的文件类型数据源。

           <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/5--Fjp5JBoBextmb/images/integrations/data-ingestion/etl-tools/airbyte_04.png?fit=max&auto=format&n=5--Fjp5JBoBextmb&q=85&s=24cb207674747e0804776820640c1af0" size="lg" border alt="在 Airbyte 中添加数据源" width="2034" height="1014" data-path="images/integrations/data-ingestion/etl-tools/airbyte_04.png" />

    2. 填写 "Set up the source" 表单，为数据源命名，并提供 NYC Taxi 2022 年 1 月文件的 URL (见下文) 。请务必选择 `parquet` 作为文件格式，`HTTPS Public Web` 作为存储提供商，以及 `nyc_taxi_2022` 作为数据集名称。

       ```text theme={null}
       https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2022-01.parquet
       ```

           <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/5--Fjp5JBoBextmb/images/integrations/data-ingestion/etl-tools/airbyte_05.png?fit=max&auto=format&n=5--Fjp5JBoBextmb&q=85&s=cbb1f103bcfb3b93916b05420de1e2cc" size="lg" border alt="在 Airbyte 中创建 ClickHouse 数据源" width="803" height="926" data-path="images/integrations/data-ingestion/etl-tools/airbyte_05.png" />

    3. 恭喜！你现在已经在 Airbyte 中添加了一个文件数据源。
  </Step>

  <Step>
    ## 创建连接并将数据集加载到 ClickHouse

    1. 在 Airbyte 中，选择 "连接" 页面并新增一个连接

    <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/5--Fjp5JBoBextmb/images/integrations/data-ingestion/etl-tools/airbyte_06.png?fit=max&auto=format&n=5--Fjp5JBoBextmb&q=85&s=edc388ad9fa83a9759ab050371801021" size="lg" border alt="在 Airbyte 中新增连接" width="1664" height="952" data-path="images/integrations/data-ingestion/etl-tools/airbyte_06.png" />

    2. 选择 "使用现有 source"，并选择 New York City Taxi Data；然后选择 "使用现有目标端"，并选择你的 ClickHouse 实例。

    3. 在 "设置连接" 表单中，选择复制频率 (本教程中我们将使用 `manual`) ，并将 `nyc_taxi_2022` 选为要同步的 stream。请确保归一化方式选择 `归一化表格数据`。

    <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/5--Fjp5JBoBextmb/images/integrations/data-ingestion/etl-tools/airbyte_07.png?fit=max&auto=format&n=5--Fjp5JBoBextmb&q=85&s=ea8756b358daadf2f2f1e9079f69a482" size="lg" border alt="在 Airbyte 中创建连接" width="1158" height="1265" data-path="images/integrations/data-ingestion/etl-tools/airbyte_07.png" />

    4. 现在连接已创建，点击 "立即同步" 以开始加载数据 (因为我们将复制频率设为 `Manual`)

    <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/5--Fjp5JBoBextmb/images/integrations/data-ingestion/etl-tools/airbyte_08.png?fit=max&auto=format&n=5--Fjp5JBoBextmb&q=85&s=e1742971dcda27c3b861616bff71ca5d" size="lg" border alt="立即在 Airbyte 中同步" width="2064" height="384" data-path="images/integrations/data-ingestion/etl-tools/airbyte_08.png" />

    5. 数据将开始加载，你可以展开视图查看 Airbyte 日志和进度。操作完成后，你会在日志中看到一条 `Completed successfully` 消息：

    <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/5--Fjp5JBoBextmb/images/integrations/data-ingestion/etl-tools/airbyte_09.png?fit=max&auto=format&n=5--Fjp5JBoBextmb&q=85&s=9b1f3b8a6e482e7f989d4da71fb004aa" size="lg" border alt="已成功完成" width="2457" height="839" data-path="images/integrations/data-ingestion/etl-tools/airbyte_09.png" />

    6. 使用您常用的 SQL 客户端连接到您的 ClickHouse 实例，并检查生成的表：

       ```sql theme={null}
       SELECT *
       FROM nyc_taxi_2022
       LIMIT 10
       ```

       响应应如下所示：

       ```response theme={null}
       Query id: 4f79c106-fe49-4145-8eba-15e1cb36d325

       ┌─extra─┬─mta_tax─┬─VendorID─┬─RatecodeID─┬─tip_amount─┬─airport_fee─┬─fare_amount─┬─DOLocationID─┬─PULocationID─┬─payment_type─┬─tolls_amount─┬─total_amount─┬─trip_distance─┬─passenger_count─┬─store_and_fwd_flag─┬─congestion_surcharge─┬─tpep_pickup_datetime─┬─improvement_surcharge─┬─tpep_dropoff_datetime─┬─_airbyte_ab_id───────────────────────┬─────_airbyte_emitted_at─┬─_airbyte_normalized_at─┬─_airbyte_nyc_taxi_2022_hashid────┐
       │     0 │     0.5 │        2 │          1 │       2.03 │           0 │          17 │           41 │          162 │            1 │            0 │        22.33 │          4.25 │               3 │ N                  │                  2.5 │ 2022-01-24T16:02:27  │                   0.3 │ 2022-01-24T16:22:23   │ 000022a5-3f14-4217-9938-5657f9041c8a │ 2022-07-19 04:35:31.000 │    2022-07-19 04:39:20 │ 91F83E2A3AF3CA79E27BD5019FA7EC94 │
       │     3 │     0.5 │        1 │          1 │       1.75 │           0 │           5 │          186 │          246 │            1 │            0 │        10.55 │           0.9 │               1 │ N                  │                  2.5 │ 2022-01-22T23:23:05  │                   0.3 │ 2022-01-22T23:27:03   │ 000036b6-1c6a-493b-b585-4713e433b9cd │ 2022-07-19 04:34:53.000 │    2022-07-19 04:39:20 │ 5522F328014A7234E23F9FC5FA78FA66 │
       │     0 │     0.5 │        2 │          1 │       7.62 │        1.25 │          27 │          238 │           70 │            1 │         6.55 │        45.72 │          9.16 │               1 │ N                  │                  2.5 │ 2022-01-22T19:20:37  │                   0.3 │ 2022-01-22T19:40:51   │ 00003c6d-78ad-4288-a79d-00a62d3ca3c5 │ 2022-07-19 04:34:46.000 │    2022-07-19 04:39:20 │ 449743975782E613109CEE448AFA0AB3 │
       │   0.5 │     0.5 │        2 │          1 │          0 │           0 │         9.5 │          234 │          249 │            1 │            0 │         13.3 │           1.5 │               1 │ N                  │                  2.5 │ 2022-01-22T20:13:39  │                   0.3 │ 2022-01-22T20:26:40   │ 000042f6-6f61-498b-85b9-989eaf8b264b │ 2022-07-19 04:34:47.000 │    2022-07-19 04:39:20 │ 01771AF57922D1279096E5FFE1BD104A │
       │     0 │       0 │        2 │          5 │          5 │           0 │          60 │          265 │           90 │            1 │            0 │         65.3 │          5.59 │               1 │ N                  │                    0 │ 2022-01-25T09:28:36  │                   0.3 │ 2022-01-25T09:47:16   │ 00004c25-53a4-4cd4-b012-a34dbc128aeb │ 2022-07-19 04:35:46.000 │    2022-07-19 04:39:20 │ CDA4831B683D10A7770EB492CC772029 │
       │     0 │     0.5 │        2 │          1 │          0 │           0 │        11.5 │           68 │          170 │            2 │            0 │         14.8 │           2.2 │               1 │ N                  │                  2.5 │ 2022-01-25T13:19:26  │                   0.3 │ 2022-01-25T13:36:19   │ 00005c75-c3c8-440c-a8e8-b1bd2b7b7425 │ 2022-07-19 04:35:52.000 │    2022-07-19 04:39:20 │ 24D75D8AADD488840D78EA658EBDFB41 │
       │   2.5 │     0.5 │        1 │          1 │       0.88 │           0 │         5.5 │           79 │          137 │            1 │            0 │         9.68 │           1.1 │               1 │ N                  │                  2.5 │ 2022-01-22T15:45:09  │                   0.3 │ 2022-01-22T15:50:16   │ 0000acc3-e64f-4b58-8e15-dc47ff1685f3 │ 2022-07-19 04:34:37.000 │    2022-07-19 04:39:20 │ 2BB5B8E849A438E08F7FCF789E7D7E65 │
       │  1.75 │     0.5 │        1 │          1 │        7.5 │        1.25 │        27.5 │           17 │          138 │            1 │            0 │        37.55 │             9 │               1 │ N                  │                    0 │ 2022-01-30T21:58:19  │                   0.3 │ 2022-01-30T22:19:30   │ 0000b339-b44b-40b0-99f8-ebbf2092cc5b │ 2022-07-19 04:38:10.000 │    2022-07-19 04:39:20 │ DCCE79199EF9217CD769EFD5271302FE │
       │   0.5 │     0.5 │        2 │          1 │          0 │           0 │          13 │           79 │          140 │            2 │            0 │         16.8 │          3.19 │               1 │ N                  │                  2.5 │ 2022-01-26T20:43:14  │                   0.3 │ 2022-01-26T20:58:08   │ 0000caa8-d46a-4682-bd25-38b2b0b9300b │ 2022-07-19 04:36:36.000 │    2022-07-19 04:39:20 │ F502BE51809AF36582561B2D037B4DDC │
       │     0 │     0.5 │        2 │          1 │       1.76 │           0 │         5.5 │          141 │          237 │            1 │            0 │        10.56 │          0.72 │               2 │ N                  │                  2.5 │ 2022-01-27T15:19:54  │                   0.3 │ 2022-01-27T15:26:23   │ 0000cd63-c71f-4eb9-9c27-09f402fddc76 │ 2022-07-19 04:36:55.000 │    2022-07-19 04:39:20 │ 8612CDB63E13D70C1D8B34351A7CA00D │
       └───────┴─────────┴──────────┴────────────┴────────────┴─────────────┴─────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴───────────────┴─────────────────┴────────────────────┴──────────────────────┴──────────────────────┴───────────────────────┴───────────────────────┴──────────────────────────────────────┴─────────────────────────┴────────────────────────┴──────────────────────────────────┘
       ```

       ```sql theme={null}
       SELECT count(*)
       FROM nyc_taxi_2022
       ```

       响应如下：

       ```response theme={null}
       Query id: a9172d39-50f7-421e-8330-296de0baa67e

       ┌─count()─┐
       │ 2392428 │
       └─────────┘
       ```

    7. 请注意，Airbyte 会自动推断数据类型，并向目标表添加 4 列。这些列由 Airbyte 用于管理复制逻辑和记录操作。更多详情请参阅 <a href="https://docs.airbyte.com/integrations/destinations/clickhouse#output-schema" target="_blank">Airbyte 官方文档</a>。

       ```sql theme={null}
           `_airbyte_ab_id` String,
           `_airbyte_emitted_at` DateTime64(3, 'GMT'),
           `_airbyte_normalized_at` DateTime,
           `_airbyte_nyc_taxi_072021_hashid` String
       ```

       现在数据集已加载到您的 ClickHouse 实例中，您可以创建一个新表，并使用更合适的 ClickHouse 数据类型 (<a href="/zh/get-started/sample-datasets/nyc-taxi" target="_blank">详见此处</a>) 。

    8. 恭喜——你已成功通过 Airbyte 将纽约市出租车数据加载到 ClickHouse 中！
  </Step>
</Steps>
