[英]How to create a partitioned table in BigQuery from java?
I would like to create a partitioned table(partition by field which is of DATE type) in BigQuery from java.我想从 Java 在 BigQuery 中创建一个分区表(按日期类型的字段分区)。 I searched a lot but there is not much information on this.
我搜索了很多,但关于这方面的信息并不多。 The code I used is
我使用的代码是
TimePartitioning timePartitioning = TimePartitioning.of(TimePartitioning.Type.DAY);
timePartitioning.toBuilder().setField("col3");
TableDefinition tableDefinition = StandardTableDefinition.newBuilder().setSchema(schema2).setTimePartitioning(timePartitioning).build();
TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build();
bigquery.create(tableInfo);
Here, I have a couple of questions在这里,我有几个问题
Easiest way would be to issue a standard query - if you can query from Java (which you already do?), just send a query like this:最简单的方法是发出标准查询 - 如果您可以从 Java 查询(您已经这样做了?),只需发送如下查询:
#standardSQL
CREATE TABLE `project.dataset.table`
(
x INT64 OPTIONS(description="An optional INTEGER field"),
y STRUCT<
a ARRAY<STRING> OPTIONS(description="A repeated STRING field"),
b BOOL
>,
date_column DATE
)
PARTITION BY date_column
CLUSTER BY i_recommend_you_to_choose_a_clustering_column
I haven't tried but I'd use this table creation sample replacing the one-liner for StandardTableDefinition
我还没有尝试过,但我会使用此表创建示例替换
StandardTableDefinition
的单行
TableDefinition tableDefinition = StandardTableDefinition.of(schema);
with the code taken from here .使用从这里获取的代码。 You could borrow the
StandardTableDefinition
creation/configuration options that make sense for you and then replace the one-liner for TimePartitioning
您可以借用对您有意义的
StandardTableDefinition
创建/配置选项,然后替换TimePartitioning
TimePartitioning TIME_PARTITIONING = TimePartitioning.of(TimePartitioning.Type.DAY, 42);
with code taken from there eg使用从那里获取的代码,例如
TimePartitioning TIME_PARTITIONING =
TimePartitioning.newBuilder(TYPE)
.setExpirationMs(EXPIRATION_MS)
.setRequirePartitionFilter(REQUIRE_PARTITION_FILTER)
.setField(FIELD)
.build();
Use .setRequirePartitionFilter(...)
only if you would like to disallow queries that doesn't take advantage of partitioning.仅当您想禁止不利用分区的查询时才使用
.setRequirePartitionFilter(...)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.