[jira] [Commented] (AVRO-2278) GenericData.Record field getter not correct

2020-04-23 Thread Zoltan Farkas (Jira)


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

Zoltan Farkas commented on AVRO-2278:
-

Created PR: https://github.com/apache/avro/pull/864

> 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
>Reporter: 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)


[jira] [Commented] (AVRO-2278) GenericData.Record field getter not correct

2020-04-27 Thread Ryan Skraba (Jira)


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

Ryan Skraba commented on AVRO-2278:
---

It *would* be more consistent:
 * For get/put by index, with an invalid index, a GenericRecord will throw an 
{{IndexOutOfBoundsException}}
 * For get/put by index, with an invalid index, a SpecificRecord will throw an 
{{AvroRuntimeException("Bad index")}}
 * For get/put by name, with an invalid name, a SpecificRecord will throw a 
{{NullPointerException}} (!!)
 * As noted, put by name with an invalid name will throw an 
{{AvroRuntimeException("Not a valid schema field: " + key)}}

It would even be more consistent if they all threw {{AvroRuntimeException}}

Expecting  *{{get("badFieldName")}}* to return null successfully (as if it were 
a Java Map) is probably smelly code.  Any opinions?

Unfortunately, the behaviour of these methods is currently undocumented, and a 
change could cause working code to break.

The correct way to determine whether a key exists today is probably still 
{{record.getSchema().getField(key) != null}}.

> 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
>Reporter: 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)


[jira] [Commented] (AVRO-2278) GenericData.Record field getter not correct

2020-04-28 Thread Zoltan Farkas (Jira)


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

Zoltan Farkas commented on AVRO-2278:
-

[~rskraba] Excellent points!
I would make all accesses by index to throw IndexOutOfBoundsException 
consistently. The exception I think is a better fit for this scenario.
The SpecificRecord access by name NPE behavior needs to be changed to be in 
sync with the GenericRecord.

The change in behavior might break apps, which is why we would make this change 
in a release where at lear the minor version number changes.

Will update the PR with your suggestions.

> 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
>Reporter: 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)


[jira] [Commented] (AVRO-2278) GenericData.Record field getter not correct

2020-04-28 Thread Zoltan Farkas (Jira)


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

Zoltan Farkas commented on AVRO-2278:
-

updated PR.

> 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
>Reporter: 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)


[jira] [Commented] (AVRO-2278) GenericData.Record field getter not correct

2020-05-06 Thread Ryan Skraba (Jira)


[ 
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)


[jira] [Commented] (AVRO-2278) GenericData.Record field getter not correct

2020-05-06 Thread Zoltan Farkas (Jira)


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

Zoltan Farkas commented on AVRO-2278:
-

[~rskraba] what about controlling this behavior with a System Property? 

> 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)


[jira] [Commented] (AVRO-2278) GenericData.Record field getter not correct

2020-05-06 Thread Ryan Skraba (Jira)


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

Ryan Skraba commented on AVRO-2278:
---

I think feature flags or system properties are a good tool!  We've already got 
some in place for experiments (currently set to false and hopefully will be 
true in the future): 
https://cwiki.apache.org/confluence/display/AVRO/Experimental+features+in+Avro

How do you think it would work here?  Would we have one flag for all API 
changes that we'd like to see appear in a "big bump" or one per-change?  
Documented with experiments?

Since the next release is 1.10.x (pretty soon), maybe we can use this 
particular clean-up as an experiment?

> 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)


[jira] [Commented] (AVRO-2278) GenericData.Record field getter not correct

2020-05-06 Thread Zoltan Farkas (Jira)


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

Zoltan Farkas commented on AVRO-2278:
-

There is basically one behavior that we are changing here significantly: 
GenericData.Record.get(String) will throw an exception  instead of returning 
null when querying record for an invalid field. The other changes are 
cleanup... (we are throwing AvroRuntimeException instead of NPE).

So if we decide to protect this via a feature flag, we should only do this for 
GenericData.Record.get(String) 

we should also not forget that currently the 2 implementations of 
GenericRecord.get(String):

GenericData.Record.get(String)
SpecificRecordBase.get(String)

are inconsistent in behavior... one returns null for non-existent field, the 
other throws a NPE... so you can't rely on current behavior for 
GenericRecord.get...

But since we are talking here about 1.10 and not 1.8.x and 1.9.x, where users 
will not expect API compatibility, I think in this specific scenario, a feature 
flag will add more complexity for not much benefit...

how can we get more people to chime in? 

> 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)


[jira] [Commented] (AVRO-2278) GenericData.Record field getter not correct

2020-05-08 Thread Andy Le (Jira)


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

Andy Le commented on AVRO-2278:
---

[~zolyfarkas] [~rskraba] I think there are 2 other options:
 * Opt #1. Introduce Schema.exist(key) to verify if a key is valid, no change 
to Schema.get(key)
 * Opt #2. Introduce a more consistent way in Schema.fetch(key) and mark 
Schema.get(key) as deprecated.

> 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)


[jira] [Commented] (AVRO-2278) GenericData.Record field getter not correct

2020-05-09 Thread Zoltan Farkas (Jira)


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

Zoltan Farkas commented on AVRO-2278:
-

[~anhldbk] to clarify we are discussing here the semantics of GenericRecord.get.

regarding Opt #1, existence of a field can already be checked with: 
GenericRecord.getSchema().getField(String) !=null.

In both instances,  leaving get as is in my opinion is a bad idea, it has the 
potential to hide bugs, and I would think that is not something people want to 
do...


> 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)


[jira] [Commented] (AVRO-2278) GenericData.Record field getter not correct

2020-05-22 Thread ASF subversion and git services (Jira)


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

ASF subversion and git services commented on AVRO-2278:
---

Commit 3a098e8be4944216f811211c9e3240fd6f67a4ae in avro's branch 
refs/heads/master from Zoltan Farkas
[ https://gitbox.apache.org/repos/asf?p=avro.git;h=3a098e8 ]

[AVRO-2278] getter semantics confusing. (#864)

* [fix] getter semantics confusing.

impossible to distinguish between a correct field with the value null.
and a nonsense field.

* [fix]delete soem generated class

* [fix]delete soem generated class

* [fix]delete soem generated class

* [add] sync up exception behavior for consistency, and better messages.

* [add] helper method.

> 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)


[jira] [Commented] (AVRO-2278) GenericData.Record field getter not correct

2020-05-22 Thread Hudson (Jira)


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

Hudson commented on AVRO-2278:
--

FAILURE: Integrated in Jenkins build AvroJava #883 (See 
[https://builds.apache.org/job/AvroJava/883/])
[AVRO-2278] getter semantics confusing. (#864) (github: 
[https://github.com/apache/avro/commit/3a098e8be4944216f811211c9e3240fd6f67a4ae])
* (edit) 
lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/FieldTest.java
* (edit) lang/java/avro/src/main/java/org/apache/avro/generic/GenericRecord.java
* (edit) 
lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
* (edit) 
lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/Player.java
* (edit) lang/java/tools/src/test/compiler/output/Player.java
* (edit) lang/java/avro/src/test/java/org/apache/avro/TestSchemaBuilder.java
* (edit) 
lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java
* (edit) lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
* (edit) 
lang/java/avro/src/main/java/org/apache/avro/specific/SpecificRecordBase.java
* (edit) 
lang/java/avro/src/test/java/org/apache/avro/TestReadingWritingDataInEvolvedSchemas.java


> 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
> Fix For: 1.10.0
>
>
> 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)


[jira] [Commented] (AVRO-2278) GenericData.Record field getter not correct

2020-05-22 Thread ASF subversion and git services (Jira)


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

ASF subversion and git services commented on AVRO-2278:
---

Commit 3a098e8be4944216f811211c9e3240fd6f67a4ae in avro's branch 
refs/heads/AVRO-2806 from Zoltan Farkas
[ https://gitbox.apache.org/repos/asf?p=avro.git;h=3a098e8 ]

[AVRO-2278] getter semantics confusing. (#864)

* [fix] getter semantics confusing.

impossible to distinguish between a correct field with the value null.
and a nonsense field.

* [fix]delete soem generated class

* [fix]delete soem generated class

* [fix]delete soem generated class

* [add] sync up exception behavior for consistency, and better messages.

* [add] helper method.

> 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
> Fix For: 1.10.0
>
>
> 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)