[ 
https://issues.apache.org/jira/browse/FLINK-4092?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Shahin Azad updated FLINK-4092:
-------------------------------
    Description: 
This function definition:
{code:python}
    def map(self, value):
        if isinstance(value, (tuple, list)):
            return "(" + b", ".join([self.map(x) for x in value]) + ")"
        else:
            return str(value)
{code}
in {{/resources/python/flink/plan/DataSet.py}} will raise an exception since 
implicit type conversion between {{String}} to {{Bytes}} is not possible. User 
will get following error if he tries to run the wordcount example from the 
documentation:
{code}
File 
"/tmp/flink-dist-cache-fb3d569b-c811-4065-acef-32267183aa15/f1b0eb6c0a099b22760f7300760e6e80/flink/flink/plan/Da
taSet.py", line 38, in map
    return "(" + b", ".join([self.map(x) for x in value]) + ")"
TypeError: sequence item 0: expected a bytes-like object, str found
        at 
org.apache.flink.python.api.streaming.data.PythonStreamer.streamBufferWithoutGroups(PythonStreamer.java:269)
        at 
org.apache.flink.python.api.functions.PythonMapPartition.mapPartition(PythonMapPartition.java:54)
        at 
org.apache.flink.runtime.operators.MapPartitionDriver.run(MapPartitionDriver.java:98)
        at org.apache.flink.runtime.operators.BatchTask.run(BatchTask.java:480)
        at 
org.apache.flink.runtime.operators.BatchTask.invoke(BatchTask.java:345)
        at org.apache.flink.runtime.taskmanager.Task.run(Task.java:559)
        at java.lang.Thread.run(Thread.java:745)
{code}
To resolve this issue it's enough to change {{b", "}} to a normal string by 
removing Byte conversion notation. 

  was:
This function definition:
{code:python}
    def map(self, value):
        if isinstance(value, (tuple, list)):
            return "(" + b", ".join([self.map(x) for x in value]) + ")"
        else:
            return str(value)
{code}
in `/resources/python/flink/plan/DataSet.py` will raise an exception since 
implicit type conversion between `String` to `Bytes` is not possible. User will 
get following error if he tries to run the wordcount example from the 
documentation:
{code}
File 
"/tmp/flink-dist-cache-fb3d569b-c811-4065-acef-32267183aa15/f1b0eb6c0a099b22760f7300760e6e80/flink/flink/plan/Da
taSet.py", line 38, in map
    return "(" + b", ".join([self.map(x) for x in value]) + ")"
TypeError: sequence item 0: expected a bytes-like object, str found
        at 
org.apache.flink.python.api.streaming.data.PythonStreamer.streamBufferWithoutGroups(PythonStreamer.java:269)
        at 
org.apache.flink.python.api.functions.PythonMapPartition.mapPartition(PythonMapPartition.java:54)
        at 
org.apache.flink.runtime.operators.MapPartitionDriver.run(MapPartitionDriver.java:98)
        at org.apache.flink.runtime.operators.BatchTask.run(BatchTask.java:480)
        at 
org.apache.flink.runtime.operators.BatchTask.invoke(BatchTask.java:345)
        at org.apache.flink.runtime.taskmanager.Task.run(Task.java:559)
        at java.lang.Thread.run(Thread.java:745)
{code}
To resolve this issue it's enough to change `b", "` to a normal string by 
removing Byte conversion notation. 


> Stringify map function's type conversion problem is breaking running provided 
> example in documents
> --------------------------------------------------------------------------------------------------
>
>                 Key: FLINK-4092
>                 URL: https://issues.apache.org/jira/browse/FLINK-4092
>             Project: Flink
>          Issue Type: Bug
>          Components: DataSet API, Python API
>    Affects Versions: 1.0.3
>            Reporter: Shahin Azad
>              Labels: easyfix
>
> This function definition:
> {code:python}
>     def map(self, value):
>         if isinstance(value, (tuple, list)):
>             return "(" + b", ".join([self.map(x) for x in value]) + ")"
>         else:
>             return str(value)
> {code}
> in {{/resources/python/flink/plan/DataSet.py}} will raise an exception since 
> implicit type conversion between {{String}} to {{Bytes}} is not possible. 
> User will get following error if he tries to run the wordcount example from 
> the documentation:
> {code}
> File 
> "/tmp/flink-dist-cache-fb3d569b-c811-4065-acef-32267183aa15/f1b0eb6c0a099b22760f7300760e6e80/flink/flink/plan/Da
> taSet.py", line 38, in map
>     return "(" + b", ".join([self.map(x) for x in value]) + ")"
> TypeError: sequence item 0: expected a bytes-like object, str found
>         at 
> org.apache.flink.python.api.streaming.data.PythonStreamer.streamBufferWithoutGroups(PythonStreamer.java:269)
>         at 
> org.apache.flink.python.api.functions.PythonMapPartition.mapPartition(PythonMapPartition.java:54)
>         at 
> org.apache.flink.runtime.operators.MapPartitionDriver.run(MapPartitionDriver.java:98)
>         at 
> org.apache.flink.runtime.operators.BatchTask.run(BatchTask.java:480)
>         at 
> org.apache.flink.runtime.operators.BatchTask.invoke(BatchTask.java:345)
>         at org.apache.flink.runtime.taskmanager.Task.run(Task.java:559)
>         at java.lang.Thread.run(Thread.java:745)
> {code}
> To resolve this issue it's enough to change {{b", "}} to a normal string by 
> removing Byte conversion notation. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to