从 Google Cloud Dataflow 输出排序的文本文件

Output sorted text file from Google Cloud Dataflow

我在 Google Cloud DataFlow 中有一个 PCollection<String>,我正在通过 TextIO.Write.to:

将其输出到文本文件
PCollection<String> lines = ...;
lines.apply(TextIO.Write.to("gs://bucket/output.txt"));

目前每个分片输出的行都是随机排列的。

是否可以让 Dataflow 按排序顺序输出行?

Dataflow 不直接支持此功能。

对于有界 PCollection,如果您将输入分片得足够细,那么您可以使用 Sink implementation that sorts each shard. You may want to refer to the TextSink 实现基本大纲来编写排序文件。