Question | Click to View Answer |
What does the following code print? What code is executed on the worker nodes and what code is executed on the driver machine. val numbersRdd = sc.parallelize(List(9, 2))
val squaresRdd = numbersRdd.map { x: Int => x * x }
val squaresArray = squaresRdd.collect()
squaresArray.foreach(println)
|
The following output is printed. 81
4
The The If the |
What does the following code print? val namesRdd = sc.parallelize(List("luisa", "melissa", "eva"))
val namesCount = namesRdd.count()
println(namesCount)
|
The |
What does the following code print? val numbersRdd = sc.parallelize(List(900, 333, 555, 10))
val biggestNumber = numbersRdd.max()
println(biggestNumber)
|
The |
What does the following code print? val numbersRdd = sc.parallelize(List(4, 99, 2, 348, 99, 1))
val numbers = numbersRdd.take(2)
println(numbers.toList)
|
The |
What does the following code print? val numbersRdd = sc.parallelize(List(4, 99, 2, 348, 99, 1))
val numbers = numbersRdd.takeOrdered(2)
println(numbers.toList)
|
The |
What does the following code print? val numbersRdd = sc.parallelize(List(4, 99, 2, 348, 99, 1))
val numbers = numbersRdd.top(2)
println(numbers.toList)
|
The |
What does the following code print? val numbersRdd = sc.parallelize(List(4, 99, 2, 348, 99, 1))
val sum = numbersRdd.fold(0) { (memo: Int, n: Int) =>
memo + n
}
println(sum)
|
|
Explain how Spark uses lazy evaluation to execute the following lines of code. val numbersRdd = sc.parallelize(List(9, 2)) // step 1
val squaresRdd = numbersRdd.map { x: Int => x * x } // step 2
val evenSquares = squaresRdd.filter { x: Int => x % 2 == 0 } // step 3
val squaresArray = squaresRdd.collect() // step 4
|
RDD transformations are not actually computed until an application calls an action method of a RDD. In step 1, the RDD isn't even actually created. The instructions for creating the RDD are saved, but the RDD isn't created. In step 2, the In step 3, the In step 4, the action method |