错误:googleapi:错误 400:字段 CONSENTS 是 RECORD 类型,但没有架构,无效
Posted
技术标签:
【中文标题】错误:googleapi:错误 400:字段 CONSENTS 是 RECORD 类型,但没有架构,无效【英文标题】:Error: googleapi: Error 400: Field CONSENTS is type RECORD but has no schema, invalid 【发布时间】:2021-12-01 14:50:21 【问题描述】:我正在尝试使用 terraform 创建 BigQuery 表。
这是我的架构:
"dataset_id": "xxx_$location_$project_env",
"table_id": "tb_xxx_user_info",
"range_partitioning": null,
"time_partitioning": null,
"clustering": null,
"description": "XXX Users",
"deletion_protection": false,
"labels" :
"env": "$project_env",
"location": "$location",
"data_layer": "specific-layer",
"confidentiality": "c3",
"description": "tb-lps-users"
,
"schema": [
"name": "CUSTOMER_ID",
"type": "STRING",
"mode": "REQUIRED",
"description": "CUSTOMER_ID"
,
"name": "SAP_NUMBER",
"type": "STRING",
"mode": "REQUIRED",
"description": "SAP_NUMBER"
,
"name": "COMPANY_NAME",
"type": "STRING",
"mode": "NULLABLE",
"description": "COMPANY_NAME"
,
"name": "EMAIL",
"type": "STRING",
"mode": "NULLABLE",
"description": "EMAIL"
,
"name": "PHONE_NUMBER",
"type": "STRING",
"mode": "NULLABLE",
"description": "PHONE_NUMBER"
,
"name": "CONTACTS",
"type": "STRING",
"mode": "NULLABLE",
"description": "CONTACTS"
,
"fields": [
"name": "OPTIN_MODIFICATION_DATE",
"type": "DATETIME",
"mode": "NULLABLE",
"description": "OPTIN_MODIFICATION_DATE"
,
"name": "CONSENT",
"type": "STRING",
"mode": "NULLABLE",
"description": "CONSENT"
],
"name": "CONSENTS",
"type": "RECORD",
"mode": "REPEATED",
"description": "CONSENTS"
]
架构被另一个文件解析
这里是这个文件的代码:
resource "google_bigquery_table" "tables"
for_each = var.tables
project = var.project_id
dataset_id = each.value.dataset_id
table_id = each.value.table_id
schema = jsonencode(each.value.schema)
clustering = each.value.clustering
description = each.value.description
labels = each.value.labels
deletion_protection = each.value.deletion_protection
dynamic "time_partitioning"
for_each = each.value.time_partitioning != null ? [each.value.time_partitioning] : []
content
type = each.value.time_partitioning.type
field = each.value.time_partitioning.field
require_partition_filter = each.value.time_partitioning.require_partition_filter
dynamic "range_partitioning"
for_each = each.value.range_partitioning != null ? [each.value.range_partitioning] : []
content
field = each.value.range_partitioning.field
range
start = each.value.range_partitioning.start
end = each.value.range_partitioning.end
interval = each.value.range_partitioning.interval
depends_on = [google_bigquery_dataset.datasets]
这里是 varaiable.tf :
variable "tables"
description = "A list of objects which include table_id, dataset_id, schema, clustering, time_partitioning, range_partitioning, expiration_time and labels."
default =
type = map(object(
dataset_id = string
table_id = string,
description = string,
schema = list(object(
name = string,
type = string,
mode = string,
description = string
)),
clustering = list(string),
deletion_protection = bool
time_partitioning = object(
expiration_ms = number,
field = string,
type = string,
require_partition_filter = bool
),
range_partitioning = object(
field = string,
start = number,
end = number,
interval = number
),
labels = map(string)
))
错误是:错误:googleapi:错误 400:字段同意是记录类型但没有架构,无效
我尝试在 variable.tf 上添加值字段,但由于所有表都不需要字段值,因此它再次崩溃..
你能帮我找出这个错误的根源吗?
非常感谢。
【问题讨论】:
【参考方案1】:感谢您的回答,但我找到了解决方案:
只需将any放入类型变量中即可。
variable "tables"
description = "A list of objects which include table_id, dataset_id, schema, clustering, time_partitioning, range_partitioning, expiration_time and labels."
default =
type = any
【讨论】:
【参考方案2】:您可以尝试更改此代码块。
"name": "CONSENTS",
"type": "RECORD",
"mode": "REPEATED",
"description": "CONSENTS",
"fields": [
"name": "OPTIN_MODIFICATION_DATE",
"type": "DATETIME",
"mode": "NULLABLE",
"description": "OPTIN_MODIFICATION_DATE"
]
或者
您可以在代码中添加“ ”。
"fields": [
"name": "OPTIN_MODIFICATION_DATE",
"type": "DATETIME",
"mode": "NULLABLE",
"description": "OPTIN_MODIFICATION_DATE"
,
"name": "CONSENT",
"type": "STRING",
"mode": "NULLABLE",
"description": "CONSENT"
],
"name": "CONSENTS",
"type": "RECORD",
"mode": "REPEATED",
"description": "CONSENTS"
您可以使用这个 Bigquery validator。
【讨论】:
以上是关于错误:googleapi:错误 400:字段 CONSENTS 是 RECORD 类型,但没有架构,无效的主要内容,如果未能解决你的问题,请参考以下文章
地理位置 - 'https://www.googleapis.com/' 上的网络位置提供商:返回错误代码 400
GCP - 创建队列时出错:googleapi:错误 400:无法创建队列,因为具有此名称的队列最近存在