SuperAPI AI 工具集

connecting-looker-to-bigquery

数据与分析

查看项目

更新于 10-16 00:01

技能介绍

用途:该技能用于在 Looker 中创建到 Google BigQuery 的数据库连接,属于 Looker 开发者入门流程的第 4 步,应在完成第 3 步(CLI 认证)后执行。它采用 Application Default Credentials(ADC),适合运行在 Google Cloud 中的 Looker Core 实例,可避免管理服务账号密钥。

前提条件:已安装并认证 Looker CLI(见 installing-looker-cli 与 authenticating-looker-cli 技能);Looker Core 实例的服务账号需在 BigQuery 项目上具备必要的 IAM 角色。

主要步骤:

  1. 确定 GCP 项目 ID(允许连字符)与 Dataset ID(仅字母数字和下划线,不允许连字符)。
  2. IAM 预检:运行预检脚本检查角色,命令为 ./skills/onboarding-preflight-check/scripts/preflight_check.sh --mode iam --looker-project {looker_gcp_project_id} --bq-project {bigquery_gcp_project_id}。若缺少角色,需为 Looker 服务账号授予 BigQuery Data Viewer、BigQuery Job User 和 Service Usage Consumer 角色。缺少 serviceusage.serviceUsageConsumer 会导致 Looker 无法认证或派发查询任务,出现 400 Bad Request 错误。
  3. 创建连接载荷文件 ./connection_config.json:name 为连接名,dialect_name 为 bigquery_standard_sql,uses_application_default_credentials 为 true,host 设为 GCP 项目 ID,database 与 schema 均设为 Dataset ID。BigQuery JDBC 驱动要求 database 不能设为带连字符的项目 ID,否则查询会立即失败。
  4. 注册连接:运行 looker-cli connection import ./connection_config.json。
  5. 验证连接:运行 looker-cli connection cat {connection_name}。

限制:仅适用于上述前提已满足的场景;需正确配置 IAM 角色与载荷字段,否则连接或查询将失败。其他细节暂未提供。