Skip to content

Support Option of sum types#450

Merged
bplommer merged 4 commits intotypelevel:masterfrom
erikvanoosten:option-plus-sum-types
Nov 23, 2022
Merged

Support Option of sum types#450
bplommer merged 4 commits intotypelevel:masterfrom
erikvanoosten:option-plus-sum-types

Conversation

@erikvanoosten
Copy link
Copy Markdown
Contributor

@erikvanoosten erikvanoosten commented May 11, 2022

The type Option[A] for any sum type A should be supported. Right now this fails with org.apache.avro.AvroRuntimeException: Nested union (see #442 problem 1).

This is because Codec[Option[_]] is build from a UnionCodec which references a nested UnionCodec. We solve the problem by creating a special Codec for Options.

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.
@erikvanoosten erikvanoosten changed the title Support Option of sum types (work in progress) Support Option of sum types (feedback requested) May 12, 2022
@erikvanoosten erikvanoosten marked this pull request as draft May 12, 2022 06:59
erikvanoosten and others added 2 commits May 12, 2022 14:10
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.
@erikvanoosten erikvanoosten marked this pull request as ready for review May 12, 2022 12:19
@erikvanoosten
Copy link
Copy Markdown
Contributor Author

@bplommer this is ready for review now

@erikvanoosten erikvanoosten changed the title Support Option of sum types (feedback requested) Support Option of sum types May 12, 2022
@bplommer
Copy link
Copy Markdown
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.

@erikvanoosten
Copy link
Copy Markdown
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.

@bplommer
Copy link
Copy Markdown
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 bplommer merged commit bef0f4e into typelevel:master Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants