使用 Spotify Scio 处理 XML 个文件(apache beam 的 scala 包装器)

process XML files with Spotify Scio (scala wrapper for apache beam)

Apache beam java sdk 支持读取大型 xml 输入文件,org.apache.beam.sdk.io.xml.XmlIO(我看的是 2.1.0 版本)

有谁知道 Scio 是否允许你做同样的事情或者有例子吗?我有一组非常大的 xml 文件需要处理。

您可以使用自定义输入转换在 Scio 中执行此操作。通常,您需要为没有本机 Scio 界面的任何输入源执行此操作。

示例:

import org.apache.beam.sdk.io.xml._


val xmlInputTransform = XmlIO.read()
  .from("file or pattern spec")         // TODO: specify file name or Java "glob" file pattern to read multiple XML files
  .withRootElement("root element")      // TODO: specify name of root element
  .withRecordElement("record element")  // TODO: specify name of record element
  .withRecordClass(classOf[Record])     // TODO: Define JAXB annotated Record class

// xmls is an SCollection[Record]
val xmls = sc.customInput("fromXML", xmlInputTransform)

有关详细信息,请参阅 Apache Beam Java SDK 参考中的 XmlIO.Read 部分:https://beam.apache.org/documentation/sdks/javadoc/2.2.0/