1、创建intRDD
val intRDD=sc.parallelize(List(3,1,2,5,5))
intRDD.collect()
intRDD.foreach(println)
2、
val StringRDD=sc.parallelize(List("apple","banana","peach","padns","apples"))
StringRDD.collect()
res4.foreach(println)
3、
def addone(x:Int):Int={
addone: (x: Int)Int
intRDD.map(addone).foreach(println)
intRDD.map(x=>x+1).foreach(println)
intRDD.map(_+1).foreach(println)
4、
val intRDD=sc.parallelize(List(6,2,4,9,9))
intRDD.filter(x=>x<7).collect()
5、
val stringRDD1=sc.parallelize(List("iphone","xiaomi","oppo","huawei"))
stringRDD1.filter(x=>x.contains("o")).collect()
6、
intRDD.distinct().collect()
7、
val sRDD=intRDD.randomSplit(Array(0.4,0.6))
8、
9、
val intRDD=sc.parallelize(List(6,2,4,9,9))
intRDD.randomSplit(Array(0.4,0.6))
res0(0).foreach(println)
res0(0).collect()
res0(1).collect()
10、
val gRDD=intRDD.groupBy(
x=>{if(x%2==0)"even" else "odd"}
).collect()
gRDD: Array[(String, Iterable[Int])] = Array((even,CompactBuffer(6, 2, 4)), (odd,CompactBuffer(9, 9)))
intRDD.sum
intRDD.mean
intRDD.max
intRDD.min