【发布时间】:2020-02-05 00:38:47
【问题描述】:
我阅读了可拆分的 DoFn 博客,据我所知,TextIO(用于云数据流运行器)中已经提供了此功能。我不清楚的是 - 使用 TextIO 将能够从给定文件中并行读取行。
【问题讨论】:
标签: google-cloud-dataflow apache-beam
我阅读了可拆分的 DoFn 博客,据我所知,TextIO(用于云数据流运行器)中已经提供了此功能。我不清楚的是 - 使用 TextIO 将能够从给定文件中并行读取行。
【问题讨论】:
标签: google-cloud-dataflow apache-beam
仅对于 Java,TextIO 源将自动并行读取未压缩的文件。
这没有正式记录,但 TextIO 源是 FileBaseSource 的子类,允许查找。这意味着如果工人决定拆分工作,它可以这样做。 FileBasedSource 拆分代码见here。
【讨论】:
Cubez 的回答很好。我还想补充一点,TextIO 既是 PTransform 又是 I/O 连接器,实现了 expand() 方法:
@Override
public PCollection<String> expand(PCollection<FileIO.ReadableFile> input) {
return input.apply(
"Read all via FileBasedSource",
new ReadAllViaFileBasedSource<>(
getDesiredBundleSizeBytes(),
new CreateTextSourceFn(getDelimiter()),
StringUtf8Coder.of()));
}
如果我们进一步看,我们可以看到 ReadAllViaFileBasedSource 类也有如下定义的 expand() 方法:
@Override
public PCollection<T> expand(PCollection<ReadableFile> input) {
return input
.apply("Split into ranges", ParDo.of(new SplitIntoRangesFn(desiredBundleSizeBytes)))
.apply("Reshuffle", Reshuffle.viaRandomKey())
.apply("Read ranges", ParDo.of(new ReadFileRangesFn<>(createSource)))
.setCoder(coder);
}
这就是底层运行器如何在执行器之间分配 PCollection 并并行读取。
【讨论】: