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

AvroCoder fails on nullable Decimal types w/ Avro 1.11.3 #5331

Closed
clairemcginty opened this issue Apr 9, 2024 · 1 comment · Fixed by #5371
Closed

AvroCoder fails on nullable Decimal types w/ Avro 1.11.3 #5331

clairemcginty opened this issue Apr 9, 2024 · 1 comment · Fixed by #5371
Labels
bug Something isn't working

Comments

@clairemcginty
Copy link
Contributor

clairemcginty commented Apr 9, 2024

Given the following schema:

{
    "type": "record",
    "name": "TestRecord",
    "fields": [
         {
           "name": "nullableDecimal",
           "type": [
             "null",
             {
                 "type": "bytes",
                 "logicalType": "decimal",
                 "precision": 4,
                 "scale": 2
             }
           ]
         }
    ]
}

Scio's default AvroCoder fails to encode records with non-null values, throwing the following error:

[info]   org.apache.avro.UnresolvedUnionException: Not in union ["null",{"type":"bytes","logicalType":"decimal","precision":4,"scale":2}]: 1.00
[info]   at org.apache.avro.generic.GenericData.resolveUnion(GenericData.java:910)
[info]   at org.apache.avro.generic.GenericDatumWriter.resolveUnion(GenericDatumWriter.java:307)
[info]   at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:157)
[info]   at org.apache.avro.specific.SpecificDatumWriter.writeField(SpecificDatumWriter.java:108)
[info]   at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:234)
[info]   at org.apache.avro.specific.SpecificDatumWriter.writeRecord(SpecificDatumWriter.java:92)
[info]   at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:145)
[info]   at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:95)
[info]   at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:82)
[info]   at org.apache.beam.sdk.extensions.avro.coders.AvroCoder.encode(AvroCoder.java:428)

(It works on Avro 1.8.2.)

This seems like it might be an issue with Avro itself (when you step through with a debugger, the GenericDatumWriter doesn't have the right conversions registered for the class), but we could still provide a workaround for it in Scio's SpecificDatumFactory?

Full repro: https://github.com/spotify/scio/compare/repro-nullable-decimal-err?expand=1

@RustedBones
Copy link
Contributor

I locally rebased the repro-nullable-decimal-err branch on the PR. Test passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants