You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Kevin Oliver (JIRA)" <ji...@apache.org> on 2010/01/19 18:45:55 UTC
[jira] Created: (AVRO-350) NPE on GenericData.Record.get(String)
for a field that doesn't exist
NPE on GenericData.Record.get(String) for a field that doesn't exist
--------------------------------------------------------------------
Key: AVRO-350
URL: https://issues.apache.org/jira/browse/AVRO-350
Project: Avro
Issue Type: Sub-task
Components: java
Affects Versions: 1.3.0
Reporter: Kevin Oliver
After the change in AVRO-278 to use arrays, GenericData.Record.get() gives an NPE if you ask for a field that doesn't exist in the schema.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (AVRO-350) NPE on GenericData.Record.get(String)
for a field that doesn't exist
Posted by "Kevin Oliver (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/AVRO-350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12802418#action_12802418 ]
Kevin Oliver commented on AVRO-350:
-----------------------------------
There is a tradeoff with isSet(). If you don't know if the field is in a schema, you would then need to always precede every call to get() with isSet().
I tend to think of the GenericRecords as modeling a map, but maybe that is not the right approach.
A compromise might be returning null when not set, and if an application is interested, they can see if the value isSet(). That feels like a nice balance between performance and features.
> NPE on GenericData.Record.get(String) for a field that doesn't exist
> --------------------------------------------------------------------
>
> Key: AVRO-350
> URL: https://issues.apache.org/jira/browse/AVRO-350
> Project: Avro
> Issue Type: Sub-task
> Components: java
> Affects Versions: 1.3.0
> Reporter: Kevin Oliver
> Attachments: AVRO-350.patch
>
>
> After the change in AVRO-278 to use arrays, GenericData.Record.get() gives an NPE if you ask for a field that doesn't exist in the schema.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (AVRO-350) NPE on GenericData.Record.get(String)
for a field that doesn't exist
Posted by "Doug Cutting (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/AVRO-350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12805614#action_12805614 ]
Doug Cutting commented on AVRO-350:
-----------------------------------
+1 This patch looks fine to me.
> NPE on GenericData.Record.get(String) for a field that doesn't exist
> --------------------------------------------------------------------
>
> Key: AVRO-350
> URL: https://issues.apache.org/jira/browse/AVRO-350
> Project: Avro
> Issue Type: Sub-task
> Components: java
> Affects Versions: 1.3.0
> Reporter: Kevin Oliver
> Attachments: AVRO-350.patch
>
>
> After the change in AVRO-278 to use arrays, GenericData.Record.get() gives an NPE if you ask for a field that doesn't exist in the schema.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (AVRO-350) NPE on GenericData.Record.get(String)
for a field that doesn't exist
Posted by "Kevin Oliver (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/AVRO-350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12805599#action_12805599 ]
Kevin Oliver commented on AVRO-350:
-----------------------------------
Any thoughts on an approach here for a patch?
Another option I thought of would be adding a flag to the constructor, boolean nullForUnknownFields and using that to determine the behavior. If you want stricter upfront checks, then you'd use false, and if you want more of a map-like behavior, you'd use true. We could have the existing constructor use the appropriate default value.
> NPE on GenericData.Record.get(String) for a field that doesn't exist
> --------------------------------------------------------------------
>
> Key: AVRO-350
> URL: https://issues.apache.org/jira/browse/AVRO-350
> Project: Avro
> Issue Type: Sub-task
> Components: java
> Affects Versions: 1.3.0
> Reporter: Kevin Oliver
> Attachments: AVRO-350.patch
>
>
> After the change in AVRO-278 to use arrays, GenericData.Record.get() gives an NPE if you ask for a field that doesn't exist in the schema.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (AVRO-350) NPE on GenericData.Record.get(String)
for a field that doesn't exist
Posted by "Kevin Oliver (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/AVRO-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Kevin Oliver updated AVRO-350:
------------------------------
Attachment: AVRO-350.patch
> NPE on GenericData.Record.get(String) for a field that doesn't exist
> --------------------------------------------------------------------
>
> Key: AVRO-350
> URL: https://issues.apache.org/jira/browse/AVRO-350
> Project: Avro
> Issue Type: Sub-task
> Components: java
> Affects Versions: 1.3.0
> Reporter: Kevin Oliver
> Attachments: AVRO-350.patch
>
>
> After the change in AVRO-278 to use arrays, GenericData.Record.get() gives an NPE if you ask for a field that doesn't exist in the schema.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (AVRO-350) NPE on GenericData.Record.get(String)
for a field that doesn't exist
Posted by "Kevin Oliver (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/AVRO-350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12802911#action_12802911 ]
Kevin Oliver commented on AVRO-350:
-----------------------------------
Actually, thinking about this a bit more. isSet() seems like a bit of a misnomer, as really we are trying to distinguish between a field existing in the schema or not. Perhaps, hasField(String name) instead?
Also, there is already the equivalent of isSet(String name) publicly exposed via GenericRecord.getSchema().getFields().get(name) != null. Adding hasField would just be a convenience method here, do we even need it?
I'm leaning towards restoring the pre AVRO-278 behavior of returning null when asking for a field that doesn't exist, and adding comments to get(String name) that explain how null can mean two things:
{code}
/**
* Return the value of a field given its name.
* @return null if the given field does not exist in the schema.
* You can differentiate between a stored null and not existing in the schema
* by introspecting the record's schema.
*/
Object get(String key);
{code}
> NPE on GenericData.Record.get(String) for a field that doesn't exist
> --------------------------------------------------------------------
>
> Key: AVRO-350
> URL: https://issues.apache.org/jira/browse/AVRO-350
> Project: Avro
> Issue Type: Sub-task
> Components: java
> Affects Versions: 1.3.0
> Reporter: Kevin Oliver
> Attachments: AVRO-350.patch
>
>
> After the change in AVRO-278 to use arrays, GenericData.Record.get() gives an NPE if you ask for a field that doesn't exist in the schema.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (AVRO-350) NPE on GenericData.Record.get(String)
for a field that doesn't exist
Posted by "Doug Cutting (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/AVRO-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Doug Cutting updated AVRO-350:
------------------------------
Resolution: Fixed
Fix Version/s: 1.3.0
Assignee: Kevin Oliver
Status: Resolved (was: Patch Available)
I just committed this. Thanks, Kevin!
> NPE on GenericData.Record.get(String) for a field that doesn't exist
> --------------------------------------------------------------------
>
> Key: AVRO-350
> URL: https://issues.apache.org/jira/browse/AVRO-350
> Project: Avro
> Issue Type: Sub-task
> Components: java
> Affects Versions: 1.3.0
> Reporter: Kevin Oliver
> Assignee: Kevin Oliver
> Fix For: 1.3.0
>
> Attachments: AVRO-350.patch
>
>
> After the change in AVRO-278 to use arrays, GenericData.Record.get() gives an NPE if you ask for a field that doesn't exist in the schema.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (AVRO-350) NPE on GenericData.Record.get(String)
for a field that doesn't exist
Posted by "Kevin Oliver (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/AVRO-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Kevin Oliver updated AVRO-350:
------------------------------
Status: Patch Available (was: Open)
Here is a patch and testcase.
> NPE on GenericData.Record.get(String) for a field that doesn't exist
> --------------------------------------------------------------------
>
> Key: AVRO-350
> URL: https://issues.apache.org/jira/browse/AVRO-350
> Project: Avro
> Issue Type: Sub-task
> Components: java
> Affects Versions: 1.3.0
> Reporter: Kevin Oliver
> Attachments: AVRO-350.patch
>
>
> After the change in AVRO-278 to use arrays, GenericData.Record.get() gives an NPE if you ask for a field that doesn't exist in the schema.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (AVRO-350) NPE on GenericData.Record.get(String)
for a field that doesn't exist
Posted by "Doug Cutting (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/AVRO-350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12802414#action_12802414 ]
Doug Cutting commented on AVRO-350:
-----------------------------------
This might be reasonable. It is certainly back-compatible.
Throwing an exception for accesses to unset fields might catch application errors earlier. So alternately we might add a 'boolean isSet(String name)' method and improve the error message when attempting to access an unset field. Null is a valid Avro value, so setting something to null is different than having it unset.
Thoughts?
> NPE on GenericData.Record.get(String) for a field that doesn't exist
> --------------------------------------------------------------------
>
> Key: AVRO-350
> URL: https://issues.apache.org/jira/browse/AVRO-350
> Project: Avro
> Issue Type: Sub-task
> Components: java
> Affects Versions: 1.3.0
> Reporter: Kevin Oliver
> Attachments: AVRO-350.patch
>
>
> After the change in AVRO-278 to use arrays, GenericData.Record.get() gives an NPE if you ask for a field that doesn't exist in the schema.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.