spark sortByKey
来源:互联网 发布:淘宝旺铺图片轮播尺寸 编辑:程序博客网 时间:2024/06/09 22:29
// sortByKey其实就是根据key进行排序,可以手动指定升序,或者降序
// 返回的,还是JavaPairRDD,其中的元素内容,都是和原始的RDD一模一样的
// 但是就是RDD中的元素的顺序,不同了
public static void mySortByKey(){
SparkConf conf = new SparkConf()
.setAppName("mySortByKey")
.setMaster("local");
JavaSparkContext sc = new JavaSparkContext(conf);
List<Tuple2<Integer, String>> scoreList = Arrays.asList(
new Tuple2<Integer, String>(65, "leo"),
new Tuple2<Integer, String>(50, "tom"),
new Tuple2<Integer, String>(100, "marry"),
new Tuple2<Integer, String>(80, "jack"));
JavaPairRDD<Integer, String> scores = sc.parallelizePairs(scoreList);
JavaPairRDD<Integer, String> sortedScores =scores.sortByKey();
sortedScores.foreach(new VoidFunction<Tuple2<Integer,String>>() {
private static final long serialVersionUID = 1L;
@Override
public void call(Tuple2<Integer, String> t) throws Exception {
System.out.println(t._1 + ": " + t._2);
}
});
sc.close();
}
运算结果:
50: tom
65: leo
80: jack
100: marry
- spark sortByKey
- spark--transform算子--sortByKey
- 【spark】sortByKey实现二次排序
- spark中的sortBy和sortByKey
- Spark: sortBy sortByKey 二次排序
- spark:sortByKey按年龄排序--20
- Spark: sortBy和sortByKey函数详解
- Spark: sortBy和sortByKey函数详解
- Spark: sortBy和sortByKey函数详解
- Spark: sortBy和sortByKey函数详解
- Spark 使用sortByKey进行二次排序
- Spark 使用sortByKey进行二次排序
- spark源码解读4之SortByKey
- Spark: sortBy和sortByKey函数详解
- Spark:sortBy和sortByKey的函数详解
- SPARK:sortByKey和sortBy 函数讲解
- spark sortByKey subtractByKey take takeOrdered等函数使用例子
- 【Spark Java API】Transformation(9)—sortByKey、repartitionAndSortWithinPartitions
- 洛谷P1656 炸铁路
- Picasso源码解析
- IOS中使用像素位图(CGImageRef)对图片进行处理
- 在java中使用dom4j解析xml(示例代码)
- failed to push some refs to 'git@github.com:songmengke/NotePadVMware.git'
- spark sortByKey
- 简单 Java 加密算法 1.0
- 自动检测溢出的unsigned int加法
- 微信三方登录
- 设计模式笔记:工厂模式
- 同步IO,异步IO,阻塞IO,非阻塞IO
- IOS开发必读博客网站
- PL/SQL TNS 12170 连接超时
- log4j的配置文件详细解析