首页 文章

Wait.on(信号)在Apache Beam中使用

提问于
浏览
1

写入1st之后是否可以使用Wait.on()方法(Apache Beam 2.4中的新功能)在批处理管道中写入第二个BigQuery表? Apache Beam文档中给出的示例是:

PCollection<Void> firstWriteResults = data.apply(ParDo.of(...write to first database...));
 data.apply(Wait.on(firstWriteResults))
     // Windows of this intermediate PCollection will be processed no earlier than when
     // the respective window of firstWriteResults closes.
     .apply(ParDo.of(...write to second database...));

但是为什么我会从ParDo中写入数据库?我们不能通过使用Dataflow中给出的I / O转换来做同样的事情吗?

谢谢 .

1 回答

  • 1

    是的,这是可能的,虽然有一些已知的限制,目前正在做一些工作来进一步支持这一点 .

    为了完成这项工作,您可以执行以下操作:

    WriteResult writeResult = data.apply(BigQueryIO.write()
         ...
         .withMethod(BigQueryIO.Write.Method.STREAMING_INSERTS) 
    );
    
    data.apply(Wait.on(writeResults.getFailedInserts()))
        .apply(...some transform which writes to second database...);
    

    应该注意,这仅适用于流式插入,不适用于文件加载 . 与此同时,目前正在做一些工作来更好地支持这个用例,你可以关注here

    有用的参考:

相关问题