【发布时间】:2020-04-21 08:38:47
【问题描述】:
我们有一个无限的 PCollection PCollection<TableRow> source 插入到 BigQuery。
每 500,000 条消息或 5 分钟触发一次窗口的简单“按规定”方法是:
source.apply("GlobalWindow", Window.<TableRow>into(new GlobalWindows())
.triggering(Repeatedly.forever(AfterFirst.of(
AfterPane.elementCountAtLeast(500000),
AfterProcessingTime.pastFirstElementInPane().plusDelayOf(Duration.standardMinutes(5))))
).withAllowedLateness(Duration.standardMinutes(1440)).discardingFiredPanes())
您会认为将以下内容应用于触发的窗口/窗格将允许您将触发的窗格的内容写入 BigQuery:
.apply("BatchWriteToBigQuery", BigQueryIO.writeTableRows()
.to(destination)
.withMethod(BigQueryIO.Write.Method.FILE_LOADS)
.withNumFileShards(NUM_FILE_SHARDS)
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)
.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND));
但这会产生编译错误An exception occured while executing the Java class. When writing an unbounded PCollection via FILE_LOADS, triggering frequency must be specified
相对简单的解决方法是将.withTriggeringFrequency(Duration.standardMinutes(5)) 添加到上面,这实际上会使每五分钟插入条消息或每N条消息的想法完全无效,在这种情况下,你也可以摆脱窗口。
有没有办法真正做到这一点?
【问题讨论】:
标签: apache-beam dataflow