Google BigQuery是否支持ARRAY <STRING>?

sag*_*sag 0 google-bigquery google-cloud-platform google-cloud-dataflow

我正在将数据从Google数据流推送到Google BigQuery。我有TableRow数据对象。TableRow中的一列确实包含字符串数组。

这里开始,我发现Google BigQuery支持Array列类型。所以我试图用ARRAY<SCHEMA>as类型创建表。但是我收到以下错误

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)
Run Code Online (Sandbox Code Playgroud)

这是我用来将值发布到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"));
Run Code Online (Sandbox Code Playgroud)

这是架构构造

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);
}
Run Code Online (Sandbox Code Playgroud)

如何将字符串数组插入BigQuery表中?

Wil*_*uks 5

ARRAY<STRING>在BigQuery中定义,请将字段设置为“ STRING”,其模式设置为“ REPEATED”。

例如在Python中,它定义为 field = SchemaField(name='field_1', type='STRING', mode='REPEATED')

对于我可以看到的Java客户端,您具有相同的选项,可以将TYPE定义为STRING,将MODE定义为REPEATED