0
エラー:BigQueryの繰り返しレコードは、アレイの外側に加え
Exception in thread "main" java.lang.RuntimeException
{"errors":[{"debugInfo":"generic::failed_precondition: Repeated record added outside of an array.","reason":"invalid"}],"index":0}
言語:スカラ
のGradle BigQueryの依存:
:compile "com.google.apis:google-api-services-bigquery:v2-rev326-1.22.0"
テーブルスキーマを生成するためのコード
import scala.collection.JavaConversions._
val orderTableSchema = new TableSchema()
orderTableSchema.setFields(Seq(
new TableFieldSchema().setName("revisionId").setType("STRING").setMode("REQUIRED"),
new TableFieldSchema().setName("executions").setType("RECORD").setMode("REPEATED").setFields(Seq(
new TableFieldSchema().setName("ts").setType("INTEGER"),
new TableFieldSchema().setName("price").setType("FLOAT"),
new TableFieldSchema().setName("qty").setType("INTEGER")
))
))
BigQueryのウェブUIに示すよう
テーブルが実行カラムの正しいスキーマで正常に作成された:
import scala.collection.JavaConversions._
val row = new TableRow()
.set("revisionId", "revision1")
.set("executions", Seq(
new TableRow().set("ts", 1L).set("price", 100.01).set("qty", 1000)
))
val content = new TableDataInsertAllRequest().setRows(Seq(
new TableDataInsertAllRequest.Rows().setJson(row)
))
val insertAll = bigQuery.tabledata().insertAll(projectId, datasetId, "order", content)
val insertResponse = insertAll.execute()
if (insertResponse.getInsertErrors != null) {
insertResponse.getInsertErrors.foreach(println)
// this prints:
// {"errors":[{"debugInfo":"generic::failed_precondition: Repeated record added outside of an array.","reason":"invalid"}],"index":0}
// throw to just terminate early for demo
throw new RuntimeException()
}