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

Marcio Silva commented on AVRO-973:
-----------------------------------

Upon further reflection, there's one issue that the current patch doesn't 
address, and that's union's containing ["float","double"].

As these are both represented as python float's there's currently no way to 
hint to the validate logic that a given python float is meant to represent a 
double. A possible solution would be to create a double class whose sole 
purpose would be to serve as that hint.

I'll generate a third patch that takes this approach, but I'm open to any other 
implementation suggestions (I'm not crazy about introducing an avro.io double 
class).
                
> Union behavior not consistent
> -----------------------------
>
>                 Key: AVRO-973
>                 URL: https://issues.apache.org/jira/browse/AVRO-973
>             Project: Avro
>          Issue Type: Bug
>          Components: python
>    Affects Versions: 1.6.1, 1.6.2
>            Reporter: Gaurav Nanda
>              Labels: patch
>         Attachments: AVRO-973-patch-1.patch, AVRO-973-patch-2.patch, 
> test_unions.py
>
>   Original Estimate: 0.25h
>  Remaining Estimate: 0.25h
>
> Python's union does not respect the order in which type is specified.
> For following schema: 
> {"type":"map","values":["int","long","float","double","string","boolean"]}, 
> an integer value is written as double, but it should respect the order in 
> which types have been specified.
> Fixed Code (io.py):
> def write_union(self, writers_schema, datum, encoder):
>    """
>    A union is encoded by first writing a long value indicating
>    the zero-based position within the union of the schema of its value.
>    The value is then encoded per the indicated schema within the union.
>    """
>    # resolve union
>    index_of_schema = -1
>    for i, candidate_schema in enumerate(writers_schema.schemas):
>      if validate(candidate_schema, datum):
>        index_of_schema = i
>        break // XXX Add break statement here XXX//
>    if index_of_schema < 0: raise AvroTypeException(writers_schema, datum)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to