0
0
Apache Sparkdata~10 mins

Spark vs Hadoop MapReduce in Apache Spark - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a Spark RDD from a text file.

Apache Spark
rdd = sparkContext.[1]("data.txt")
Drag options to blanks, or click blank then click option'
Aread
BtextFile
Cload
Dopen
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'read' instead of 'textFile' causes an error.
Using 'load' is for DataFrames, not RDDs.
2fill in blank
medium

Complete the code to perform a map operation on an RDD to square each number.

Apache Spark
squared_rdd = numbers_rdd.[1](lambda x: x * x)
Drag options to blanks, or click blank then click option'
Areduce
Bfilter
CflatMap
Dmap
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'reduce' tries to combine all elements into one value.
Using 'filter' removes elements instead of transforming them.
3fill in blank
hard

Fix the error in the code to count the number of elements in an RDD.

Apache Spark
count = rdd.[1]()
Drag options to blanks, or click blank then click option'
Acount
Bsize
Clen
Dlength
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'len' causes a Python error because RDDs do not support it.
Using 'size' or 'length' are not valid RDD methods.
4fill in blank
hard

Fill both blanks to create a dictionary of word counts using Spark RDD transformations.

Apache Spark
word_counts = rdd.[1](lambda line: line.split()).[2](lambda word: (word, 1)).reduceByKey(lambda a, b: a + b).collectAsMap()
Drag options to blanks, or click blank then click option'
AflatMap
Bmap
Cfilter
DgroupBy
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'map' instead of 'flatMap' for splitting lines results in nested lists.
Using 'filter' or 'groupBy' in wrong places breaks the logic.
5fill in blank
hard

Fill all three blanks to filter an RDD for words longer than 3 characters, convert to uppercase, and collect results.

Apache Spark
result = rdd.[1](lambda word: len(word) [2] 3).[3](lambda word: word.upper()).collect()
Drag options to blanks, or click blank then click option'
Afilter
B>
Cmap
DflatMap
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'flatMap' instead of 'map' for uppercase conversion.
Using '<' instead of '>' in the length comparison.