-
Notifications
You must be signed in to change notification settings - Fork 1.7k
AVRO-3989: [java] add conversion classes to default instance of SpecificData #3354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
CC: @Fokko I'd appreciate it if you could look at this PR and leave any feedback for me! Also, apologies for the 1:1 ping in advance. |
| @Test | ||
| public void testUnionWithLogicalType() throws IOException { | ||
| File file = new File(DIR.getPath(), "testSpecificDatumReaderDefaultCtorWithOptionalLogicalType"); | ||
| Schema s1 = new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Bar\",\"namespace\":\"foo\"," |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason to use duplicate the schema in this string? Or is it sufficient to read the schema from fooBar.avsc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I addressed it in this update.
|
Hi @hmit, |
Adding it to ReflectData is a good idea, I'll do that. However, adding it to Thanks @opwvhk for taking a look at this PR. I appreciate it! |
There are if the schema contains logical types: the conversions are used to determine the actual value, regardless of whether there is a typed field for the value to go into. |
|
Another thing to consider (just remembered): starting with version 1.11.4 and 1.12.0, conversions are loaded using a |
I also think the |
You have a point there, although I believe it's more a lack of being able to ignore a logical type (the class API does not provide for this). Adjusting that would be too much for this PR though. |
|
Thanks for the merge @opwvhk! |
…ficData (#3354) * AVRO-3989: [java] add conversion classes to default instance of SpecificData * add test case, exclude decimal conversion * review comment: use schema from the generated class for `fooBar.avsc` * add logical type conversion classes to ReflectData as well * refactor to single method --------- Co-authored-by: Harshit Mittal <hmittal@netflix.com> (cherry picked from commit f131a5c)
|
@opwvhk Is it possible to patch avro1.11 as well with this change and perhaps released as v1.11.5? |
…ficData (apache#3354) * AVRO-3989: [java] add conversion classes to default instance of SpecificData * add test case, exclude decimal conversion * review comment: use schema from the generated class for `fooBar.avsc` * add logical type conversion classes to ReflectData as well * refactor to single method --------- Co-authored-by: Harshit Mittal <hmittal@netflix.com>
What is the purpose of the change
This pull request improves deserialization of data when using default
SpecificDatainstance.Why?
Often times,
SpecificDatumReaderandReflectDatumReaderare configured using the defaultSpecificDatainstance. This leads to deserialization error when reading fields with union type and inner logical type (see test-case).Deserialization works correctly when using the custom
SpecificDatainstance stored in theMODEL$field of the schema class thatextends SpecificRecord. The customSpecificDatahas the necessary conversions stored to handle fields with union and logical types. The issue has been reported multiple times, notably in [AVRO-3989](linked JIRA).Verifying this change
This change added tests and can be verified as follows:
Documentation