我正在将Google数据流中的数据推送到Google BigQuery。我有TableRow
对象,其中包含数据。 TableRow中的一列确实包含String of String。
从here开始,我发现Google BigQuery支持Array列类型。
所以我尝试创建ARRAY<SCHEMA>
类型的表。但我得到了以下错误
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid value for: ARRAY<STRING> is not a valid value",
"reason" : "invalid"
} ],
"message" : "Invalid value for: ARRAY<STRING> is not a valid value"
}
com.google.cloud.dataflow.sdk.util.UserCodeException.wrapIf(UserCodeException.java:47)
com.google.cloud.dataflow.sdk.util.DoFnRunnerBase.wrapUserCodeException(DoFnRunnerBase.java:369)
com.google.cloud.dataflow.sdk.util.DoFnRunnerBase.finishBundle(DoFnRunnerBase.java:162)
com.google.cloud.dataflow.sdk.runners.worker.SimpleParDoFn.finishBundle(SimpleParDoFn.java:194)
com.google.cloud.dataflow.sdk.runners.worker.ForwardingParDoFn.finishBundle(ForwardingParDoFn.java:47)
以下是我用于将值发布到BigQuery
的代码 .apply(BigQueryIO.Write.named("Write enriched data")
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)
.withSchema(getSchema())
.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND)
.to("table_name"));
这是架构构造
private static TableSchema getSchema() {
List<TableFieldSchema> fields = new ArrayList<>();
fields.add(new TableFieldSchema().setName("column1").setType("STRING"));
fields.add(new TableFieldSchema().setName("column2").setType("STRING"));
fields.add(new TableFieldSchema().setName("array_column").setType("ARRAY<STRING>"));
return new TableSchema().setFields(fields);
}
如何在BigQuery表中插入字符串数组?