> ## 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.

> 分步指导您创建首个 BigQuery ClickPipe。

# 创建您的首个 BigQuery ClickPipe

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>;
};

export const PrivatePreviewBadge = () => {
  return <div className="privatePreviewBadge">
            <div className="privatePreviewIcon">
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M5.33301 6.66667V4.66667V4.66667C5.33301 3.194 6.52701 2 7.99967 2V2C9.47234 2 10.6663 3.194 10.6663 4.66667V4.66667V6.66667" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
                <path d="M8.00033 9.33337V11.3334" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
                <path fillRule="evenodd" clipRule="evenodd" d="M11.333 14H4.66634C3.92967 14 3.33301 13.4033 3.33301 12.6666V7.99996C3.33301 7.26329 3.92967 6.66663 4.66634 6.66663H11.333C12.0697 6.66663 12.6663 7.26329 12.6663 7.99996V12.6666C12.6663 13.4033 12.0697 14 11.333 14Z" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
            </svg>
        </div>
            {'ClickHouse Cloud 私有预览'}
        </div>;
};

<PrivatePreviewBadge />

<Note>
  你可以在[这里](https://clickhouse.com/cloud/clickpipes/bigquery-connector)加入私有预览候补名单。
</Note>

BigQuery ClickPipe 提供了一种完全托管且具备高弹性的方式，可将 BigQuery 中的数据摄取到 ClickHouse Cloud。在私有预览阶段，它支持 **initial load** 复制方法，帮助你批量加载 BigQuery 数据集，以便进行探索和原型验证。未来将支持 **CDC (变更数据捕获) **；在此之前，我们建议你在 initial load 完成后，使用 [Google Cloud Storage ClickPipe](/docs/zh/integrations/clickpipes/object-storage/google-cloud-storage/overview) 持续将 BigQuery 导出的数据同步到 ClickHouse Cloud。

BigQuery ClickPipes 既可通过 ClickPipes UI 手动部署和管理，也可通过 [OpenAPI](/docs/zh/integrations/clickpipes/programmatic-access/openapi) 和 [Terraform](/docs/zh/integrations/clickpipes/programmatic-access/terraform) 以编程方式进行部署和管理。

<div id="pre-requisites">
  ## 前提条件
</div>

* 您必须具备在 GCP 项目中管理[服务账号](https://docs.cloud.google.com/iam/docs/service-account-overview)和 [IAM roles](https://docs.cloud.google.com/iam/docs/roles-overview) 的权限，或者获得管理员协助。我们建议按照[官方文档](https://docs.cloud.google.com/iam/docs/service-accounts-create)创建一个专用服务账号，并仅授予所需的最小[权限](/docs/zh/integrations/clickpipes/bigquery/overview#permissions)。

* 初始加载过程需要用户提供一个 Google Cloud Storage (GCS) 存储桶用于暂存。我们建议按照[官方文档](https://docs.cloud.google.com/storage/docs/creating-buckets)为您的 ClickPipe 创建一个专用存储桶。未来，该中间存储桶将由 ClickPipes 提供并管理。

<Steps>
  <Step title="选择数据源" id="1-select-the-data-source">
    **1.** 在 ClickHouse Cloud 中，从主导航菜单选择 **Data sources** 并点击 **Create ClickPipe**。

    <Image img="https://mintcdn.com/private-7c7dfe99/KW34O4k4cC0oxlHH/images/integrations/data-ingestion/clickpipes/cp_step0.webp?fit=max&auto=format&n=KW34O4k4cC0oxlHH&q=85&s=9e134912809363f85f1602e2f744c872" alt="选择导入" size="lg" border width="2606" height="790" data-path="images/integrations/data-ingestion/clickpipes/cp_step0.webp" />

    **2.** 点击 **BigQuery** 磁贴。

    <Image img="https://mintcdn.com/private-7c7dfe99/KW34O4k4cC0oxlHH/images/integrations/data-ingestion/clickpipes/bigquery/cp_step1.webp?fit=max&auto=format&n=KW34O4k4cC0oxlHH&q=85&s=1081b114565469e0f122329bd8272297" alt="选择 BigQuery 磁贴" size="lg" border width="2680" height="1070" data-path="images/integrations/data-ingestion/clickpipes/bigquery/cp_step1.webp" />
  </Step>

  <Step title="设置你的 ClickPipe 连接" id="2-setup-your-clickpipe-connection">
    要设置新的 ClickPipe，你必须提供如何连接和验证你的 BigQuery 数据仓库的详细信息，以及一个用于暂存的 GCS 存储桶。

    **1.** 上传为 ClickPipes 创建的服务账号的 `.json` 密钥。确保该服务账号具有最小所需的 [权限](/docs/zh/integrations/clickpipes/bigquery/overview#permissions)。

    <Image img="https://mintcdn.com/private-7c7dfe99/KW34O4k4cC0oxlHH/images/integrations/data-ingestion/clickpipes/bigquery/cp_step2.webp?fit=max&auto=format&n=KW34O4k4cC0oxlHH&q=85&s=3f2a10e5650f1482dff72b0c2392f22c" alt="上传服务账号密钥" size="lg" border width="2684" height="926" data-path="images/integrations/data-ingestion/clickpipes/bigquery/cp_step2.webp" />

    **2.** 选择 **Replication method**。在 Private Preview 中，当前唯一支持的选项是 [**仅初始加载**](/docs/zh/integrations/clickpipes/bigquery/overview#initial-load)。

    **3.** 提供用于初始加载期间暂存数据的 GCS 存储桶路径。

    **4.** 点击 **Next** 以进行验证。
  </Step>

  <Step title="配置你的 ClickPipe" id="3-configure-your-clickpipe">
    根据你的 BigQuery 数据集的大小，或你想要同步的表的总大小，你可能需要调整 ClickPipe 的默认摄取设置。
  </Step>

  <Step title="配置表" id="4-configure-tables">
    **1.** 选择要将 BigQuery 表复制到的 ClickHouse 数据库。你可以选择现有数据库或创建新的数据库。

    **2.** 选择要复制的表以及 (可选) 要复制的列。只有提供的服务账号有权访问的数据集才会被列出。

    <Image img="https://mintcdn.com/private-7c7dfe99/KW34O4k4cC0oxlHH/images/integrations/data-ingestion/clickpipes/bigquery/cp_step3.webp?fit=max&auto=format&n=KW34O4k4cC0oxlHH&q=85&s=091e0b32f9d5db458260957c136068c3" alt="权限" size="lg" border width="2682" height="1430" data-path="images/integrations/data-ingestion/clickpipes/bigquery/cp_step3.webp" />

    **3.** 对于每个选定的表，请务必在 **Advanced settings** > **Use a custom sorting key** 下定义自定义排序键。将来，排序键会根据上游数据库中现有的聚类或分区键自动推断。

    <Warning>
      你**必须**为被复制的表定义 [排序键](/docs/zh/concepts/best-practices/choosing-a-primary-key)，以优化 ClickHouse 中的查询性能。否则，排序键将被设置为 `tuple()`，这意味着不会创建主索引，ClickHouse 将对该表上的所有查询执行全表扫描。
    </Warning>

    <Image img="https://mintcdn.com/private-7c7dfe99/KW34O4k4cC0oxlHH/images/integrations/data-ingestion/clickpipes/bigquery/cp_step4.webp?fit=max&auto=format&n=KW34O4k4cC0oxlHH&q=85&s=0d18650de38d0ee1a95a4523049eaf21" alt="权限" size="lg" border width="2676" height="854" data-path="images/integrations/data-ingestion/clickpipes/bigquery/cp_step4.webp" />
  </Step>

  <Step title="配置权限" id="6-configure-permissions">
    最后，你可以为内部 ClickPipes 用户配置权限。

    **Permissions:** ClickPipes 将创建一个专用用户用于将数据写入目标表。你可以为该内部用户选择自定义角色或以下预定义角色之一：

    * `Full access`: 对集群具有完全访问权限。如果你在目标表上使用 materialized views 或 dictionary，则需要此权限。
    * `Only destination`: 仅对目标表具有插入权限。
  </Step>

  <Step title="完成设置" id="7-complete-setup">
    点击 **Create ClickPipe** 完成设置。你将被重定向到概览页面，在那里可以查看初始加载的进度并点击查看你的 BigQuery ClickPipes 的详细信息。

    <Image img="https://mintcdn.com/private-7c7dfe99/KW34O4k4cC0oxlHH/images/integrations/data-ingestion/clickpipes/bigquery/cp_step5.webp?fit=max&auto=format&n=KW34O4k4cC0oxlHH&q=85&s=7277e240df65a4552486ade8cc8a5c02" alt="权限" size="lg" border width="2682" height="918" data-path="images/integrations/data-ingestion/clickpipes/bigquery/cp_step5.webp" />
  </Step>
</Steps>
