本页介绍了如何针对 Conversational Analytics API 进行身份验证。本文还介绍了如何使用直接 HTTP 请求或 SDK 在 Looker、BigQuery、数据洞察 和 Cloud Databases(AlloyDB、GoogleSQL for Spanner、Cloud SQL for MySQL 和 Cloud SQL for PostgreSQL)中配置与数据的连接。Conversational Analytics API 使用标准的 Google Cloud 身份验证方法。
准备工作
在向 Conversational Analytics API 进行身份验证并配置与数据的连接之前,您必须满足前提条件并为 Google Cloud 项目启用所需的 API,如启用 Conversational Analytics API 中所述。
如果您计划在 Looker 数据源中使用客户管理的加密密钥 (CMEK) 来保护 Conversational Analytics API 资源,则必须向该 API 的服务账号授予使用 Cloud Key Management Service 密钥的权限。如需了解详情,请参阅 CMEK 文档中的准备工作。
针对 Conversational Analytics API 进行身份验证
本部分介绍了如何使用 HTTP 和 Python 方法获取必要的授权令牌,以便向 Conversational Analytics API 进行身份验证。以下示例使用基于资源位置的区域端点逻辑。如需详细了解区域级端点,请参阅数据驻留。
HTTP curl
以下示例 curl 命令会通过指定您所在位置的相应端点网址向 Conversational Analytics API 发送请求:
curl -H "Authorization: Bearer $(gcloud auth print-identity-token)" \
https://ENDPOINT_URL/PATH
按如下所示替换示例值:
- ENDPOINT_URL:与您的位置对应的服务端点,例如
global的geminidataanalytics.googleapis.com或us的geminidataanalytics.us.rep.googleapis.com。 - PATH:相应的资源路径,例如
v1/projects/PROJECT_ID/locations/LOCATION/dataAgents。
使用 Python 进行 HTTP 通信
以下 Python 代码示例演示了如何使用 Google Cloud CLI 和 Python 获取访问令牌以授权 HTTP 请求。该代码会根据指定的位置类型动态构建端点网址。
billing_project = 'PROJECT_ID'
location = 'LOCATION'
access_token = !gcloud auth application-default print-access-token
# Set the base URL based on location.
if not location or location == "global":
base_url = "https://geminidataanalytics.googleapis.com"
elif "-" in location:
# Regional endpoints
base_url = f"https://geminidataanalytics-{location}.googleapis.com"
else:
# Multi-regional endpoints
base_url = f"https://geminidataanalytics.{location}.rep.googleapis.com"
url = f"{base_url}/v1/projects/{billing_project}/locations/{location}METHOD"
headers = {"Authorization": f'Bearer {access_token[0]}'}
按如下所示替换示例值:
- PROJECT_ID:已启用所需 API 的结算项目的 ID。
- LOCATION:资源存储的位置,例如
global或us-east4。 - METHOD:目标端点方法或资源路径。例如:
- 如需创建数据代理,请使用
POST方法和路径/dataAgents。 - 如需列出现有数据代理,请使用
GET方法和路径/dataAgents。
- 如需创建数据代理,请使用
Python SDK
以下 Python 代码示例演示了如何在 Colaboratory 中对您的 Google 账号进行身份验证,以便访问 Conversational Analytics API:
from google.colab import auth
auth.authenticate_user()
使用 Conversational Analytics API 连接到 Looker
如需使用 Conversational Analytics API 连接到 Looker,您必须提供以下信息:
您的 Looker 实例还必须满足特定要求:
此外,进行身份验证的用户或服务账号必须具有所需的 Looker 权限。
选择合适的连接方法
然后,您可以选择使用 Looker API 密钥(客户端 ID 和客户端密钥)或访问令牌来授权请求。仅使用专用连接的 Looker (Google Cloud Core) 客户必须使用访问令牌进行连接。
使用下表选择如何授权请求。
| 用户类型 | 授权方法 | 对于 Looker(原始版本) | 对于 Looker (Google Cloud Core) | 对于仅使用专用连接的 Looker (Google Cloud Core) | 说明 |
| 嵌入用户 | 访问令牌 | login_user |
login_user |
login_user |
尊重目标用户 access_token 的 LookML 行级和列级权限(例如 access_filters、access_grants、sql_always_where)。 |
| 标准用户 | 访问令牌 |
或 |
OAuth 客户端 | OAuth 客户端 | 尊重目标用户 access_token 的 LookML 行级和列级权限(例如 access_filters、access_grants、sql_always_where)。 |
| 仅限 Looker API 的服务账号 | API 密钥 | 客户端 ID 和密钥 | 客户端 ID 和密钥 | 不适用 | 所有用户都拥有相同的 Looker 访问权限级别。 |
API 密钥使用用户的权限和访问权限级别。如果您要构建的应用中所有用户都具有相同的访问权限,那么 API 密钥会非常有用。
借助访问令牌,您可以使用目标用户的 access_token 的 LookML 行级和列级权限(例如 access_filters、access_grants、sql_always_where)。访问令牌对于多租户应用非常有用。
必需的 Looker 权限
用于进行身份验证的用户或服务账号必须被授予 Looker 角色,该角色包含您要查询的模型的以下权限:
您可以在 Looker 实例的管理 > 角色部分配置这些权限。
使用 Looker API 密钥进行连接
本部分介绍了如何生成 API 密钥,以及如何配置 Conversational Analytics API 以使用直接 HTTP 请求或 SDK 连接到 Looker。
如需与 Looker 实例建立连接,您需要有效的 Looker API 密钥,这些密钥由 Looker 创建,包含客户端 ID 和客户端密钥。Looker 使用这些密钥针对 Looker API 对用户进行身份验证。
如需详细了解如何生成新的 Looker API 密钥,请参阅管理员设置 - 用户。如需详细了解身份验证方法和如何管理 Looker API 密钥,请参阅 Looker API 身份验证。
使用 Python 进行 HTTP 通信
生成 API 密钥(客户端 ID 和客户端密钥)后,您可以配置 Conversational Analytics API 以通过发出直接 HTTP 请求来连接到 Looker。以下示例代码演示了如何在 HTTP 请求的正文中指定 Looker 数据源详细信息和 API 密钥。
looker_credentials = {
"oauth": {
"secret": {
"client_id": "CLIENT_ID",
"client_secret": "CLIENT_SECRET",
}
}
}
looker_data_source = {
"looker": {
"explore_references": {
"looker_instance_uri": "INSTANCE_URI",
"lookml_model": "MODEL",
"explore": "EXPLORE",
}
}
}
按如下所示替换示例值:
- CLIENT_ID:您生成的 Looker API 密钥的客户端 ID
- CLIENT_SECRET:您生成的 Looker API 密钥的客户端密钥
- INSTANCE_URI:Looker 实例的完整网址(例如
https://mycompany.looker.com) - MODEL:您要使用的 LookML 模型的名称
- EXPLORE:您要使用的指定模型中的探索名称
Python SDK
生成 API 密钥(客户端 ID 和客户端密钥)后,您可以配置 Conversational Analytics API 以使用 Python 连接到 Looker。以下 Python 代码示例演示了如何向 Conversational Analytics API 指定 Looker 数据源详细信息和 API 密钥。
looker_client_id = "CLIENT_ID" # @param {type:"string"}
looker_client_secret = "CLIENT_SECRET" # @param {type:"string"}
looker_instance_uri = "INSTANCE_URI" # @param {type:"string"}
lookml_model = "MODEL" # @param {type:"string"}
explore = "EXPLORE" # @param {type:"string"}
# Looker data source
looker_explore_reference = geminidataanalytics.LookerExploreReference()
looker_explore_reference.looker_instance_uri = looker_instance_uri
looker_explore_reference.lookml_model = lookml_model
looker_explore_reference.explore = explore
credentials = geminidataanalytics.Credentials()
credentials.oauth.secret.client_id = looker_client_id
credentials.oauth.secret.client_secret = looker_client_secret
# Connect to your data source
datasource_references = geminidataanalytics.DatasourceReferences()
datasource_references.looker.explore_references = [looker_explore_reference]
按如下所示替换示例值:
- CLIENT_ID:您生成的 Looker API 密钥的客户端 ID
- CLIENT_SECRET:您生成的 Looker API 密钥的客户端密钥
- INSTANCE_URI:Looker 实例的完整网址(例如
https://mycompany.looker.com) - MODEL:您要使用的 Looker 模型的名称
- EXPLORE:您要使用的 Looker 探索的名称
使用访问令牌连接
本部分介绍了如何配置 Conversational Analytics API 以使用访问令牌连接到 Looker。
如需与 Looker 实例建立连接,您需要有效的 OAuth2 access_token 值,该值是通过成功向 login Looker API 端点发出请求而创建的。
如需详细了解如何生成访问令牌,请参阅 Looker API 身份验证以及如何提供客户端凭证以获取访问令牌。
使用 Python 进行 HTTP 通信
以下示例代码演示了如何在 HTTP 请求的正文中指定 Looker 数据源详细信息和访问令牌。
建议将 Looker 访问令牌 (access_token) 存储为环境变量,以提高安全性。
looker_credentials = {
"oauth": {
"token": {
"access_token": "ACCESS_TOKEN",
}
}
}
looker_data_source = {
"looker": {
"explore_references": {
"looker_instance_uri": "INSTANCE_URI",
"lookml_model": "MODEL",
"explore": "EXPLORE",
}
}
}
按如下所示替换示例值:
- ACCESS_TOKEN:您生成的用于授权向 Looker 发出的请求的
access_token值。 - INSTANCE_URI:Looker 实例的完整网址(例如
https://mycompany.looker.com) - MODEL:您要使用的 LookML 模型的名称
- EXPLORE:您要使用的指定模型中的探索名称
Python SDK
以下 Python 代码示例演示了如何使用 Python SDK 定义 Looker 数据源详细信息和访问令牌以授权请求。
建议将 Looker 访问令牌 (access_token) 存储为环境变量,以提高安全性。
looker_access_token = "ACCESS_TOKEN"
looker_instance_uri = "INSTANCE_URI"
lookml_model = "MODEL"
explore = "EXPLORE"
# Looker data source
looker_explore_reference = geminidataanalytics.LookerExploreReference()
looker_explore_reference.looker_instance_uri = looker_instance_uri
looker_explore_reference.lookml_model = lookml_model
looker_explore_reference.explore = explore
credentials = geminidataanalytics.Credentials()
credentials.oauth.token.access_token = looker_access_token
# Connect to your data source
datasource_references = geminidataanalytics.DatasourceReferences()
datasource_references.looker.explore_references = [looker_explore_reference]
按如下所示替换示例值:
- ACCESS_TOKEN:用于授权向 Looker 发出的请求的
access_token值 - INSTANCE_URI:Looker 实例的完整网址(例如
https://mycompany.looker.com) - MODEL:您要使用的 Looker 模型的名称
- EXPLORE:您要使用的 Looker 探索的名称
使用 Conversational Analytics API 连接到 BigQuery
本部分介绍了如何配置 Conversational Analytics API 以使用直接 HTTP 请求或 SDK 连接到 BigQuery。Conversational Analytics API 支持连接到 BigQuery 表和 BigQuery Graph(处于预览版阶段)。
借助 Conversational Analytics API,您可以连接的 BigQuery 表的数量没有硬性限制。不过,连接到大量表格可能会降低准确率,或者导致您超出 Gemini 的输入 token 限制。需要跨多个表进行复杂联接的查询也可能会导致回答不太准确。
连接到表格
如需连接到一个或多个 BigQuery 表,请为每个表提供项目 ID、数据集 ID 和表 ID。
以下示例展示了如何使用 HTTP 请求或 Python SDK 连接到一个或多个 BigQuery 表。
使用 Python 进行 HTTP 通信
以下示例代码定义了与多个 BigQuery 表的连接:
bigquery_data_sources = {
"bq": {
"tableReferences": [
{
"projectId": "PROJECT_ID",
"datasetId": "DATASET_ID",
"tableId": "TABLE_ID"
},
{
"projectId": "PROJECT_ID_2",
"datasetId": "DATASET_ID_2",
"tableId": "TABLE_ID_2"
},
{
"projectId": "PROJECT_ID_3",
"datasetId": "DATASET_ID_3",
"tableId": "TABLE_ID_3"
},
]
}
}
按如下所示替换示例值:
- PROJECT_ID、PROJECT_ID_2、PROJECT_ID_3:包含您要连接到的 BigQuery 数据集和表的 Google Cloud 项目的 ID。如需连接到公共数据集,请指定
bigquery-public-data。 - DATASET_ID、DATASET_ID_2、DATASET_ID_3:BigQuery 数据集的 ID(或 Lakehouse 运行时目录表的
catalog.namespace)。 - TABLE_ID、TABLE_ID_2、TABLE_ID_3:BigQuery 表的 ID(或 Lakehouse 运行时目录表的表名称)。
Python SDK
您可以使用 Colaboratory 中的 auth SDK,通过您的 Google 账号凭据进行身份验证,并授权 Colab 客户端使用您的凭据访问 BigQuery。
以下 Python 代码示例定义了与多个 BigQuery 表的连接,并演示了如何在 Colaboratory 中使用 Google 账号凭据进行身份验证以授权请求。
from google.colab import auth
auth.authenticate_user()
# BigQuery data source
bigquery_table_reference = geminidataanalytics.BigQueryTableReference()
bigquery_table_reference.project_id = "PROJECT_ID"
bigquery_table_reference.dataset_id = "DATASET_ID"
bigquery_table_reference.table_id = "TABLE_ID"
bigquery_table_reference_2 = geminidataanalytics.BigQueryTableReference()
bigquery_table_reference_2.project_id = "PROJECT_ID_2"
bigquery_table_reference_2.dataset_id = "DATASET_ID_2"
bigquery_table_reference_2.table_id = "TABLE_ID_2"
bigquery_table_reference_3 = geminidataanalytics.BigQueryTableReference()
bigquery_table_reference_3.project_id = "PROJECT_ID_3"
bigquery_table_reference_3.dataset_id = "DATASET_ID_3"
bigquery_table_reference_3.table_id = "TABLE_ID_3"
# Connect to your data source
datasource_references = geminidataanalytics.DatasourceReferences()
datasource_references.bq.table_references = [bigquery_table_reference, bigquery_table_reference_2, bigquery_table_reference_3]
按如下所示替换示例值:
- PROJECT_ID、PROJECT_ID_2、PROJECT_ID_3:包含您要连接到的 BigQuery 数据集和表的 Google Cloud 项目的 ID。如需连接到公共数据集,请指定
bigquery-public-data。 - DATASET_ID、DATASET_ID_2、DATASET_ID_3:BigQuery 数据集的 ID(或
catalog.namespace,表示 Lakehouse 运行时目录表)。例如san_francisco。 - TABLE_ID、TABLE_ID_2、TABLE_ID_3:BigQuery 表的 ID(或 Lakehouse 运行时目录表的表名称)。例如
street_trees。
连接到图表
以下示例展示了如何使用 HTTP 请求或 Python SDK 连接到 BigQuery 图。每个代理或对话只能连接到一个图。
使用 Python 进行 HTTP 通信
以下示例代码定义了与 BigQuery 图的连接:
bigquery_data_sources = {
"bq": {
"propertyGraphReferences": [
{
"projectId": "GRAPH_PROJECT_ID",
"datasetId": "GRAPH_DATASET_ID",
"propertyGraphId": "GRAPH_ID"
}
]
}
}
按如下所示替换示例值:
- GRAPH_PROJECT_ID:包含 BigQuery 图的 Google Cloud 项目的 ID。
- GRAPH_DATASET_ID:包含图表的 BigQuery 数据集的 ID。
- GRAPH_ID:BigQuery 图表的 ID。
Python SDK
您可以使用 Colaboratory 中的 auth SDK,通过用户的凭据(已向 Colaboratory 进行了身份验证)向 BigQuery 进行身份验证。
以下 Python 代码示例定义了与 BigQuery 图的连接:
from google.colab import auth
auth.authenticate_user()
# BigQuery graph reference
bigquery_pg_reference = geminidataanalytics.BigQueryPropertyGraphReference()
bigquery_pg_reference.project_id = "GRAPH_PROJECT_ID"
bigquery_pg_reference.dataset_id = "GRAPH_DATASET_ID"
bigquery_pg_reference.property_graph_id = "GRAPH_ID"
# Connect to your data source
datasource_references = geminidataanalytics.DatasourceReferences()
datasource_references.bq.property_graph_references = [bigquery_pg_reference]
按如下所示替换示例值:
- GRAPH_PROJECT_ID:包含 BigQuery 图的 Google Cloud 项目的 ID。
- GRAPH_DATASET_ID:包含图表的 BigQuery 数据集的 ID。
- GRAPH_ID:BigQuery 图表的 ID。
使用 Conversational Analytics API 连接到数据洞察
如需使用 Conversational Analytics API 连接到数据洞察,您必须先启用数据洞察 API。本部分介绍了如何通过直接 HTTP 请求或 SDK 配置 Conversational Analytics API 以连接到数据洞察。
如需将 Conversational Analytics API 与数据洞察 Pro 搭配使用,您的 Pro 订阅必须位于 VPC-SC 边界之外。
启用 Data Studio API
如需启用 Data Studio API,请按照启用 API 中的说明操作。
向数据洞察进行身份验证
如需使用 Conversational Analytics API 连接到数据洞察,您必须确保经过身份验证的用户或服务账号有权访问数据洞察数据源,然后提供数据源 ID。
使用 Python 进行 HTTP 通信
启用 Data Studio API 后,您可以通过使用 Python 发出 HTTP curl 请求来连接到 Data Studio。以下示例代码演示了如何在 HTTP 请求的正文中指定数据洞察数据源详细信息。
您可以通过发出直接 HTTP 请求来连接到数据洞察。以下代码块中演示了一个 HTTP 调用示例。
looker_studio_data_source = {
"studio":{
"studio_references":
[
{
"datasource_id": "DATASOURCE_ID"
}
]
}
}
将 your_studio_datasource_id 替换为您要使用的数据洞察数据源的实际 ID。
Python SDK
启用数据洞察 API 后,您可以使用 SDK 连接到数据洞察。以下 Python 代码示例演示了如何指定数据洞察数据源详细信息。
datasource_id = "DATASOURCE_ID"
# Looker Studio
studio_references = geminidataanalytics.StudioDatasourceReference()
studio_references.datasource_id = studio_datasource_id
# Connect to your data source
datasource_references = geminidataanalytics.DatasourceReferences()
datasource_references.studio.studio_references = [studio_references]
将 STUDIO-DATASOURCE-ID 替换为您要使用的数据洞察数据源的实际 ID。
使用 Conversational Analytics API 连接到数据库
如需使用 Conversational Analytics API 连接到数据库,您必须拥有数据库实例所需的 IAM 权限。
连接到 AlloyDB for PostgreSQL
用户或服务账号必须具有 alloydb.databaseUser 角色。如需了解详情,请参阅 AlloyDB、IAM 数据库身份验证。
使用 Python 进行 HTTP 通信
以下示例代码演示了如何在向 queryData 端点发送的 HTTP 请求的正文中指定 AlloyDB 数据源详细信息。
alloydb_data_sources = {
"alloydb": {
"database_reference": {
"project_id": alloydb_project_id,
"region": location,
"cluster_id": alloydb_cluster_id,
"instance_id": alloydb_instance_id,
"database_id": alloydb_database_id,
"table_ids":["table1", "table2", "table3"]
},
# Optional: Include this if you have pre-authored context for the agent
# "agent_context_reference": {
# "context_set_id": f"projects/alloydb_project_id/locations/{location}/contextSets/your_context_set_id"
# }
}
}
按如下所示替换示例值:
- your_table_id:以英文逗号分隔的表 ID 列表。如果未设置,则会考虑数据库中的所有表。
- your_context_set_id(可选):要检索的上下文集的完整 ID。如需详细了解如何查找上下文集 ID,请参阅在 AlloyDB 中查找代理上下文 ID。
Python SDK
以下 Python 代码示例演示了如何使用 Python SDK 定义 AlloyDB 数据源详细信息。
# AlloyDB data source
alloydb_table_ids = ["your_table_id_1", "your_table_id_2"]
alloydb_context_set_id = "your_context_set_id"
alloydb_reference = geminidataanalytics.AlloyDbReference()
alloydb_reference.database_reference.table_id = alloydb_table_ids
alloydb_reference_database_reference.project_id = billing_project
alloydb_reference_database_reference.region = "us-central1" # Example region
alloydb_reference_database_reference.cluster_id = alloydb_cluster_id
alloydb_reference_database_reference.instance_id = alloydb_instance_id
alloydb_reference_database_reference.database_id = alloydb_database_id
# optional set agent context reference
# alloydb_ref_1.agent_context_reference.context_set_id = f"projects/{billing_project}/locations/{location}/contextSets/your_context_set_id"
alloydb_reference.agent_context_reference.context_set_id = alloydb_context_set_id
# Connect to your data source
datasource_references = geminidataanalytics.DatasourceReferences()
datasource_references.alloydb.alloydb_reference = alloydb_reference
按如下所示替换示例值:
- your_table_id_1:AlloyDB 实例中第一个表的 ID。
- your_table_id_2:AlloyDB 实例中第二个表的 ID。
- your_context_set_id:要检索的上下文集的完整 ID。如需详细了解如何查找上下文集 ID,请参阅在 AlloyDB 中查找代理上下文 ID。
连接到 GoogleSQL for Spanner
用户或服务账号必须具有 spanner.databaseReader 角色。如需了解详情,请参阅应用 IAM 角色。
使用 Python 进行 HTTP 通信
以下示例代码演示了如何在向 queryData 端点发送的 HTTP 请求的正文中指定 GoogleSQL for Spanner 数据源详细信息。
spanner_data_sources = {
"spanner_reference": {
"database_reference": {
"project_id": spanner_project_id,
"region": location,
"engine": engine,
"instance_id": spanner_instance_id,
"database_id": spanner_database_id,
},
# Optional: Include this if you have pre-authored context for the agent
# "agent_context_reference": {
# "context_set_id": f"projects/{billing_project}/locations/{location}/contextSets/your_context_set_id"
# }
}
}
按如下所示替换示例值:
- your_table_id_1:GoogleSQL for Spanner 实例中第一个表的 ID。
- your_table_id_2:GoogleSQL for Spanner 实例中第二个表的 ID。
- your_context_set_id:要检索的上下文集的完整 ID。如需详细了解如何查找上下文集 ID,请参阅 在 GoogleSQL for Spanner 中查找代理上下文 ID。
Python SDK
以下 Python 代码示例演示了如何使用 Python SDK 定义 GoogleSQL for Spanner 数据源详细信息。
# Spanner data source
spanner_table_ids = ["your_table_id_1", "your_table_id_2"]
spanner_context_set_id = "your_context_set_id"
spanner_reference = geminidataanalytics.SpannerReference()
spanner_reference.database_reference.table_id = spanner_table_ids
spanner_reference.agent_context_reference.context_set_id = spanner_context_set_id
# Connect to your data source
datasource_references = geminidataanalytics.DatasourceReferences()
datasource_references.spanner.spanner_reference = spanner_reference
按如下所示替换示例值:
- your_table_id_1:GoogleSQL for Spanner 实例中第一个表的 ID。
- your_table_id_2:GoogleSQL for Spanner 实例中第二个表的 ID。
- your_context_set_id:要检索的上下文集的完整 ID。如需详细了解如何查找上下文集 ID,请参阅 在 GoogleSQL for Spanner 中查找代理上下文 ID。
连接到 Cloud SQL for MySQL 和 Cloud SQL for PostgreSQL
以下部分提供了有关连接到 Cloud SQL for MySQL 和 Cloud SQL for PostgreSQL 的说明。用户或服务账号必须拥有 cloudsql.studioUser 和 cloudsql.instanceUser 角色。如需了解详情,请参阅使用 IAM 数据库身份验证管理 Cloud SQL for MySQL 用户和使用 IAM 数据库身份验证管理 Cloud SQL for PostgreSQL 用户。
使用 Python 进行 HTTP 通信
以下示例代码演示了如何在 HTTP 请求的正文中指定 Cloud SQL for MySQL 和 Cloud SQL for PostgreSQL 数据源详细信息,以向 queryData 端点发送请求。
cloudsql_data_source = {
"cloudSqlReference": {
"databaseReference": {
"engine": MYSQL,
"project_id": cloud-db-nl2sql,
"region": us-central1,
"instance_id": nl2sql-birdsql-mysql,
"database_id": financial
},
# Optional: Include this if you have pre-authored context for the agent
# "agent_context_reference": {
# "context_set_id": f"projects/cloud-db-nl2sql/locations/us-central1/contextSets/bdf_pg_all_templates\"
# }
}
}
按如下所示替换示例值:
- your_table_id_1:Cloud SQL for MySQL 和 Cloud SQL for PostgreSQL 实例中第一个表的 ID。
- your_table_id_2:Cloud SQL for MySQL 和 Cloud SQL for PostgreSQL 实例中第二个表的 ID。
- your_context_set_id:要检索的上下文集的完整 ID。如需详细了解如何查找上下文集 ID,请参阅 在 Cloud SQL for MySQL 中查找代理上下文 ID和在 Cloud SQL for PostgreSQL 中查找代理上下文 ID。
Python SDK
以下 Python 代码示例演示了如何使用 Python SDK 定义 Cloud SQL for MySQL 和 Cloud SQL for PostgreSQL 数据源详细信息。
# Cloud SQL data source
cloudsql_table_ids = ["your_table_id_1", "your_table_id_2"]
cloudsql_context_set_id = "your_context_set_id"
cloudsql_reference = geminidataanalytics.CloudSqlReference()
cloudsql_reference.database_reference.table_id = cloudsql_table_ids
cloudsql_reference.agent_context_reference.context_set_id = cloudsql_context_set_id
# Connect to your data source
datasource_references = geminidataanalytics.DatasourceReferences()
datasource_references.cloudsql.cloudsql_reference = cloudsql_reference
按如下所示替换示例值:
- your_table_id_1:Cloud SQL 和 Cloud SQL for PostgreSQL 实例中第一个表的 ID。
- your_table_id_2:Cloud SQL 和 Cloud SQL for PostgreSQL 实例中第二个表的 ID。
- your_context_set_id:要检索的上下文集的完整 ID。如需详细了解如何查找上下文集 ID,请参阅在 Cloud SQL 中查找代理上下文 ID和在 Cloud SQL for PostgreSQL 中查找代理上下文 ID。