spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mateiz <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-2538] [PySpark] Hash based disk spillin...
Date Thu, 17 Jul 2014 17:59:13 GMT
Github user mateiz commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1460#discussion_r15073144
  
    --- Diff: python/pyspark/serializers.py ---
    @@ -297,6 +297,33 @@ class MarshalSerializer(FramedSerializer):
         loads = marshal.loads
     
     
    +class AutoSerializer(FramedSerializer):
    +    """
    +    Choose marshal or cPickle as serialization protocol autumatically
    +    """
    +    def __init__(self):
    +        FramedSerializer.__init__(self)
    +        self._type = None
    +
    +    def dumps(self, obj):
    +        try:
    +            if self._type is not None:
    +                raise TypeError("fallback")
    +            return 'M' + marshal.dumps(obj)
    +        except Exception:
    +            self._type = 'P'
    +            return 'P' + cPickle.dumps(obj, -1)
    +
    +    def loads(self, stream):
    +        _type = stream[0]
    +        if _type == 'M':
    +            return marshal.loads(stream[1:])
    +        elif _type == 'P':
    +            return cPickle.loads(stream[1:])
    --- End diff --
    
    Seems to be more efficient to read a byte with stream.read(1) than to index into the stream,
but I'm not sure


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message