Is there a way to create a date partitioned table using Apache Beam BigQueryIO
, in other words, is there a way to use partition decorator for a table which is not created yet?
I know that I can create a table at first and then I can use partition decorator within my code but since I dynamically determine the TableDestination
from fields of rows, I cannot create these tables in advance.
My code is like this:
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));
With this, it tries to create a table of project-id:dataset-id.tableName$partition
and it complains that $
cannot be used inside a table name.