-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-24822][PySpark] Python support for barrier execution mode #22011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2406,6 +2406,26 @@ def toLocalIterator(self): | |
| sock_info = self.ctx._jvm.PythonRDD.toLocalIteratorAndServe(self._jrdd.rdd()) | ||
| return _load_from_socket(sock_info, self._jrdd_deserializer) | ||
|
|
||
| def barrier(self): | ||
| """ | ||
| .. note:: Experimental | ||
|
|
||
| Indicates that Spark must launch the tasks together for the current stage. | ||
|
|
||
| .. versionadded:: 2.4.0 | ||
| """ | ||
| return RDDBarrier(self) | ||
|
|
||
| def isBarrier(self): | ||
|
||
| """ | ||
| .. note:: Experimental | ||
|
|
||
| Whether this RDD is in a barrier stage. | ||
|
|
||
| .. versionadded:: 2.4.0 | ||
| """ | ||
| return self._jrdd.rdd().isBarrier() | ||
|
|
||
|
|
||
| def _prepare_for_python_RDD(sc, command): | ||
| # the serialized command will be compressed by broadcast | ||
|
|
@@ -2429,6 +2449,36 @@ def _wrap_function(sc, func, deserializer, serializer, profiler=None): | |
| sc.pythonVer, broadcast_vars, sc._javaAccumulator) | ||
|
|
||
|
|
||
| class RDDBarrier(object): | ||
|
|
||
| """ | ||
| .. note:: Experimental | ||
|
|
||
| An RDDBarrier turns an RDD into a barrier RDD, which forces Spark to launch tasks of the stage | ||
|
||
| contains this RDD together. | ||
|
||
|
|
||
| .. versionadded:: 2.4.0 | ||
| """ | ||
|
|
||
| def __init__(self, rdd): | ||
| self.rdd = rdd | ||
| self._jrdd = rdd._jrdd | ||
|
|
||
| def mapPartitions(self, f, preservesPartitioning=False): | ||
|
||
| """ | ||
| .. note:: Experimental | ||
|
|
||
| Return a new RDD by applying a function to each partition of this RDD. | ||
|
|
||
| .. versionadded:: 2.4.0 | ||
| """ | ||
|
||
| def func(s, iterator): | ||
| return f(iterator) | ||
| jBarrierRdd = self._jrdd.rdd().barrier().toJavaRDD() | ||
|
||
| pyBarrierRdd = RDD(jBarrierRdd, self.rdd.ctx, self.rdd._jrdd_deserializer) | ||
| return pyBarrierRdd.mapPartitions(f, preservesPartitioning) | ||
|
|
||
|
|
||
| class PipelinedRDD(RDD): | ||
|
|
||
| """ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why we didn't mark the version so far here but we really should
.. versionadded:: 2.4.0here or