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

Jeno I. Hajdu commented on AVRO-1566:
-------------------------------------

The patch I have attached first was not complete, I have attached a new one 
which also covers the validation code.

I have check what you have mentioned, Sean. The original behaviour which is 
also advised in the guide worked perfectly, during writing the value is first 
validated and for null None is expected, so when the field type is union with 
null, null gets picked up. But when the field is not optional the value 
validation fails, resulting in an avro.io.AvroTypeException. Actually 
write_record itself is not reached in that case.

I have extended validation to follow the extended logic of using defaults (if 
value is available validate it, if not and default available we are OK 
(assuming default value is validated on schema loading, which is not checked at 
the moment there's only a TODO comment in the code ... perhaps I should add 
validating defaults), otherwise validate None (which keeps the optional field 
behaviour)). The else branch of the write_record is not used in practice, I 
have only included it for sake of completeness.

I have tried both the python 2 and 3 changes with default and optional fields.

> Use field default value to fill in missing values when serializing records
> --------------------------------------------------------------------------
>
>                 Key: AVRO-1566
>                 URL: https://issues.apache.org/jira/browse/AVRO-1566
>             Project: Avro
>          Issue Type: Improvement
>          Components: python
>            Reporter: Jeno I. Hajdu
>            Priority: Minor
>         Attachments: AVRO-1566.patch
>
>
> Field default values according to the spec are meant to fill in fields 
> present in the reader schema but missing from the writer schema during 
> deserialization. In addition to that default values could be used in the 
> writer schema to fill in missing values when serializing. This is already 
> supported in the Java implementation through record builders.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to