【发布时间】:2018-09-27 15:26:36
【问题描述】:
根据此处的文档:https://cloud.google.com/bigquery/docs/tables#creating_a_table_when_you_load_data BigQuery 应该可以根据数据创建表。
将数据加载到 BigQuery 时,您可以将数据加载到新表或分区中,可以将数据附加到现有表或分区中,也可以覆盖表或分区。在将数据加载到其中之前,您不需要创建一个空表。您可以同时创建新表并加载数据。
但是,每当我尝试将数据从 Java 流式传输到 BigQuery 时,我都会收到一条错误消息。
这是一个插入语句的示例,但仅在我手动创建表之后才有效:
InsertAllResponse response = bigQuery
.insertAll(
InsertAllRequest
.newBuilder(tableId)
.addRow(rowContent)
.build()
);
我可以在 Java 中创建架构,然后创建表,但是我必须不断检查架构是否已创建,然后才能流式传输到它。 generateBigQuerySchema 是我创建的定义模式的方法。如果架构已经存在,下面的代码将失败,所以我必须在创建它之前检查它是否存在。
InsertAllResponse response = bigQuery
.create(requestLog.generateBigQuerySchema(tableId))
.getBigQuery()
.insertAll(
InsertAllRequest
.newBuilder(tableId)
.addRow(rowContent)
.build()
);
【问题讨论】:
标签: java google-bigquery