Skip to content

Commit 080541a

Browse files
committed
broke something
1 parent 0704b86 commit 080541a

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed

python/pyspark/rdd.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ def mapPartitions(self, f, preservesPartitioning=False):
283283
>>> rdd.mapPartitions(f).collect()
284284
[3, 7]
285285
"""
286-
def func(s, iterator): return f(iterator)
286+
def func(s, iterator):
287+
return f(iterator)
287288
return self.mapPartitionsWithIndex(func)
288289

289290
def mapPartitionsWithIndex(self, f, preservesPartitioning=False):

python/pyspark/streaming/context.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,23 @@ def _testInputStream(self, test_inputs, numSlices=None):
169169
jinput_stream = self._jvm.PythonTestInputStream(self._jssc,
170170
jtempFiles,
171171
numSlices).asJavaDStream()
172-
return DStream(jinput_stream, self, PickleSerializer())
173-
172+
return DStream(jinput_stream, self, BatchedSerializer(PickleSerializer()))
174173

175174
def _testInputStream2(self, test_inputs, numSlices=None):
176175
"""
177176
This is inpired by QueStream implementation. Give list of RDD and generate DStream
178177
which contain the RDD.
179178
"""
180179
test_rdds = list()
180+
test_rdd_deserializers = list()
181181
for test_input in test_inputs:
182182
test_rdd = self._sc.parallelize(test_input, numSlices)
183-
print test_rdd.glom().collect()
184183
test_rdds.append(test_rdd._jrdd)
184+
test_rdd_deserializers.append(test_rdd._jrdd_deserializer)
185185

186186
jtest_rdds = ListConverter().convert(test_rdds, SparkContext._gateway._gateway_client)
187187
jinput_stream = self._jvm.PythonTestInputStream2(self._jssc, jtest_rdds).asJavaDStream()
188188

189-
return DStream(jinput_stream, self, BatchedSerializer(PickleSerializer()))
189+
dstream = DStream(jinput_stream, self, test_rdd_deserializers[0])
190+
dstream._test_switch_dserializer(test_rdd_deserializers)
191+
return dstream

python/pyspark/streaming/dstream.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from collections import defaultdict
1919
from itertools import chain, ifilter, imap
20+
import time
2021
import operator
2122

2223
from pyspark.serializers import NoOpSerializer,\
@@ -289,6 +290,25 @@ def get_output(rdd, time):
289290

290291
self.foreachRDD(get_output)
291292

293+
def _test_switch_dserializer(self, serializer_que):
294+
"""
295+
Deserializer is dynamically changed based on numSlice and the number of
296+
input. This function choose deserializer. Currently this is just FIFO.
297+
"""
298+
299+
jrdd_deserializer = self._jrdd_deserializer
300+
301+
def switch(rdd, jtime):
302+
try:
303+
print serializer_que
304+
jrdd_deserializer = serializer_que.pop(0)
305+
print jrdd_deserializer
306+
except Exception as e:
307+
print e
308+
309+
self.foreachRDD(switch)
310+
311+
292312

293313
# TODO: implement groupByKey
294314
# TODO: impelment union

python/pyspark/streaming_tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ def test_count(self):
118118
test_input = [[], [1], range(1, 3), range(1, 4), range(1, 5)]
119119

120120
def test_func(dstream):
121+
print "count"
122+
dstream.count().pyprint()
121123
return dstream.count()
122124
expected_output = map(lambda x: [len(x)], test_input)
123125
output = self._run_stream(test_input, test_func, expected_output)

python/pyspark/worker.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import time
2424
import socket
2525
import traceback
26+
import itertools
2627
# CloudPickler needs to be imported so that depicklers are registered using the
2728
# copy_reg module.
2829
from pyspark.accumulators import _accumulatorRegistry
@@ -74,6 +75,16 @@ def main(infile, outfile):
7475
(func, deserializer, serializer) = command
7576
init_time = time.time()
7677
iterator = deserializer.load_stream(infile)
78+
print "deserializer in worker: %s" % str(deserializer)
79+
iterator, walk = itertools.tee(iterator)
80+
if isinstance(walk, int):
81+
print "this is int"
82+
print walk
83+
else:
84+
try:
85+
print list(walk)
86+
except:
87+
print list(walk)
7788
serializer.dump_stream(func(split_index, iterator), outfile)
7889
except Exception as e:
7990
# Write the error to stderr in addition to trying to pass it back to

streaming/src/main/scala/org/apache/spark/streaming/api/python/PythonDStream.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ class PythonTestInputStream(ssc_ : JavaStreamingContext, inputFiles: JArrayList[
165165
tempFile.getAbsolutePath
166166
}
167167
}
168-
println("PythonTestInputStreaming numPartitons" + numPartitions )
169168
val rdd = PythonRDD.readRDDFromFile(JavaSparkContext.fromSparkContext(ssc_.sparkContext), selectedInputFile, numPartitions).rdd
170169
logInfo("Created RDD " + rdd.id + " with " + selectedInputFile)
171170
Some(rdd)

0 commit comments

Comments
 (0)