Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 29.4k
[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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2406,6 +2406,22 @@ 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 _is_barrier(self): | ||
| """ | ||
| Whether this RDD is in a barrier stage. | ||
| """ | ||
| return self._jrdd.rdd().isBarrier() | ||
| def _prepare_for_python_RDD(sc, command): | ||
| # the serialized command will be compressed by broadcast | ||
| @@ -2429,6 +2445,33 @@ 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 | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: | ||
| contains this RDD together. | ||
| ||
| .. versionadded:: 2.4.0 | ||
| """ | ||
| def __init__(self, rdd): | ||
| self.rdd = rdd | ||
| 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) | ||
| return PipelinedRDD(self.rdd, func, preservesPartitioning, isFromBarrier=True) | ||
| class PipelinedRDD(RDD): | ||
| """ | ||
| @@ -2448,7 +2491,7 @@ class PipelinedRDD(RDD): | ||
| 20 | ||
| """ | ||
| def __init__(self, prev, func, preservesPartitioning=False): | ||
| def __init__(self, prev, func, preservesPartitioning=False, isFromBarrier=False): | ||
| if not isinstance(prev, PipelinedRDD) or not prev._is_pipelinable(): | ||
| # This transformation is the first in its stage: | ||
| self.func = func | ||
| @@ -2474,6 +2517,7 @@ def pipeline_func(split, iterator): | ||
| self._jrdd_deserializer = self.ctx.serializer | ||
| self._bypass_serializer = False | ||
| self.partitioner = prev.partitioner if self.preservesPartitioning else None | ||
| self.is_barrier = prev._is_barrier() or isFromBarrier | ||
| def getNumPartitions(self): | ||
| return self._prev_jrdd.partitions().size() | ||
| @@ -2493,7 +2537,7 @@ def _jrdd(self): | ||
| wrapped_func = _wrap_function(self.ctx, self.func, self._prev_jrdd_deserializer, | ||
| self._jrdd_deserializer, profiler) | ||
| python_rdd = self.ctx._jvm.PythonRDD(self._prev_jrdd.rdd(), wrapped_func, | ||
| self.preservesPartitioning) | ||
| self.preservesPartitioning, self.is_barrier) | ||
| self._jrdd_val = python_rdd.asJavaRDD() | ||
| if profiler: | ||
| @@ -2509,6 +2553,9 @@ def id(self): | ||
| def _is_pipelinable(self): | ||
| return not (self.is_cached or self.is_checkpointed) | ||
| def _is_barrier(self): | ||
| return self.is_barrier | ||
| def _test(): | ||
| import doctest | ||
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