【问题标题】:Apache Beam: Wait for AvroIO write step is done before start ImportTransform Dataflow templateApache Beam:在启动 ImportTransform Dataflow 模板之前等待 AvroIO 写入步骤完成
【发布时间】:2021-07-05 16:11:50
【问题描述】:

我正在使用 Apache Beam 创建一个管道,其中基本上读取 InputFile,转换为 Avro,将 AvroFile 写入存储桶,然后使用 Dataflow 模板将这些 avro 文件导入到 Spanner

我面临的问题是最后一步(将 Avro 文件导入数据库)在前一步(将 Avro 文件写入存储桶)完成之前开始。

我尝试添加 Wait.on 函数,但这仅在返回 PCollection 时有效,但当我将文件写入 avro 时,它会返回 PDone。

代码示例:

// Step 1: Read Files
PCollection<String> lines = pipeline.apply("Reading Input Data exported from Cassandra",TextIO.read().from(options.getInputFile()));

// Step 2: Convert to Avro
lines .apply("Write Item Avro File",AvroIO.writeGenericRecords(spannerItemAvroSchema).to(options.getOutput()).withSuffix(".avro"));

// Step 3: Import to the DataBase

pipeline.apply( new ImportTransform(
                spannerConfig,
                options.getInputDir(),
                options.getWaitForIndexes(),
                options.getWaitForForeignKeys(),
                options.getEarlyIndexCreateFlag()));

同样,问题在于第 3 步在第 2 步完成之前开始

有什么想法吗?

【问题讨论】:

  • 感谢 Ricco 的回复,但这不起作用,因为 AvroIO.write 函数返回一个 PDone 并且它不能使用 Wait 方法。此方法 (Wait) 仅在返回 PCollection 时有效

标签: google-cloud-dataflow apache-beam dataflow


【解决方案1】:

这是 API 中的一个缺陷,请参阅,例如recent discussion 在梁开发列表上。目前唯一的解决方案是 fork AvroIO 以返回 PCollection 或按顺序运行两个管道。

【讨论】:

  • 这正是我的问题。感谢分享
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-13
  • 2020-03-31
  • 1970-01-01
  • 2014-10-04
  • 2014-11-15
  • 2017-03-15
相关资源
最近更新 更多