以编程方式创建日期分区表
Creating Date Partitioned Tables programmatically
有没有办法使用 Apache Beam BigQueryIO
创建分区 table 的日期,换句话说,有没有办法为尚未创建的 table 使用分区装饰器?
我知道我可以首先创建一个 table 然后我可以在我的代码中使用分区装饰器但是因为我从行的字段动态确定 TableDestination
,我无法创建这些 table提前.
我的代码是这样的:
rows.apply("Write rows",
BigQueryIO.writeTableRows()
.to(new SerializableFunction<ValueInSingleWindow<TableRow>, TableDestination>() {
@Override
public TableDestination apply(ValueInSingleWindow<TableRow> value) {
TableRow t = value.getValue();
String tableName = ... // get from the fields of table row
String partition = ... // get the date part that will be used for decorator
TableDestination td = new TableDestination(
"project-id:dataset-id." + tableName + "$" + partition, "");
return td;
}
}).withSchema(someSchema)
.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND)
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED));
有了这个,它会尝试创建 project-id:dataset-id.tableName$partition
的 table 并抱怨 $
不能在 table 名称中使用。
Table id格式:The ID of the table. The ID must contain only letters (a-z, A-Z), numbers (0-9), or underscores (_). The maximum length is 1,024 characters.
勾选BigQuery doc。
目前看来这是不可能的。
虽然官方 BEAM JIRA 问题列表中有对此的请求:BEAM-2390 and an official pull request,所以看起来这很快就会成为可能!
有没有办法使用 Apache Beam BigQueryIO
创建分区 table 的日期,换句话说,有没有办法为尚未创建的 table 使用分区装饰器?
我知道我可以首先创建一个 table 然后我可以在我的代码中使用分区装饰器但是因为我从行的字段动态确定 TableDestination
,我无法创建这些 table提前.
我的代码是这样的:
rows.apply("Write rows",
BigQueryIO.writeTableRows()
.to(new SerializableFunction<ValueInSingleWindow<TableRow>, TableDestination>() {
@Override
public TableDestination apply(ValueInSingleWindow<TableRow> value) {
TableRow t = value.getValue();
String tableName = ... // get from the fields of table row
String partition = ... // get the date part that will be used for decorator
TableDestination td = new TableDestination(
"project-id:dataset-id." + tableName + "$" + partition, "");
return td;
}
}).withSchema(someSchema)
.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND)
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED));
有了这个,它会尝试创建 project-id:dataset-id.tableName$partition
的 table 并抱怨 $
不能在 table 名称中使用。
Table id格式:The ID of the table. The ID must contain only letters (a-z, A-Z), numbers (0-9), or underscores (_). The maximum length is 1,024 characters.
勾选BigQuery doc。
目前看来这是不可能的。
虽然官方 BEAM JIRA 问题列表中有对此的请求:BEAM-2390 and an official pull request,所以看起来这很快就会成为可能!