Thursday, March 24, 2022

Spark Basics : RDD ,Stages, Tasks and DAG

 

Spark Basics : RDDs, Stages, Tasks and DAG

val rdd = sc.textFile("/some_file",3)  
val lines = sc.parallelize(List("this is","an example"))
val rdd = sc.textFile("spam.txt")
val filtered = rdd.filter(line => line.contains("money"))
filtered.count()
New RDD is created after every transformation.(DAG graph)
DAGScheduler Transforming RDD Lineage(DAG) Into Stage DAG(Physical Execution Plan)
val input = sc.textFile("log.txt")
val splitedLines = input.map(line => line.split(" "))
.map(words => (words(0), 1))
.reduceByKey{(a,b) => a + b}
Shuffled RDD is created by reduceByKey wide transforamtion
val sfi  = sc.textFile("/data/blah/input").map{ x => val xi = x.toInt; (xi,xi*xi) }
val sp = sc.parallelize{ (0 until 1000).map{ x => (x,x * x+1) }}
val spj = sfi.join(sp)
val sm = spj.mapPartitions{ iter => iter.map{ case (k,(v1,v2)) => (k, v1+v2) }}
val sf = sm.filter{ case (k,v) => v % 10 == 0 }
sf.saveAsTextFile("/data/blah/out")

No comments: