有没有办法使用 java 驱动程序为大查询创建基于非摄取时间的分区表?

Posted

技术标签:

【中文标题】有没有办法使用 java 驱动程序为大查询创建基于非摄取时间的分区表?【英文标题】:Is there a way to create non-ingestion time based partition tables for big query with the java driver? 【发布时间】:2019-07-10 21:50:03 【问题描述】:

我一直在环顾四周,甚至使用了最新的大查询 java 驱动程序:

<dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-bigquery</artifactId>
    <version>1.81.0</version>
</dependency>

它似乎只提供了基于加载/摄取时间进行分区的选项。

TimePartitioning.of(Type.DAY);

我应该使用另一个选项或类来根据特定的 DATE 或 TIMESTAMP 列进行分区吗?或者这只是 java 驱动程序不支持?

【问题讨论】:

您是否尝试过执行CREATE TABLE 语句? cloud.google.com/bigquery/docs/reference/standard-sql/… 我知道我可以通过 UI 来完成,但希望它可以在 java 中使用,以便我们可以将它与我们现有的工作流集成。也就是说,通过 bigquery API 使用 create table 语句可能是一种方便的解决方法。将不得不深入研究它。 :) 谢谢! 【参考方案1】:

Java 似乎不可能,但 Python and Go 客户端库、DDL 语句、UI 等可能。

【讨论】:

【参考方案2】:

是的,根据客户端文档it is supported。

这是一个例子:

BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();

String my_field = "my_field";
Schema schema = Schema.of(Field.of(my_field, LegacySQLTypeName.TIMESTAMP));

// Here is where we set the field we want to be used for the partition
TimePartitioning timePartitioning = TimePartitioning.newBuilder(TimePartitioning.Type.DAY)
                                                      .setField(my_field)
                                                      .build();

TableDefinition tableDef = StandardTableDefinition.newBuilder()
                                          .setSchema(schema)
                                          .setTimePartitioning(timePartitioning)
                                          .build();

TableInfo tableInfo = TableInfo.newBuilder(TableId.of("dataset", "table"), tableDef).build();

Table table = bigquery.create(tableInfo);

【讨论】:

以上是关于有没有办法使用 java 驱动程序为大查询创建基于非摄取时间的分区表?的主要内容,如果未能解决你的问题,请参考以下文章