Scala学习中对reduceBykey(func: (V, V) => V)的理解
数据:
编号 | 性别 | 身高 |
---|---|---|
1 | F | 170 |
2 | M | 178 |
3 | M | 174 |
… | … | … |
要求:分别计算各个性别的最高身高和最低身高
代码如下:
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setMaster("local[*]").setAppName("Peopleinfo")
val sc = new SparkContext(conf)
val lineRDD = sc.textFile("file:///d:/peopleinfo.txt")
val man:LongAccumulator = sc.longAccumulator("man")
val female:LongAccumulator = sc.longAccumulator("female")
val infoRDD:RDD[(String,(Int,Int))] = lineRDD.map(t => {
val fields = t.split