【发布时间】: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