Question | Click to View Answer |
What does the following code print? val mammals = List("Lion", "Dolphin", "Whale")
val mammalsRdd = sc.parallelize(mammals)
val mammalsLengthRdd = mammalsRdd.map { (m: String) =>
m.length
}
mammalsLengthRdd.collect().foreach(println)
|
The The The |
What does the following code print? val languages = List("spanish", "french", "farsi")
val languagesRdd = sc.parallelize(languages)
val someLanguagesRdd = languagesRdd.filter { (l: String) =>
l.take(1) != "f"
}
someLanguagesRdd.collect().foreach(println)
|
The The |
What does the following code print? val numbers = List("one", "two")
val letters = List("a", "b")
val numbersRdd = sc.parallelize(numbers)
val lettersRdd = sc.parallelize(letters)
val both = numbers.union(letters)
println(both)
|
The |
What does the following code print? val numbersRdd = sc.parallelize(List(1, 2, 3, 4, 3, 2, 1))
val uniqueNumbersRdd = numbersRdd.distinct
uniqueNumbersRdd.collect().foreach(println)
|
The |
What does the following code print? val numbersRdd = sc.parallelize(List(10, 20))
val lettersRdd = sc.parallelize(List("a", "b"))
val zippedPairsRdd = numbersRdd.zip(lettersRdd)
zippedPairsRdd.collect().foreach(println)
|
The following lines are printed: (10,a)
(20,b)
The |
What does the following code print? case class Person(name: String, age: Int)
val bob = new Person("bob", 40)
val mario = new Person("mario", 40)
val britney = new Person("britney", 16)
val peopleRdd = sc.parallelize(List(bob, mario, britney))
val inDaClubRdd = peopleRdd.groupBy { p => {
p.age
}
}
inDaClubRdd.collect().foreach(println)
|
The following is printed: (16,CompactBuffer(Person(britney,16)))
(40,CompactBuffer(Person(bob,40), Person(mario,40)))
An RDD of |
What does the following code print? val numbersRdd = sc.parallelize(List(8, 10, 2))
val sortedRdd = numbersRdd.sortBy(x => x, true)
sortedRdd.collect().foreach(println)
|
The |
What does the following code print? val pairRdd1 = sc.parallelize(List(("a", 1), ("b",2), ("c",3)))
val pairRdd2 = sc.parallelize(List(("b", "second"), ("c","third"), ("d","fourth")))
val joinRdd = pairRdd1.join(pairRdd2)
joinRdd.collect().foreach(println)
|
The following output is printed: (b,(2,second))
(c,(3,third))
The |
What does the following code print? val pairRdd1 = sc.parallelize(List(("a", 1), ("b",2), ("c",3)))
val pairRdd2 = sc.parallelize(List(("b", "second"), ("c","third"), ("d","fourth")))
val leftOuterJoinRdd = pairRdd1.leftOuterJoin(pairRdd2)
leftOuterJoinRdd.collect().foreach(println)
|
The following output is printed: (a,(1,None))
(b,(2,Some(second)))
(c,(3,Some(third)))
The |