如何在 Apache Flink 中对数据集进行排序? [英] How to sort a dataset in Apache Flink?
本文介绍了如何在 Apache Flink 中对数据集进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个格式为 DataSet> 的元组数据集.我希望对字段 String 上的整个"数据集进行排序,然后仅获取文件中的 Long 值.Flink 确实提供了排序分区,但这在这里没有帮助,因为我需要对数据集进行完全排序.
I have a Tuple Dataset of the form DataSet>. I wish to sort the "entire" Dataset on field String and then get only the Long values in a file. Flink does provide sort-partition but that does not help here as I need to sort the Dataset completely.
推荐答案
如果将并行度设置为 <代码>1代码>:
You can also use sortPartition()
to sort the complete DataSet
if you set the parallelism to 1
:
DataSet<Tuple2<String, Long>> data = ...
DataSet<Tuple2<String, Long>> sorted = data
.sortPartition(0, Order.ASCENDING).setParallelism(1); // sort in one partition
DataSet<Long> longs = sorted.map(new LongExtractor()); // map to extract long
这篇关于如何在 Apache Flink 中对数据集进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文