我有PCollection<List<KV<String,Long>>
,我使用Top
转换和OrderByValue
对列表进行了排序,但是当我将结果写入文件时,它不是有序的。
public class StringFormatResult extends DoFn<List<KV<String, Long>>, String> {
@Override
public void processElement(ProcessContext context) {
for (KV<String, Long> item : context.element()) {
context.output(item.getKey() + " | " + item.getValue());
}
}
}
p.apply(TextIO.Read.named("ReadLines").from(options.getInputFile()))
.apply("Word counter phase",new WordCounter())
.apply(TextIO.Write.named("WriteCounts").to(options.getOutputFile()).withoutSharding());
p.run();