5d16d5bbfd
This pull request aims to resolve all outstanding PEP8 violations in PySpark. Author: Nicholas Chammas <nicholas.chammas@gmail.com> Author: nchammas <nicholas.chammas@gmail.com> Closes #1505 from nchammas/master and squashes the following commits: 98171af [Nicholas Chammas] [SPARK-2470] revert PEP 8 fixes to cloudpickle cba7768 [Nicholas Chammas] [SPARK-2470] wrap expression list in parentheses e178dbe [Nicholas Chammas] [SPARK-2470] style - change position of line break 9127d2b [Nicholas Chammas] [SPARK-2470] wrap expression lists in parentheses 22132a4 [Nicholas Chammas] [SPARK-2470] wrap conditionals in parentheses 24639bc [Nicholas Chammas] [SPARK-2470] fix whitespace for doctest 7d557b7 [Nicholas Chammas] [SPARK-2470] PEP8 fixes to tests.py 8f8e4c0 [Nicholas Chammas] [SPARK-2470] PEP8 fixes to storagelevel.py b3b96cf [Nicholas Chammas] [SPARK-2470] PEP8 fixes to statcounter.py d644477 [Nicholas Chammas] [SPARK-2470] PEP8 fixes to worker.py aa3a7b6 [Nicholas Chammas] [SPARK-2470] PEP8 fixes to sql.py 1916859 [Nicholas Chammas] [SPARK-2470] PEP8 fixes to shell.py 95d1d95 [Nicholas Chammas] [SPARK-2470] PEP8 fixes to serializers.py a0fec2e [Nicholas Chammas] [SPARK-2470] PEP8 fixes to mllib c85e1e5 [Nicholas Chammas] [SPARK-2470] PEP8 fixes to join.py d14f2f1 [Nicholas Chammas] [SPARK-2470] PEP8 fixes to __init__.py 81fcb20 [Nicholas Chammas] [SPARK-2470] PEP8 fixes to resultiterable.py 1bde265 [Nicholas Chammas] [SPARK-2470] PEP8 fixes to java_gateway.py 7fc849c [Nicholas Chammas] [SPARK-2470] PEP8 fixes to daemon.py ca2d28b [Nicholas Chammas] [SPARK-2470] PEP8 fixes to context.py f4e0039 [Nicholas Chammas] [SPARK-2470] PEP8 fixes to conf.py a6d5e4b [Nicholas Chammas] [SPARK-2470] PEP8 fixes to cloudpickle.py f0a7ebf [Nicholas Chammas] [SPARK-2470] PEP8 fixes to rddsampler.py 4dd148f [nchammas] Merge pull request #5 from apache/master f7e4581 [Nicholas Chammas] unrelated pep8 fix a36eed0 [Nicholas Chammas] name ec2 instances and security groups consistently de7292a [nchammas] Merge pull request #4 from apache/master 2e4fe00 [nchammas] Merge pull request #3 from apache/master 89fde08 [nchammas] Merge pull request #2 from apache/master 69f6e22 [Nicholas Chammas] PEP8 fixes 2627247 [Nicholas Chammas] broke up lines before they hit 100 chars 6544b7e [Nicholas Chammas] [SPARK-2065] give launched instances names 69da6cf [nchammas] Merge pull request #1 from apache/master
96 lines
3.4 KiB
Python
96 lines
3.4 KiB
Python
"""
|
|
Copyright (c) 2011, Douban Inc. <http://www.douban.com/>
|
|
All rights reserved.
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
modification, are permitted provided that the following conditions are
|
|
met:
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
in the documentation and/or other materials provided with the
|
|
distribution.
|
|
|
|
* Neither the name of the Douban Inc. nor the names of its
|
|
contributors may be used to endorse or promote products derived from
|
|
this software without specific prior written permission.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
"""
|
|
|
|
from pyspark.resultiterable import ResultIterable
|
|
|
|
|
|
def _do_python_join(rdd, other, numPartitions, dispatch):
|
|
vs = rdd.map(lambda (k, v): (k, (1, v)))
|
|
ws = other.map(lambda (k, v): (k, (2, v)))
|
|
return vs.union(ws).groupByKey(numPartitions).flatMapValues(lambda x: dispatch(x.__iter__()))
|
|
|
|
|
|
def python_join(rdd, other, numPartitions):
|
|
def dispatch(seq):
|
|
vbuf, wbuf = [], []
|
|
for (n, v) in seq:
|
|
if n == 1:
|
|
vbuf.append(v)
|
|
elif n == 2:
|
|
wbuf.append(v)
|
|
return [(v, w) for v in vbuf for w in wbuf]
|
|
return _do_python_join(rdd, other, numPartitions, dispatch)
|
|
|
|
|
|
def python_right_outer_join(rdd, other, numPartitions):
|
|
def dispatch(seq):
|
|
vbuf, wbuf = [], []
|
|
for (n, v) in seq:
|
|
if n == 1:
|
|
vbuf.append(v)
|
|
elif n == 2:
|
|
wbuf.append(v)
|
|
if not vbuf:
|
|
vbuf.append(None)
|
|
return [(v, w) for v in vbuf for w in wbuf]
|
|
return _do_python_join(rdd, other, numPartitions, dispatch)
|
|
|
|
|
|
def python_left_outer_join(rdd, other, numPartitions):
|
|
def dispatch(seq):
|
|
vbuf, wbuf = [], []
|
|
for (n, v) in seq:
|
|
if n == 1:
|
|
vbuf.append(v)
|
|
elif n == 2:
|
|
wbuf.append(v)
|
|
if not wbuf:
|
|
wbuf.append(None)
|
|
return [(v, w) for v in vbuf for w in wbuf]
|
|
return _do_python_join(rdd, other, numPartitions, dispatch)
|
|
|
|
|
|
def python_cogroup(rdds, numPartitions):
|
|
def make_mapper(i):
|
|
return lambda (k, v): (k, (i, v))
|
|
vrdds = [rdd.map(make_mapper(i)) for i, rdd in enumerate(rdds)]
|
|
union_vrdds = reduce(lambda acc, other: acc.union(other), vrdds)
|
|
rdd_len = len(vrdds)
|
|
|
|
def dispatch(seq):
|
|
bufs = [[] for i in range(rdd_len)]
|
|
for (n, v) in seq:
|
|
bufs[n].append(v)
|
|
return tuple(map(ResultIterable, bufs))
|
|
return union_vrdds.groupByKey(numPartitions).mapValues(dispatch)
|