【问题标题】:How To Combine Parsed TextFiles In Apache-Beam DataFlow in Python?如何在 Python 的 Apache-Beam DataFlow 中组合解析文本文件?
【发布时间】:2020-02-05 16:55:20
【问题描述】:

这似乎在 DirectRunner 中运行良好,但当我切换到 DataflowRunner 时出现错误。我基本上需要以某种方式组合读入的文件,但是一旦我使用beam.combiners.ToList() 连接我的数据,它就会引入一大堆问题。

代码示例:

def convert_to_dataframe(readable_file):
    yield pd.read_csv(io.TextIOWrapper(readable_file.open()))

class merge_dataframes(beam.DoFn):
    def process(self, element):
        yield pd.concat(element).reset_index(drop=True)

    with beam.Pipeline(options=pipeline_options) as p:

        (p
            | 'Match Files From GCS' >> beam.io.fileio.MatchFiles(raw_data_path)
            | 'Read Files' >> beam.io.fileio.ReadMatches()
            | 'Shuffle' >> beam.Reshuffle()
            | 'Create DataFrames' >> beam.FlatMap(convert_to_dataframe)
            | 'Combine To List' >> beam.combiners.ToList()
            | 'Merge DataFrames' >> beam.ParDo(merge_dataframes())
            | 'Apply Transformations' >> beam.ParDo(ApplyPipeline(creds_path=args.creds_path,
                                                                  project_name=args.project_name,
                                                                  feature_group_name=args.feature_group_name
                                                                  ))
            | 'Write To GCS' >> beam.io.WriteToText(feature_data_path,
                                                    file_name_suffix='.csv',
                                                    shard_name_template='')
         )

错误:

"No objects to concatenate [while running 'Merge DataFrames']" 

我不明白这个错误,因为执行“合并到列表”的部分应该生成一个数据帧列表,然后将其传递到“合并数据帧”步骤中,当我使用 DirectRunner 时确实是这种情况。

【问题讨论】:

  • 我在没有源/接收器的情况下进行了测试,这对我来说似乎对两个跑步者都有效 (code here)。我建议在merge_dataframes 中添加日志记录(执行似乎在process 方法内)并检查进入步骤的实际数据

标签: python pandas parallel-processing google-cloud-dataflow apache-beam


【解决方案1】:

鉴于此错误,我怀疑MatchFiles 实际上没有匹配任何内容(例如,由于文件模式错误),因此beam.combiners.ToList 的输出是一个空列表。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-18
    • 2018-01-03
    • 1970-01-01
    • 2022-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    相关资源
    最近更新 更多