创建跨云连接

跨云连接是一种 BigQuery 连接,可将 Amazon Web Services (AWS)、Microsoft Azure 和 Salesforce Data 360 中的数据引入 BigQuery 以供查询。这些连接是使用 BigQuery Omni 的标准 BigQuery 连接的替代方案,其中 BigQuery 会将轻量级计算工作器部署到远程区域,以便在不移动任何数据的情况下查询其他云中的数据。

与标准连接相比,工作负载可以从跨云连接中获益,原因如下:

  • 功能一致性。通过将其他云中的数据迁移到 BigQuery,您可以直接使用 BigQuery AI 功能、Gemini Enterprise Agent Platform、具体化视图、用户定义的函数以及其他无法通过标准连接使用的功能。
  • 成本效益。使用跨云连接的工作负载会消耗标准 slot 预留和承诺,因此无需管理单独的计算容量。
  • 智能缓存。在跨云传输数据时,BigQuery 会自动在本地缓存数据片段,从而避免在后续查询中产生高昂的跨云出站流量费用。如需了解详情,请参阅智能缓存

如果您的工作负载涉及 Apache Iceberg 目录,或者您需要在 BigQuery 以外的引擎之间进行查询,请考虑改用无边界湖仓一体的跨云数据访问功能

准备工作

授予为用户提供执行本文档中的每个任务所需权限的 Identity and Access Management 角色和第三方角色。

所需 BigQuery 角色

如需获得创建跨云连接所需的权限,请让您的管理员为您授予项目的 BigQuery Admin (roles/bigquery.admin) IAM 角色。 如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

您也可以通过自定义角色或其他预定义角色来获取所需的权限。

所需的第三方角色

如需获得创建跨云连接所需的权限,请确保您拥有以下第三方角色:

  • 对于 AWS:一个可让您在 AWS 账号中创建 IAM 政策和角色的角色。
  • 对于 Azure:一种可让您在 Microsoft Entra ID (Azure AD) 中管理应用注册并为目标 Azure 账号分配角色(例如 Storage Blob Data Reader)的角色。

创建 AWS 跨云连接

如需创建 AWS 跨云连接,请执行以下操作:

  1. 为 BigQuery 创建 AWS IAM 政策,就像为标准 BigQuery 连接创建政策一样。
  2. 为 BigQuery 创建 AWS IAM 角色,就像为标准 BigQuery 连接创建角色一样。
  3. 如需创建连接资源,请使用 bq mk --connection 命令

    bq mk --connection \
        --connection_type='AWS' \
        --location=LOCATION \
        --project_id=PROJECT_ID \
        --properties='{"accessRole":{"iamRoleId":"arn:aws:iam::AWS_ACCOUNT_ID:role/ROLE_NAME"}}' \
        CONNECTION_ID

    替换以下内容:

    • LOCATION:标准 BigQuery 位置,而非 BigQuery Omni 位置。如需有关选择区域的指导,请参阅区域建议
    • PROJECT_ID:您的 Google Cloud 项目的 ID。
    • AWS_ACCOUNT_ID:上一步中的 AWS IAM 用户的 ID。
    • ROLE_NAME:您选择的 AWS 角色政策名称。
    • CONNECTION_ID:为此连接资源提供的 ID。
  4. 如需记下服务账号信息,请使用 bq show 命令

    bq show --connection \
        --location=LOCATION \
        PROJECT_ID.LOCATION.CONNECTION_ID
  5. 使用服务账号信息为 AWS 角色添加信任政策,就像您为标准 BigQuery 连接添加信任政策一样。

建立 AWS 跨云连接后,您现在可以创建表和数据集来查询远程数据。

AWS 示例

以下示例创建了一个外部表,用于通过跨云连接直接从 Amazon Simple Storage Service (Amazon S3) 存储桶查询 Parquet 文件:

CREATE SCHEMA `my-project.aws_raw_data`
  OPTIONS (
    location = 'us-east4');

CREATE EXTERNAL TABLE `my-project.aws_raw_data.sales_parquet`
WITH CONNECTION `us-east4.my-aws-connection`
  OPTIONS (
    format = 'PARQUET',
    uris = ['s3://my-data-bucket/sales/year=2025/*']);

以下示例使用 AWS Glue 通过跨云连接将整个数据库联合到 BigQuery 中:

CREATE EXTERNAL SCHEMA `my-project.aws_glue_data`
WITH CONNECTION `us-east4.my-aws-connection`
  OPTIONS (
    location = 'us-east4',
    external_source = 'aws-glue://arn:aws:glue:us-east-4:123456789:database/test_database');

如需详细了解 AWS Glue 联合,请参阅创建和管理 AWS Glue 联合数据集

创建 Azure 跨云连接

如需创建 Azure 跨云连接,请执行以下操作:

  1. 在 Azure 租户中创建应用,就像创建标准 BigQuery 连接一样,并记下应用(客户端)ID 和目录(租户)ID。
  2. 为 Azure 应用分配角色,就像为标准 BigQuery 连接分配角色一样。
  3. 如需创建连接资源,请使用 bq mk --connection 命令

    bq mk --connection \
        --connection_type='Azure' \
        --tenant_id=TENANT_ID \
        --location=LOCATION \
        --federated_azure=true \
        --federated_app_client_id=APP_ID \
        --project_id=PROJECT_ID \
        CONNECTION_ID

    替换以下内容:

    • TENANT_ID:包含 Azure 账号的 Azure 目录的租户 ID。
    • LOCATION:标准 BigQuery 位置,而非 BigQuery Omni 位置。如需有关选择区域的指导,请参阅区域建议
    • APP_ID:Azure 应用(客户端)ID。
    • PROJECT_ID:您的 Google Cloud 项目的 ID。
    • CONNECTION_ID:为此连接资源提供的 ID。
  4. 如需记下服务账号信息,请使用 bq show 命令

    bq show --connection \
        --location=LOCATION \
        PROJECT_ID.LOCATION.CONNECTION_ID
  5. 使用服务账号信息添加联合凭据,就像添加标准 BigQuery 连接一样。

建立 Azure 跨云连接后,您现在可以创建表和数据集来查询远程数据。

Azure 示例

以下示例创建了一个外部表,用于通过跨云连接直接从 Azure Blob Storage 容器查询 Parquet 文件:

CREATE SCHEMA `my-project.azure_raw_data`
  OPTIONS (
    location = 'us-east4');

CREATE EXTERNAL TABLE `my-project.azure_raw_data.sales_parquet`
WITH CONNECTION `us-east4.my-azure-connection`
  OPTIONS (
    format = 'PARQUET',
    uris = ['azure://mystorageaccount.blob.core.windows.net/mycontainer/sales/year=2025/*']);

以下示例创建了一个外部表,用于通过跨云连接查询 Blob Storage 容器中的原始 CSV 导出数据:

CREATE EXTERNAL TABLE `my-project.azure_raw_data.daily_logs_csv`
WITH CONNECTION `us-east4.my-azure-connection`
  OPTIONS (
    format = 'CSV',
    skip_leading_rows = 1,
    uris = ['azure://mystorageaccount.blob.core.windows.net/mycontainer/logs/*.csv']);

创建 Data 360 跨云连接

如需创建 Data 360 跨云连接,请按照将 Data 360 数据集关联到 BigQuery 的步骤操作,但不要在 BigQuery Omni 位置创建关联的数据集,而是在标准 BigQuery 位置创建。如需有关选择区域的指导,请参阅区域建议

更新查询以使用新数据集后,您可以删除所有旧版关联数据集和 BigQuery Omni 具体化视图。

区域建议

为跨云连接选择标准 BigQuery 区域时,请选择在地理位置上最接近您的数据的区域,以实现最佳的成本和性能效率。

下表列出了 AWS 区域以及最适合的相应 BigQuery 区域:

AWS 区域 最近的 BigQuery 区域 其他邻近的 BigQuery 区域
us-east-1 us-east4 us-east1
us-east5
us-central1
us-east-2 us-east5 us-east4
us-east1
us-central1
us-west-1 us-west2 us-west4
us-west1
us-west3
us-west-2 us-west1 us-west3
us-west4
us-west2
ca-central-1 northamerica-northeast1 northamerica-northeast2
us-east4
us-east5
sa-east-1 southamerica-east1 southamerica-west1
us-east1
us-south1
eu-west-1 europe-west1 europe-west2
europe-west9
europe-west4
eu-west-2 europe-west2 europe-west1
europe-west9
europe-west4
eu-west-3 europe-west9 europe-west1
europe-west2
europe-west3
eu-central-1 europe-west3 europe-west4
europe-west1
europe-west6
eu-central-2 europe-west6 europe-west8
europe-west12
europe-west3
eu-north-1 europe-north1 europe-west4
europe-central2
europe-west1
eu-south-1 europe-west8 europe-west12
europe-west6
europe-west3
eu-south-2 europe-southwest1 europe-west9
europe-west1
europe-west8
me-central-1 me-central1 me-central2
me-west1
asia-south1
me-south-1 me-central2 me-central1
me-west1
asia-south1
af-south-1 europe-southwest1 me-central2
me-west1
europe-west1
ap-east-1 asia-east2 asia-east1
asia-southeast1
asia-northeast1
ap-northeast-1 asia-northeast1 asia-northeast2
asia-northeast3
asia-east1
ap-northeast-2 asia-northeast3 asia-northeast2
asia-northeast1
asia-east1
ap-northeast-3 asia-northeast2 asia-northeast1
asia-northeast3
asia-east1
ap-south-1 asia-south1 asia-south2
me-central1
asia-southeast1
ap-south-2 asia-south2 asia-south1
asia-southeast1
me-central1
ap-southeast-1 asia-southeast1 asia-southeast2
asia-east1
asia-south1
ap-southeast-2 australia-southeast1 australia-southeast2
asia-southeast2
asia-southeast1
ap-southeast-3 asia-southeast2 asia-southeast1
australia-southeast1
asia-east1

下表列出了 Azure 区域以及最适合的相应 BigQuery 区域:

Azure 区域 最近的 BigQuery 区域 其他邻近的 BigQuery 区域
美国东部 us-east4 us-east1
us-east5
us-central1
美国东部 2 us-east4 us-east1
us-east5
us-south1
美国西部 us-west1 us-west2
us-west3
us-west4
美国西部 2 us-west1 us-west4
us-west3
us-west2
美国西部 3 us-west4 us-west2
us-west3
us-west1
美国中部 us-central1 us-east5
us-east4
us-east1
美国中北部 us-east5 us-central1
us-east4
us-east1
美国中南部 us-south1 us-east5
us-central1
us-east1
美国中西部 us-west3 us-central1
us-west4
us-west2
加拿大中部 northamerica-northeast2 northamerica-northeast1
us-east5
us-east4
加拿大东部 northamerica-northeast1 northamerica-northeast2
us-east4
us-east5
西欧 europe-west4 europe-west1
europe-west3
europe-west9
北欧 europe-west1 europe-west2
europe-west9
europe-west4
法国中部 europe-west9 europe-west1
europe-west2
europe-west3
法国南部 europe-west9 europe-southwest1
europe-west8
europe-west1
德国中西部 europe-west3 europe-west4
europe-west1
europe-west6
德国北部 europe-west3 europe-west4
europe-central2
europe-west2
瑞士北部 europe-west6 europe-west8
europe-west12
europe-west3
瑞士西部 europe-west6 europe-west9
europe-west8
europe-west3
英国南部 europe-west2 europe-west1
europe-west9
europe-west4
英国西部 europe-west2 europe-west1
europe-west9
europe-west4
挪威东部 europe-north1 europe-west4
europe-central2
europe-west1
挪威西部 europe-north1 europe-west4
europe-central2
europe-west1
瑞典中部 europe-north1 europe-west4
europe-central2
europe-west1
东亚 asia-east2 asia-east1
asia-southeast1
asia-northeast1
东南亚 asia-southeast1 asia-southeast2
asia-east1
asia-south1
日本东部 asia-northeast1 asia-northeast2
asia-northeast3
asia-east1
日本西部 asia-northeast2 asia-northeast1
asia-northeast3
asia-east1
韩国中部 asia-northeast3 asia-northeast2
asia-northeast1
asia-east1
澳大利亚东部 australia-southeast1 australia-southeast2
asia-southeast2
asia-southeast1
澳大利亚东南部 australia-southeast2 australia-southeast1
asia-southeast1
asia-east1
澳大利亚中部 australia-southeast1 australia-southeast2
asia-southeast2
asia-southeast1
印度西部 asia-south1 asia-south2
me-central1
asia-southeast1
印度中部 asia-south1 asia-south2
me-central1
asia-southeast1
印度南部 asia-south1 asia-south2
asia-southeast1
me-central1

后续步骤