Support Option of sum types#450
Merged
bplommer merged 4 commits intotypelevel:masterfrom Nov 23, 2022
Merged
Conversation
The type `Option[A]` for any sum type `A` should be supported. Right now this fails with `org.apache.avro.AvroRuntimeException: Nested union` (see typelevel#442 problem 1). This is because `Codec[Option[_]]` is build from a `UnionCodec`. We solve the problem by creating a special `Codec` for `Option`s.
There was mostly a problem in the decoder, not in the encoder. There are still some failing tests but those are just error string mismatches. I will work on that next.
Contributor
Author
|
@bplommer this is ready for review now |
Contributor
|
Hi, thanks for this and sorry for the long silence! This looks good, but I'd like to try and solve it in a more generic way by making the union codec flatten nested unions in the schema. So I'm going to leave this open for now. |
Contributor
Author
|
Adapting the union codec was also my first attempt. I had a hard time aligning all the types. When I switched to this approach all went pretty smooth. |
Contributor
|
I came up with something but it’s not quite as robust because of the way the union codec uses heuristics in decoding, so I’m going to merge this as a special case. Thanks! |
bplommer
approved these changes
Jul 16, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The type
Option[A]for any sum typeAshould be supported. Right now this fails withorg.apache.avro.AvroRuntimeException: Nested union(see #442 problem 1).This is because
Codec[Option[_]]is build from aUnionCodecwhich references a nestedUnionCodec. We solve the problem by creating a specialCodecforOptions.