GitHub user zsxwing opened a pull request:

    https://github.com/apache/spark/pull/11535

    [SPARK-13697][PySpark]Fix the missing module name of 
TransformFunctionSerializer.loads

    ## What changes were proposed in this pull request?
    
    Set the function's module name to `__main__` if it's missing in 
`TransformFunctionSerializer.loads`.
    
    ## How was this patch tested?
    
    Manually test in the shell.
    
    Before this patch:
    ```
    >>> from pyspark.streaming import StreamingContext
    >>> from pyspark.streaming.util import TransformFunction
    >>> ssc = StreamingContext(sc, 1)
    >>> func = TransformFunction(sc, lambda x: x, sc.serializer)
    >>> func.rdd_wrapper(lambda x: x)
    TransformFunction(<function <lambda> at 0x106ac8b18>)
    >>> bytes = 
bytearray(ssc._transformerSerializer.serializer.dumps((func.func, 
func.rdd_wrap_func, func.deserializers))) 
    >>> func2 = ssc._transformerSerializer.loads(bytes)
    >>> print(func2.func.__module__)
    None
    >>> print(func2.rdd_wrap_func.__module__)
    None
    >>> 
    ```
    After this patch:
    ```
    >>> from pyspark.streaming import StreamingContext
    >>> from pyspark.streaming.util import TransformFunction
    >>> ssc = StreamingContext(sc, 1)
    >>> func = TransformFunction(sc, lambda x: x, sc.serializer)
    >>> func.rdd_wrapper(lambda x: x)
    TransformFunction(<function <lambda> at 0x108bf1b90>)
    >>> bytes = 
bytearray(ssc._transformerSerializer.serializer.dumps((func.func, 
func.rdd_wrap_func, func.deserializers))) 
    >>> func2 = ssc._transformerSerializer.loads(bytes)
    >>> print(func2.func.__module__)
    __main__
    >>> print(func2.rdd_wrap_func.__module__)
    __main__
    >>> 
    ```
    


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/zsxwing/spark loads-module

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/11535.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #11535
    
----
commit c4e35ff068e269935ae96e5ab25b4ae94cc02b0b
Author: Shixiong Zhu <[email protected]>
Date:   2016-03-05T08:14:24Z

    Fix the missing module name of TransformFunctionSerializer.loads

----


---
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