Created
October 24, 2014 17:43
-
-
Save AtlasPilotPuppy/6fdbc6a3d9a40d453397 to your computer and use it in GitHub Desktop.
accumulator example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyspark import SparkContext | |
sc = SparkContext('spark://master:7077', 'accumulator example') | |
# accumulators are initialized with a initial value | |
# they have and add method to add values to the accumulator | |
# and a value property that is visibile only to the master | |
accum = sc.accumulator(0) | |
data = sc.parallelize(range(1,1000)) | |
# we are going to iterate over our data and add each value to the | |
# accumulator | |
data.foreach(lambda value: accum.add(value)) | |
print accum.value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment