-
Notifications
You must be signed in to change notification settings - Fork 34
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
Some issues migrating from Avro4s #442
Comments
If you like, with pointers into the code, I can attempt to fix some of these things. |
That would be great for the AvroName feature (I've opened a ticket at #443). The relevant bit of code (for Scala 2) is at vulcan/modules/generic/src/main/scala-2/vulcan/generic/package.scala Lines 88 to 92 in 26aaa04
I have something in progress for flattening nested union codecs, I'll dig it out. |
Re field mappers, the general philosophy in Vulcan is to encourage writing codecs manually and keep generic derivation as lightweight as possible, but I'm open to being persuaded 🙂 |
I have added a 4th issue. |
I have added a 5th issue. Also, I added a rationale of why we want to move to Vulcan (performance!). Re. fieldmapper and keeping generic derivation lightweight, we have a workaround so I won't press the issue :) Actually, we now have workarounds for all 5 issues. Some are not so pretty, in particular we would like to see issues 1 and 4 be resolved. I can look at no. 4 next week. |
I'd like to keep the existing behaviour for defaults as it is, but we could add an |
WDYT of adding variants of the I have to follow a schema definitions that demands dozens of records. It is maintained by multiple people. If we need to put an annotation on every case class, there is a good chance one will be forgotten. In addition, I'd prefer to keep the Vulcan dependency out of the model code (but that is not a hard requirement). |
I'd be down for that. Should be feasible. I'll try to look at your PR and write up some more thoughts in the next few days. |
Interesting! The main issues with avro4s that motivated creating Vulcan were to do with slow compile time and undesired results from always-on autoderivation but I don't remember runtime performance being a problem. Have you opened an issue with avro4s? |
Actually, we have since found out that we were accidentally running our code in a mutex so no multi-threaded speedup was possible. I have to update this part of the story. Update: removed this part from the description. |
Re. no 4, from https://github.com/softwaremill/magnolia#limitations (on the Scala 3 version):
Fortunately, the next version of Magnolia will support it :) |
Proposal to solve no. 5 in PR #447 |
The type `Option[A]` for any sum type `A` should be supported. Right now this fails with `org.apache.avro.AvroRuntimeException: Nested union` (see fd4s#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.
We now run in production with a fork that contains #444 (without config) and #450. It works pretty well. I did not get a chance to work on adding defaults yet. Although I found out that it is not that urgent. This is because we add |
Hi, I would like to know more about performance difference between vulcan and avro4s. I currently use avro4s in a kafka streams application for reflection based schema generation. Is performance one of the primary considerations for the creation of this project or was it an afterthought in comparison to more of the developer experience based concerns? |
hi @erikvanoosten, did you find a solution for no. 4? |
@Zhen-hao Since I have a work around (see #442 (comment)), I no longer worked on a proper solution. However, now that Magnolia exposes default values, it could be baked directly into Vulcan. |
Because Avro4s is too slow in writing binary (for our use case), we want to migrate to Vulcan. Compared to Avro4s the performance is very good! We see 10 to 12 times the throughput on a single thread.
Unfortunately, we do have some problems when migrating from Avro4s:
@AvroName
annotation for field names #443Optional union types get nested
prints:
(with newlines added for clarity)
I expected Vulcan to silently add the
null
type to the union, not create a new union with the 'Location' union nested in it.Missing a field mapper
Unfortunately we need to use case classes that have weird field names. They contain weird characters like
@
and:
. With Avro4s we defined a field mapper that would map these to valid names.As a work around we could use the
@AvroName
annotation on the case class fields. Unfortunately we are still not allowed to use the@
character in the field name even though it is no longer relevant for the schema. This is probably related to the next item:AvroName annotation is ignored
prints:
Field defaults are ignored
expected:
Generic parameters are not included in a record name
Prints:
Event
, Avro4s givesEvent__SomeData
.The Avro4s approach has the advantage of giving each type instance of
Event
a different name. This is relevant if the consumer of the schema uses code generation.Note that we can not solve this with an
@AvroName
annotation as then the name would be same for every type instance ofEvent
. (If that is what@AvroName
is supposed to do, currently it does not seem to change the name when set on a case class.)All code in this issue tested with Vulcan 1.3.8, Scala 2.12.15.
The text was updated successfully, but these errors were encountered: