Skip to content

Commit 9ef1896

Browse files
committed
Recover earlier changes lost in previous merge for serializers.py
1 parent 077ecb2 commit 9ef1896

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

python/pyspark/serializers.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
from itertools import chain, izip, product
6565
import marshal
6666
import struct
67+
import sys
6768
from pyspark import cloudpickle
6869

6970

@@ -113,6 +114,11 @@ class FramedSerializer(Serializer):
113114
where C{length} is a 32-bit integer and data is C{length} bytes.
114115
"""
115116

117+
def __init__(self):
118+
# On Python 2.6, we can't write bytearrays to streams, so we need to convert them
119+
# to strings first. Check if the version number is that old.
120+
self._only_write_strings = sys.version_info[0:2] <= (2, 6)
121+
116122
def dump_stream(self, iterator, stream):
117123
for obj in iterator:
118124
self._write_with_length(obj, stream)
@@ -127,7 +133,10 @@ def load_stream(self, stream):
127133
def _write_with_length(self, obj, stream):
128134
serialized = self.dumps(obj)
129135
write_int(len(serialized), stream)
130-
stream.write(serialized)
136+
if self._only_write_strings:
137+
stream.write(str(serialized))
138+
else:
139+
stream.write(serialized)
131140

132141
def _read_with_length(self, stream):
133142
length = read_int(stream)
@@ -290,7 +299,7 @@ class MarshalSerializer(FramedSerializer):
290299

291300
class UTF8Deserializer(Serializer):
292301
"""
293-
Deserializes streams written by getBytes.
302+
Deserializes streams written by String.getBytes.
294303
"""
295304

296305
def loads(self, stream):

0 commit comments

Comments
 (0)