【问题标题】:GCP Workflows - Set destination table?GCP 工作流 - 设置目标表?
【发布时间】:2021-06-06 16:30:26
【问题描述】:

我正在使用 Google Cloud Workflows,使用 googleapis.bigquery.v2. jobs.query 来转换 BigQuery 上的数据。我能够正确运行我的工作流程并对给定的表执行查询,但我现在要做的是将查询结果存储在不同的数据集和表上。 googleapis.bigquery.v2.jobs.query 文档中没有关于目标表的内容。基于this SO question,我发现可以设置目标数据集和表,但是如果我可以在.yaml上做类似的事情,我会感到困惑

我在 SO 上找到的示例

"configuration": {
  "query": {
    "query": "select count(*) from foo.bar",
    "destinationTable": {
      "projectId": "my_project",
      "datasetId": "my_dataset",
      "tableId": "my_table"
    },
    "createDisposition": "CREATE_IF_NEEDED",
    "writeDisposition": "WRITE_APPEND",
  }
}

我的工作流程:workflows-1.yaml

- getCurrentTime:
    call: googleapis.bigquery.v2.jobs.query
    args:
        projectId: survivor-316012
        body:
            connectionProperties: 
            createSession: false
            defaultDataset:
                datasetId: europe
                projectId: survivor-316012
            dryRun: false
            kind: ...
            location: ...
            maxResults: 32
            preserveNulls: false
            query: "SELECT * FROM `survivor-316012.europe.france`"
            queryParameters: []
            timeoutMs: 10000
            useLegacySql: false
            useQueryCache: false
    result: currentDateTime

【问题讨论】:

    标签: google-cloud-platform google-bigquery


    【解决方案1】:
    1. googleapis.bigquery.v2.jobs.query 端点不提供通过 API/YAML 语法创建目标表,但您可以编写查询来创建表

      create table mytable as (select ........)

    2. 要使用destinationTable API 设置,您需要使用不同的端点: googleapis.bigquery.v2.jobs.insert,它还有很多需要配置的地方,这篇linked 文章中有一个完整的示例。

    基本上你需要它的query 部分。

    - insert:
        call: googleapis.bigquery.v2.jobs.insert
        args:
            projectId: ...
            body:
                configuration:
                    query:
                        allowLargeResults: ...
                        clustering:
                        connectionProperties: ...
                        createDisposition: ...
                        createSession: ...
                        defaultDataset:
                            datasetId: ...
                            projectId: ...
                        destinationEncryptionConfiguration:
                        destinationTable: <YOUR SECTION> 
                        flattenResults: ...
                        maximumBillingTier: ...
                        maximumBytesBilled: ...
                        parameterMode: ...
                        preserveNulls: ...
                        priority: ...
                        query: ...
                        queryParameters: ...
                        rangePartitioning:
                        schemaUpdateOptions: ...
                        tableDefinitions: ...
                        timePartitioning:
                        useLegacySql: ...
                        useQueryCache: ...
                        userDefinedFunctionResources: ...
                        writeDisposition: ...
        result: insertResult
    

    【讨论】:

      猜你喜欢
      • 2019-04-09
      • 2013-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多