Skip to content
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

AvroItemWriter uses GenericDatumWriter instead of SpecificDatumWriter for type that extends SpecificRecordBase #3859

Closed
adrianbielewicz opened this issue Feb 27, 2021 · 0 comments
Labels
for: backport-to-4.2.x Issues that will be back-ported to the 4.2.x line in: infrastructure type: bug

Comments

@adrianbielewicz
Copy link

Bug description
I am generating Java code from an Avro schema. It creates classes that extend SpecificRecordBase. In this case AvroItemWriter automatically chooses GenericDatumWriter as the underlying writer. This causes multiple exceptions when logical types are used in the schema (for example decimal or timestamp-millis).

It would work perfectly if SpecificDatumWriter is used. I believe that the problem lies in the order in which datum writer is chosen. The code checks first if my item class is an instance of GenericRecord and only after that returns false, it check if it is an instance of SpecificRecordBase. As SpecificRecordBase implements GenericRecord the first check will always return true and this leads to GenericDatumWriter to be used.

Environment
Spring Batch 4.3.1

Steps to reproduce

  1. Create a simple schema that uses logical types like decimal and timestamp-millis.
  2. Generate java code using avro-tools.
  3. Try to write using the generated classes.

Expected behavior
SpecificDatumWriter should be used instead of GenericDatumWriter.

@adrianbielewicz adrianbielewicz added status: waiting-for-triage Issues that we did not analyse yet type: bug labels Feb 27, 2021
@fmbenhassine fmbenhassine added in: infrastructure for: backport-to-4.2.x Issues that will be back-ported to the 4.2.x line and removed status: waiting-for-triage Issues that we did not analyse yet labels Mar 1, 2021
fmbenhassine pushed a commit that referenced this issue May 18, 2021
Due to GenericRecord being checked before SpecificRecordBase,
GenericDatumWriter was used incorrectly for types that extend
SpecificRecordBase.

Resolves #3859
fmbenhassine pushed a commit that referenced this issue May 18, 2021
Due to GenericRecord being checked before SpecificRecordBase,
GenericDatumWriter was used incorrectly for types that extend
SpecificRecordBase.

Resolves #3859
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: backport-to-4.2.x Issues that will be back-ported to the 4.2.x line in: infrastructure type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants