Github user JoshRosen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2659#discussion_r18613782
  
    --- Diff: python/pyspark/serializers.py ---
    @@ -452,20 +454,182 @@ def loads(self, obj):
                 raise ValueError("invalid sevialization type: %s" % _type)
     
     
    -class CompressedSerializer(FramedSerializer):
    +class SizeLimitedStream(object):
         """
    -    Compress the serialized data
    +    Read at most `limit` bytes from underline stream
    +
    +    >>> from StringIO import StringIO
    +    >>> io = StringIO()
    +    >>> io.write("Hello world")
    +    >>> io.seek(0)
    +    >>> lio = SizeLimitedStream(io, 5)
    +    >>> lio.read()
    +    'Hello'
    +    """
    +    def __init__(self, stream, limit):
    +        self.stream = stream
    +        self.limit = limit
    +
    +    def read(self, n=0):
    +        if n > self.limit or n == 0:
    +            n = self.limit
    +        buf = self.stream.read(n)
    +        self.limit -= len(buf)
    +        return buf
    +
    +
    +class CompressedStream(object):
    +    """
    +    Compress the data using zlib
    +
    +    >>> from StringIO import StringIO
    +    >>> io = StringIO()
    +    >>> wio = CompressedStream(io, 'w')
    +    >>> wio.write("Hello world")
    +    >>> wio.flush()
    +    >>> io.seek(0)
    +    >>> rio = CompressedStream(io, 'r')
    +    >>> rio.read()
    +    'Hello world'
    +    """
    +    MAX_BATCH = 1 << 20
    --- End diff --
    
    Maybe add a comment next to this line saying "1 megabyte"?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to