[ 
https://issues.apache.org/jira/browse/AVRO-2154?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16387641#comment-16387641
 ] 

Usman Shahid commented on AVRO-2154:
------------------------------------

The problem occurs on python client in the `DatumWriter.write_union()` method. 
The method iterates over all the types in a union and performs an 
`isinstance()` on the value with each type. Incidentally, due to [python design 
decision regarding booleans|https://www.python.org/dev/peps/pep-0285/], 
`isinstance(True, int)` returns `True` to maintain backward compatibility and 
since the loop in `write_union` doesn't break, the type that returns true last 
in the sequence of the union gets selected. If we reverse the sequence of the 
types in the union definition, it works fine and a boolean is returned on the 
server side.

> Python to Java IPC converts boolean inside a union to integer
> -------------------------------------------------------------
>
>                 Key: AVRO-2154
>                 URL: https://issues.apache.org/jira/browse/AVRO-2154
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.8.2
>         Environment: macOS 10.13.3
> Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
> Python 2.7.10
>            Reporter: Usman Shahid
>            Priority: Major
>
> Using the following IDL:
> {code:java}
> @namespace("us.codemug")
> protocol BooleanTestProtocol {
>   void booleanInUnion(union{boolean, int, string} myunion);
> }
> {code}
> and the following Java implementation:
> {code:java}
> package us.codemug;
> import java.util.Map;
> import org.apache.avro.AvroRemoteException;
> public class BooleanTestResponder implements BooleanTestProtocol {
>   public Void booleanInUnion(Object myunion) throws AvroRemoteException {
>     print(myunion);
>     return null;
>   }
>   private void print(Object value) {
>     System.out.println("Type: " + value.getClass().getName());
>     System.out.println("Value: " + value);
>   }
> }
> {code}
> When performing the IPC from python with the input:
> {code}
> args = dict()
> args['myunion'] = True
> requestor.request('booleanInUnion', args)
> {code}
> Produces this output at the server side:
> {code:java}
> Type: java.lang.Integer
> Value: 1
> {code}
> The booleans are being converted to integers



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to