티스토리 뷰

반응형
package com.ex

import org.apache.spark.{SparkConf, SparkContext}

/**
* Created by moonsun on 17. 3. 14..
*/
object RddTest {

def main(args: Array[String]): Unit = {
val conf = new SparkConf().setMaster("local").setAppName("RDD TEST")
val sc = new SparkContext(conf)

val input = sc.parallelize(List((1,2),(3,6),(2,3),(2,5)))

println("\ntt0")
val tt0 = input.reduceByKey( (x,y)=> x+y)
tt0.foreach{ println }

println("\ntt1")
val tt1 = input.groupByKey()
tt1.foreach{ println }

println("\ntt2")
val tt2 = input.keys
tt2.foreach{ println }

println("\ntt3")
val tt3 = input.values
tt3.foreach{ println }

println("\ntt4")
val tt4 = input.mapValues(x => x + 1)
tt4.foreach{ println }

println("\ntt5")
val tt5 = input.sortByKey()
tt5.foreach{ println }

}

}
==> 결과

tt0 (1,2) (3,6) (2,8) tt1 (1,CompactBuffer(2)) (3,CompactBuffer(6)) (2,CompactBuffer(3, 5)) tt2 1 3 2 2 tt3 2 6 3 5 tt4 (1,3) (3,7) (2,4) (2,6) tt5 (1,2) (2,3) (2,5) (3,6)



-- 끝 --





반응형