Skip to content
Snippets Groups Projects
Commit 56f57f89 authored by Mortada Mehyar's avatar Mortada Mehyar Committed by Sean Owen
Browse files

[SPARK-12760][DOCS] invalid lambda expression in python example for …

…local vs cluster

srowen thanks for the PR at https://github.com/apache/spark/pull/10866! sorry it took me a while.

This is related to https://github.com/apache/spark/pull/10866, basically the assignment in the lambda expression in the python example is actually invalid

```
In [1]: data = [1, 2, 3, 4, 5]
In [2]: counter = 0
In [3]: rdd = sc.parallelize(data)
In [4]: rdd.foreach(lambda x: counter += x)
  File "<ipython-input-4-fcb86c182bad>", line 1
    rdd.foreach(lambda x: counter += x)
                                   ^
SyntaxError: invalid syntax
```

Author: Mortada Mehyar <mortada.mehyar@gmail.com>

Closes #10867 from mortada/doc_python_fix.
parent 358a33bb
No related branches found
No related tags found
No related merge requests found
...@@ -789,9 +789,12 @@ counter = 0 ...@@ -789,9 +789,12 @@ counter = 0
rdd = sc.parallelize(data) rdd = sc.parallelize(data)
# Wrong: Don't do this!! # Wrong: Don't do this!!
rdd.foreach(lambda x: counter += x) def increment_counter(x):
global counter
counter += x
rdd.foreach(increment_counter)
print("Counter value: " + counter) print("Counter value: ", counter)
{% endhighlight %} {% endhighlight %}
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment