赞
踩
val rdd: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4))
// reduce聚合
val res: Int = rdd.reduce(_+_)
val rdd: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4))
val ints: Array[Int] = rdd.collect()
println(ints.mkString(","))
val rdd: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4))
println(rdd.count())
println(rdd.first())
println(rdd.take(3).mkString(","))
val rdd2: RDD[Int] = sc.makeRDD(List(3, 5, 1, 2, 9, 6))
println(rdd2.takeOrdered(3).mkString(","))
val rdd3: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4), 8)
val resRDD: Int = rdd3.aggregate(10)(_ + _, _ + _)
println(resRDD)
val rdd3: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4), 8)
println(rdd3.fold(10)(_ + _))
val rdd4: RDD[(Int, String)] = sc.makeRDD(List((1, "a"), (2, "b"), (1, "c"), (2, "a"), (2, "d"), (3, "e")))
println(rdd4.countByKey())
val rdd4: RDD[(Int, String)] = sc.makeRDD(List((1, "a"), (2, "b"), (1, "c"), (2, "a"), (2, "d"), (3, "e")))
rdd4.saveAsTextFile("")
rdd4.saveAsObjectFile("")
// savaAsSequenceFile 只能保存kv类型的数据
rdd4.saveAsSequenceFile("")
rdd.foreach(println)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。