Apache Beam 将 PCollection 初始化为空

Apache Beam initialize an PCollection to empty

我正在尝试将 Spark ETL 应用程序转换为 Beam 应用程序。

在 Spark 应用程序中,我有一个空的 RDD。

sc.emptyRDD()

其中 scSparkContext

如果我很好理解,PCollection 就像 Spark RDD。所以,有一种方法可以创建一个空的 PCollection?

使用Create.empty()。由于 PCollection 是类型化的并且需要编码器,因此您还需要指定编码器或类型描述符(即使集合为空),例如PCollection<String> emptyStrings = Create.of(StringUtf8Coder.of()).

对我有用的是:

PCollection<String> output = p.apply(Create.empty(StringUtf8Coder.of()));