Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'broadcast' instead of 'accumulator'.
Trying to use a non-existent method like 'accum'.
✗ Incorrect
The accumulator method creates an accumulator variable in Spark.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'increment' which is not a Spark accumulator method.
Using 'update' which is not valid here.
✗ Incorrect
The add method increments the accumulator by the given value.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call
value() as a method.Using non-existent methods like
getValue().✗ Incorrect
The accumulator's current value is accessed using the value property without parentheses.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'broadcast' instead of 'accumulator' to create the variable.
Using 'update' instead of 'add' to increase the accumulator.
✗ Incorrect
First, create the accumulator with accumulator. Then add 5 using add.
5fill in blank
hardFill 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'
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.
✗ Incorrect
Create the accumulator with accumulator, add 3 with add, and get the value with value.