You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "shiraeeshi (JIRA)" <ji...@apache.org> on 2016/06/07 08:16:21 UTC

[jira] [Comment Edited] (AVRO-1777) Select best matching record when writing a union in python

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

shiraeeshi edited comment on AVRO-1777 at 6/7/16 8:16 AM:
----------------------------------------------------------

I believe my PR is relevant to this issue.

https://github.com/apache/avro/pull/95

Following the Java logic, I've added the GenericRecord type that stores the schema.


was (Author: shiraeeshi):
I believe my PR is relevant to this issue.

https://github.com/apache/avro/pull/95

Following the Java logic, I've added the GenericRecord type that stores schema.

> Select best matching record when writing a union in python
> ----------------------------------------------------------
>
>                 Key: AVRO-1777
>                 URL: https://issues.apache.org/jira/browse/AVRO-1777
>             Project: Avro
>          Issue Type: Improvement
>          Components: python
>    Affects Versions: 1.7.7
>            Reporter: Steven Aerts
>
> Unlike javascript, python is not using wrapped types.
> So when writing a union it needs to guess find out which type it will output.
> At the moment it takes the last validating type.
> I propose to take the type with the most matching fields.
> So I propose to change in {{io.py}}:
> {code}
> # resolve union
> index_of_schema = -1
> for i, candidate_schema in enumerate(writers_schema.schemas):
>   if validate(candidate_schema, datum):
>     index_of_schema = i
> if index_of_schema < 0: raise AvroTypeException(writers_schema, datum)
> {code}
> into
> {code}
> # resolve union
> index_of_schema = -1
> found_fields = -1
> for i, candidate_schema in enumerate(writers_schema.schemas):
>   if validate(candidate_schema, datum):
>     nr_fields = candidate_schema.type in ['record', 'error', 'request'] and len(candidate_schema.fields) or 1
>     if nr_fields > found_fields:
>       index_of_schema = i
>       found_fields = nr_fields
> if index_of_schema < 0: raise AvroTypeException(writers_schema, datum)
> {code}
> If you want, I can create a pull request for this.  And apply it both on py3 as py.



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