Repository: spark
Updated Branches:
  refs/heads/branch-1.2 473777ef2 -> 4a550acb2


[SPARK-733] Add documentation on use of accumulators in lazy transformation

I've added documentation clarifying the particular lack of clarity highlighted 
in the relevant JIRA. I've also added code examples for this issue to clarify 
the explanation.

Author: Ilya Ganelin <[email protected]>

Closes #4022 from ilganeli/SPARK-733 and squashes the following commits:

587def5 [Ilya Ganelin] Updated to clarify verbage
df3afd7 [Ilya Ganelin] Revert "Partially updated task metrics to make some vars 
private"
3f6c512 [Ilya Ganelin] Revert "Completed refactoring to make vars in 
TaskMetrics class private"
58034fb [Ilya Ganelin] Merge remote-tracking branch 'upstream/master' into 
SPARK-733
4dc2cdb [Ilya Ganelin] Merge remote-tracking branch 'upstream/master' into 
SPARK-733
3a38db1 [Ilya Ganelin] Verified documentation update by building via jekyll
33b5a2d [Ilya Ganelin] Added code examples for java and python
1fd59b2 [Ilya Ganelin] Updated documentation for accumulators to highlight lazy 
evaluation issue
5525c20 [Ilya Ganelin] Completed refactoring to make vars in TaskMetrics class 
private
c64da4f [Ilya Ganelin] Partially updated task metrics to make some vars private

(cherry picked from commit fd3a8a1d15ad516ea056089e30d6fd14e2f2d9a1)
Signed-off-by: Imran Rashid <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/4a550acb
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/4a550acb
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/4a550acb

Branch: refs/heads/branch-1.2
Commit: 4a550acb28530ed69c0b5d84f850eb94e61968e1
Parents: 473777e
Author: Ilya Ganelin <[email protected]>
Authored: Fri Jan 16 13:25:17 2015 -0800
Committer: Imran Rashid <[email protected]>
Committed: Fri Jan 16 13:25:47 2015 -0800

----------------------------------------------------------------------
 docs/programming-guide.md | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/4a550acb/docs/programming-guide.md
----------------------------------------------------------------------
diff --git a/docs/programming-guide.md b/docs/programming-guide.md
index 0211bba..2443fc2 100644
--- a/docs/programming-guide.md
+++ b/docs/programming-guide.md
@@ -1316,7 +1316,35 @@ For accumulator updates performed inside <b>actions 
only</b>, Spark guarantees t
 will only be applied once, i.e. restarted tasks will not update the value. In 
transformations, users should be aware 
 of that each task's update may be applied more than once if tasks or job 
stages are re-executed.
 
+Accumulators do not change the lazy evaluation model of Spark. If they are 
being updated within an operation on an RDD, their value is only updated once 
that RDD is computed as part of an action. Consequently, accumulator updates 
are not guaranteed to be executed when made within a lazy transformation like 
`map()`. The below code fragment demonstrates this property:
 
+<div class="codetabs">
+
+<div data-lang="scala"  markdown="1">
+{% highlight scala %}
+val acc = sc.accumulator(0)
+data.map(x => acc += x; f(x))
+// Here, acc is still 0 because no actions have cause the `map` to be computed.
+{% endhighlight %}
+</div>
+
+<div data-lang="java"  markdown="1">
+{% highlight java %}
+Accumulator<Integer> accum = sc.accumulator(0);
+data.map(x -> accum.add(x); f(x););
+// Here, accum is still 0 because no actions have cause the `map` to be 
computed.
+{% endhighlight %}
+</div>
+
+<div data-lang="python"  markdown="1">
+{% highlight python %}
+accum = sc.accumulator(0)
+data.map(lambda x => acc.add(x); f(x))
+# Here, acc is still 0 because no actions have cause the `map` to be computed.
+{% endhighlight %}
+</div>
+
+</div>
 
 # Deploying to a Cluster
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to