我正在编写一个云数据流,它从Pubsub读取消息并将其存储到BigQuery中。我想使用分区表(按日期),我使用与消息关联的Timestamp
来确定消息应该进入哪个分区。以下是我的代码:
BigQueryIO.writeTableRows()
.to(new SerializableFunction<ValueInSingleWindow<TableRow>, TableDestination>() {
private static final long serialVersionUID = 1L;
@Override
public TableDestination apply(ValueInSingleWindow<TableRow> value) {
log.info("Row value : {}", value.getValue());
Instant timestamp = value.getTimestamp();
String partition = DateTimeFormat.forPattern("yyyyMMdd").print(timestamp);
TableDestination td = new TableDestination(
"<project>:<dataset>.<table>" + "$" + partition, null);
log.info("Table Destination : {}", td);
return td;
}
})
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)
.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND)
.withSchema(tableSchema);
当我部署数据流时,我可以在Stackdriver中看到日志语句,但是,消息没有插入到BigQuery表中,我收到以下错误:
Request failed with code 400, will NOT retry: https://www.googleapis.com/bigquery/v2/projects/<project_id>/datasets/<dataset_id>/tables
severity: "WARNING"
因此,看起来它无法创建表,导致插入失败。我是否需要更改数据流定义才能使其工作?如果没有,是否有其他方式以编程方式创建分区表?
我正在使用Apache beam 2.0.0。