【问题标题】:Does Google BigQuery supports ARRAY<STRING>?Google BigQuery 是否支持 ARRAY<STRING>?
【发布时间】:2017-06-03 06:53:50
【问题描述】:

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

here,我发现Google BigQuery 支持Array 列类型。 所以我尝试创建以ARRAY&lt;SCHEMA&gt; 为类型的表。但是我得到了以下错误

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 表?

【问题讨论】:

    标签: google-bigquery google-cloud-platform google-cloud-dataflow


    【解决方案1】:

    要在 BigQuery 中定义 ARRAY&lt;STRING&gt;,我将字段设置为“STRING”,并将其模式设置为“REPEATED”。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-24
      • 1970-01-01
      • 2018-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-14
      相关资源
      最近更新 更多