Google bigquery Google BigQuery是否支持数组<;字符串>;?
我正在将数据从Google数据流推送到Google BigQuery。我有Google bigquery Google BigQuery是否支持数组<;字符串>;?,google-bigquery,google-cloud-platform,google-cloud-dataflow,Google Bigquery,Google Cloud Platform,Google Cloud Dataflow,我正在将数据从Google数据流推送到Google BigQuery。我有TableRow对象,其中包含数据。TableRow中的一列不包含字符串数组 从中,我发现Google BigQuery支持数组列类型。 所以我尝试创建一个表,将ARRAY作为类型。但是我得到了下面的错误 com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request { "code" : 400, "errors
TableRow
对象,其中包含数据。TableRow中的一列不包含字符串数组
从中,我发现Google BigQuery支持数组列类型。
所以我尝试创建一个表,将ARRAY
作为类型。但是我得到了下面的错误
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)
这里是模式构造
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);
}
private static TableSchema getSchema(){
列表字段=新的ArrayList();
add(新的TableFieldSchema().setName(“column1”).setType(“STRING”);
add(新的TableFieldSchema().setName(“column2”).setType(“STRING”));
fields.add(new TableFieldSchema().setName(“array_column”).setType(“array”));
返回新的TableSchema().setFields(fields);
}
如何将字符串数组插入BigQuery表?要在BigQuery中定义数组
,我将字段设置为“字符串”,其模式设置为“重复”
例如,在Python中,它被定义为field=SchemaField(name='field_1',type='STRING',mode='REPEATED')
对于Java客户端,我可以看到您有相同的选项,您可以定义asSTRING
和asREPEATED
要在BigQuery中定义数组,我将字段设置为“STRING”,其模式设置为“REPEATED”
例如,在Python中,它被定义为field=SchemaField(name='field_1',type='STRING',mode='REPEATED')
对于Java客户端,我可以看到您有相同的选项,您可以定义asSTRING
和asREPEATED
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);
}