【问题标题】:Create bigquery table using google cloud deployment manager YAML file使用谷歌云部署管理器 YAML 文件创建 bigquery 表
【发布时间】:2019-08-02 18:16:47
【问题描述】:
我正在尝试按照 YAML 文件使用部署管理器创建一个大查询表:
进口:
- path: schema.txt
资源:
- name: test
type: bigquery.v2.table
properties:
datasetId: test_dt
tableReference:
datasetId: test_dt
projectId: test_dev
tableId: test
schema:
fields: {{ imports["schema.txt"] }}
但是,当我尝试通过 .txt 文件给出表架构定义时,我得到一个解析错误。如果我给出架构定义而不是 .txt 文件,那么脚本会成功运行。谷歌云帮助中给出了这种导入文本文件的方法。谁能帮我解决这个问题?
【问题讨论】:
标签:
google-bigquery
google-cloud-platform
【解决方案1】:
我认为部署管理器格式化 .txt 文件内容的方式可能不正确。调试此问题的一个好方法是收集 HTTP 请求跟踪并比较两个请求之间的差异。
【解决方案2】:
这是我们可以在 bigquery 部署管理器中使用嵌套或重复字段来工作的 yaml。
# Example of the BigQuery (dataset and table) template usage.
#
# Replace `<FIXME:my_account@email.com>` with your account email.
imports:
- path: templates/bigquery/bigquery_dataset.py
name: bigquery_dataset.py
- path: templates/bigquery/bigquery_table.py
name: bigquery_table.py
resources:
- name: dataset_name_here
type: bigquery_dataset.py
properties:
name: dataset_name_here
location: US
access:
- role: OWNER
userByEmail: my_account@email.com
- name: table_name_here
type: bigquery_table.py
properties:
name: table_name_here
datasetId: $(ref.dataset_name_here.datasetId)
timePartitioning:
properties:
field:
type: DAY
schema:
- name: column1
type: STRUCT
fields:
- name: column2
type: string
- name: test1
type: RECORD
mode: REPEATED
fields:
- name: test2
type: string
【解决方案3】:
使用部署管理器在 BigQuery 中创建视图的 YAML 示例:
注意:此 YAML 还展示了如何在表 (hello_table) 上创建分区 (_PARTITIONTIME)
# Example of the BigQuery (dataset and table) template usage.
# Replace `<FIXME:my_account@email.com>` with your account email.
imports:
- path: templates/bigquery/bigquery_dataset.py
name: bigquery_dataset.py
- path: templates/bigquery/bigquery_table.py
name: bigquery_table.py
resources:
- name: dataset_name
type: bigquery_dataset.py
properties:
name: dataset_name
location: US
access:
- role: OWNER
userByEmail: my_account@email.com
- name: hello
type: bigquery_table.py
properties:
name: hello_table
datasetId: $(ref.dataset_name.datasetId)
timePartitioning:
type: DAY
schema:
- name: partner_id
type: STRING
- name: view_step
type: bigquery_table.py
properties:
name: hello_view
datasetId: $(ref.dataset_name.datasetId)
view:
query: select partner_id from `project_name.dataset_name.hello_table`
useLegacySql: False