【问题标题】:Is it possible to read a text file sequentially?是否可以按顺序读取文本文件?
【发布时间】:2018-07-28 20:08:16
【问题描述】:

我正在使用beam.io.ReadFromText 处理来自文本文件的数据。

解析文件比逐行读取更复杂(有一些状态需要携带并逐行更改)。

我可以让 Beam 只用一个处理器读取我的文件吗? (未并行化)这些情况下的任何其他最佳实践?

【问题讨论】:

    标签: apache-beam apache-beam-io


    【解决方案1】:

    是的,您可以使用FileSystems API 自己对文件进行任意处理。这就是 ReadFromText 和所有其他基于文件的内置转换在后台所做的。

    def ParseFile(name):
      with FileSystems.open(name) as f:
        ... Parse the file and yield elements ...
    
    p | beam.Create(['/path/to/file'])
      | beam.FlatMapElements(ParseFile)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-31
      • 1970-01-01
      • 2011-06-28
      • 2014-02-12
      • 1970-01-01
      • 2013-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多