【发布时间】:2019-11-01 01:17:46
【问题描述】:
我正在尝试使用 Nifi 处理器 PutBigQueryBatch 1.9.2 将以下 json 数据插入到 bigquery 表中
{
"Revenue_Label": "Dining Room",
"StoreName": "STORE A",
"Revenue_Id": "1",
"Alteration_Flag": "False",
"Order_Mode_Label": "DriveThru",
"checkClosetime": "2019-10-24T13:43:19+13:00",
"Alterations": [ {
"Alteration_Product_Code": "211136",
"Alteration_Product_Net_Amount": 0.0,
"Altered_Product_Code": "211135",
"Alteration_Product_Amount": 0.0,
"Altered_Product_Name": "Burger",
"Alteration_Product_Name": "Add Sauce",
"Alteration_Product_Qty": 1.0 } ],
"StoreId": "1234",
"dob": "20191024",
"Order_Mode_Id": "3",
"checknumber": "54321"}
但是,我不断收到以下错误
PutBigQueryBatch:RECORD 字段必须至少有一个 子字段:java.lang.IllegalArgumentException:RECORD 字段必须 至少有一个子字段
在 PutBigQueryBatch 的属性中,我使用了以下与 BigQuery 表定义在顺序、模式、名称和类型方面匹配的架构定义
[
{"mode": "NULLABLE","name": "Revenue_Label","type": "STRING"},
{"mode": "NULLABLE","name": "StoreName","type": "STRING"},
{"mode": "NULLABLE","name": "Revenue_Id", "type": "STRING" },
{"mode": "NULLABLE","name": "Alteration_Flag","type": "STRING"},
{"mode": "NULLABLE","name": "Order_Mode_Label","type": "STRING"},
{"mode": "NULLABLE","name": "checkClosetime","type": "TIMESTAMP" },
{"mode": "REPEATED",
"name": "Alterations",
"type": "RECORD",
"fields": [
{"mode": "NULLABLE","name": "Alteration_Product_Code", "type": "STRING" },
{"mode": "NULLABLE", "name": "Alteration_Product_Net_Amount", "type": "FLOAT" },
{"mode": "NULLABLE", "name": "Altered_Product_Code","type": "STRING" },
{"mode": "NULLABLE", "name": "Alteration_Product_Amount", "type": "FLOAT" },
{"mode": "NULLABLE", "name": "Altered_Product_Name", "type": "STRING" },
{"mode": "NULLABLE", "name": "Alteration_Product_Name", "type": "STRING" },
{"mode": "NULLABLE","name": "Alteration_Product_Qty", "type": "FLOAT" }
]
},
{"mode": "NULLABLE","name": "StoreId","type": "STRING"},
{"mode": "NULLABLE", "name": "dob","type": "STRING"},
{"mode": "NULLABLE","name": "Order_Mode_Id","type": "STRING"},
{"mode": "NULLABLE","name": "checknumber","type": "STRING" }
]
我尝试过的:
- 从 json flowflie 中删除了所有的空格和回车符
- 尝试了 json 文件开头和结尾的数组,并将 BigQuery 表与此匹配。
- 将项目名称更改为不包含下划线。
- 一次构建插入一列,只有在数组存在时才会失败。
- 在使用实用程序“bq show --schema --format=prettyjson”时,直接使用了从 Google Cloud BigQuery 生成的架构定义。
- 将每个数组项的模式定义为 REQUIRED 而不是 NULLABLE。
- 从 Nifi 中 PutBigQueryBatch 进程的属性中的架构定义中删除了所有空格和回车符
所有都导致了与上述相同的错误
注意 在我的 nifi 进程的其他地方,我成功地使用了 PutBigQueryBatch 进程并更新了表。不同之处在于 json 不存在数组。
有人对如何解决这个问题有任何想法吗?
【问题讨论】:
-
至少
Alterations数组未关闭。 -
嗨 daggett - 谢谢你的回复。我对您的意思“更改”数组未关闭感到有些困惑。是架构定义还是需要关闭的json文件?你能提供一个应该是什么的例子吗?谢谢蒂姆
-
@TimManger 您没有找到解决此问题的方法吗?我遇到了类似的问题。我可以手动加载模式 json 以在 GCP 控制台中生成表,但如果我尝试通过 PutBigQueryBatch 执行此操作,它会在模式的同一 RECORD 部分失败。当手动创建表时,所有记录都可以毫无问题地写入其中。
-
嗨 Aklys - 我必须创建一个解决方法。我所做的是在 GCP 中创建一个主题和订阅,然后使用 nifi 中的 PublishGCPubSub 进程将 json 流文件传递给 PubSub。从那里我写了一个云函数,当 jason 文件到达队列主题并将 json 文件插入到 bigquery 的表中时触发。
标签: arrays json google-bigquery apache-nifi