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

Ryan Skraba commented on AVRO-2278:
-----------------------------------

Argh – the change in the PR is _better_ (in my opinion) but _different_.  We 
have a lot of in-house code that works with Avro generic records, and I ran 
this change through one of our libraries, and the different behaviour breaks 
some tests.  We have some queries that can be dynamically created to extract 
internal field values from records.

Typically, if a query fails once (because the field name is unknown) it should 
always fail, which is one reason that I think it's better to have an exception 
occur...  Rarely, the datum can be a union of two different records where the 
query might  succeed.

I was bumping from 1.8.x to a 1.10 snapshot so there were some unrelated 
compilation errors with deprecated methods being removed in 1.9.  This is 
consistent with the second number being a "major" version and at least it was 
an indication that there could be behaviour changes with 1.10.

I've got no issue with fixing *our* code with the bump, but it's a pretty big 
flag that this could break others.  There's currently a discussion on the 
mailing list about how we can encourage fixes and new features, while 
maintaining stability...

 

> GenericData.Record field getter not correct
> -------------------------------------------
>
>                 Key: AVRO-2278
>                 URL: https://issues.apache.org/jira/browse/AVRO-2278
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.8.2, 1.9.2
>            Reporter: Zoltan Farkas
>            Assignee: Zoltan Farkas
>            Priority: Major
>
> Currently the get field implementation is not correct in GenericData.Record:
> at: 
> https://github.com/apache/avro/blob/master/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java#L209
> {code}
>    @Override public Object get(String key) {
>       Field field = schema.getField(key);
>       if (field == null) return null;
>       return values[field.pos()];
>     }
> {code}
> The method returns null when a field is not present, making it impossible to 
> distinguish between:
> field value = null
> and
> field does not exist.
> A more "correct" implementation would be:
> {code}
>     @Override public Object get(String key) {
>       Field field = schema.getField(key);
>       if (field == null) {
>         throw new IllegalArgumentException("Invalid field " + key);
>       }
>       return values[field.pos()];
>     }
> {code}
> this will make the behavior consistent with put which will throw a exception 
> when setting a non existent field.
> when I make this change in my fork, some bugs in unit tests showed up....



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to