0
0
Apache Sparkdata~10 mins

Reduce and aggregate actions in Apache Spark - Interactive Code Practice

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

Complete the code to calculate the sum of all numbers in the RDD.

Apache Spark
total_sum = numbers.[1](lambda x, y: x + y)
Drag options to blanks, or click blank then click option'
Areduce
Bcollect
Cmap
Dfilter
Attempts:
3 left
💡 Hint
Common Mistakes
Using collect returns all elements, not the sum.
Using map transforms elements but does not aggregate.
Using filter selects elements but does not combine.
2fill in blank
medium

Complete the code to find the maximum value in the RDD.

Apache Spark
max_value = numbers.[1]()
Drag options to blanks, or click blank then click option'
Amax
Breduce
Cmin
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using min returns the smallest element.
Using reduce without a function will cause an error.
Using count returns the number of elements, not the max.
3fill in blank
hard

Fix the error in the code to correctly compute the sum using reduce.

Apache Spark
total = numbers.reduce(lambda x, y: x [1] y)
Drag options to blanks, or click blank then click option'
A/
B+
C-
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication * will compute the product, not sum.
Using subtraction - or division / will give wrong results.
4fill in blank
hard

Fill both blanks to create a dictionary of word counts using reduceByKey.

Apache Spark
word_counts = words.[1](lambda a, b: a [2] b).collectAsMap()
Drag options to blanks, or click blank then click option'
AreduceByKey
B+
C*
Dmap
Attempts:
3 left
💡 Hint
Common Mistakes
Using map does not aggregate values.
Using multiplication * will multiply counts incorrectly.
5fill in blank
hard

Fill all three blanks to create a dictionary of word lengths for words longer than 3 characters.

Apache Spark
lengths = words.filter(lambda word: len(word) [3] 3).map(lambda word: (word[1](), [2])).collectAsMap()
Drag options to blanks, or click blank then click option'
A.upper()
Blen(word)
C>
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of > filters wrong words.
Not transforming the word to uppercase as key.
Using the word itself instead of its length as value.