0
0
Apache Sparkdata~10 mins

Accumulator variables 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 create an accumulator variable named 'acc'.

Apache Spark
acc = sc.[1](0)
Drag options to blanks, or click blank then click option'
Aaccumulator
Bbroadcast
Caccum
Daccumulate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'broadcast' instead of 'accumulator'.
Trying to use a non-existent method like 'accum'.
2fill in blank
medium

Complete the code to add 1 to the accumulator variable 'acc' inside the map function.

Apache Spark
rdd.map(lambda x: (acc.[1](1), x))
Drag options to blanks, or click blank then click option'
Aupdate
Bincrement
Cincrease
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'increment' which is not a Spark accumulator method.
Using 'update' which is not valid here.
3fill in blank
hard

Fix the error in the code to correctly get the accumulator's value.

Apache Spark
print('Accumulator value:', acc.[1])
Drag options to blanks, or click blank then click option'
Avalue
BgetValue()
Cvalue()
Dget_value
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call value() as a method.
Using non-existent methods like getValue().
4fill in blank
hard

Fill both blanks to create an accumulator and add 5 to it.

Apache Spark
acc = sc.[1](0)
acc.[2](5)
Drag options to blanks, or click blank then click option'
Aaccumulator
Badd
Cbroadcast
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'broadcast' instead of 'accumulator' to create the variable.
Using 'update' instead of 'add' to increase the accumulator.
5fill in blank
hard

Fill all three blanks to create an accumulator, add 3 inside a map, and print its value.

Apache Spark
acc = sc.[1](0)
rdd.map(lambda x: acc.[2](3))
print(acc.[3])
Drag options to blanks, or click blank then click option'
Aaccumulator
Badd
Cvalue
Dbroadcast
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'broadcast' instead of 'accumulator' for creation.
Trying to call 'value()' as a method instead of property.
Using 'update' instead of 'add' to increment.