【问题标题】:ByteStringCoder for reading data in Apache Beam用于在 Apache Beam 中读取数据的 ByteStringCoder
【发布时间】:2018-06-22 19:42:18
【问题描述】:

我正在尝试使用标准 TextIO.read() 读取 Apache Beam 2.4.0 版的数据。数据必须作为 ByteString 读取。

不幸的是,Apache Beam 似乎不像 Dataflow 那样支持.withCoder()。我似乎找不到介绍编码器的替代方法。此外,似乎 ByteStringCoder 不再包含在 Apache Beam 的编码器中。

使用最新版本的 Apache Beam 获得与 Dataflow 的 .withCoder(ByteStringCoder.of()) 相同的结果的最佳方法是什么?编码器仍然存在于 Apache Beam 中,因此必须有某种方式来使用它们。

【问题讨论】:

    标签: apache-beam dataflow


    【解决方案1】:

    ByteStringCoder 位于beam-sdks-java-extensions-protobuf 模块中,因此需要包含依赖项

    https://mvnrepository.com/artifact/org.apache.beam/beam-sdks-java-extensions-protobuf

    至于TextIO:它使用StringUtf8Coder,因此您可能需要编写自己的BoundedSource/UnboundedSource。 然后使用:

    pipeline.apply(Read.from(yourCreatedSource))

    您可以从当前的TextSource 中汲取灵感,您可以可能只将FileBasedSourceString 类型更改为ByteString

    https://github.com/apache/beam/blob/master/sdks/java/core/src/main/java/org/apache/beam/sdk/io/TextSource.java

    【讨论】:

      猜你喜欢
      • 2018-06-07
      • 1970-01-01
      • 1970-01-01
      • 2019-07-18
      • 2023-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多