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

SpecificRecord Support for multi record union type #116

Open
xuehaowen opened this issue Feb 27, 2019 · 2 comments
Open

SpecificRecord Support for multi record union type #116

xuehaowen opened this issue Feb 27, 2019 · 2 comments

Comments

@xuehaowen
Copy link

xuehaowen commented Feb 27, 2019

I need to deserialize avro message which implemented SpecificRecord.
The schema I used is like:
union { record1, record2, record3} event;

But I find SpecificRecord does not support OptionShapelessCoproduct, OptionEitherShapelessCoproduct, or OptionalShapelessCoproduct.

val avroScalaCustomTypes = SpecificRecord.defaultTypes.copy(union = OptionEitherShapelessCoproduct)
val generator = new Generator(SpecificRecord, restrictedFieldNumber = true, avroScalaCustomTypes = Some(avroScalaCustomTypes))

java.lang.RuntimeException: Unions beyond nullable fields are not supported
at scala.sys.package$.error(package.scala:27)
at avrohugger.format.specific.converters.JavaConverter$.convertToJava(JavaConverter.scala:35)
at avrohugger.format.specific.methods.GetGenerator$.avrohugger$format$specific$methods$GetGenerator$$asGetCase$1(GetGenerator.scala:23)

Can we add support for specific record

@Dr-Nikson
Copy link

Dr-Nikson commented Mar 25, 2019

👍🏼 +1. Same issue.

Would it make sense to support this kind of unions? Because it doesn't work event for two types inside union:

{
  "name": "myField",
  "type": ["MyEvent1", "MyEvent2"]
}

@nicolaemarasoiu
Copy link

nicolaemarasoiu commented Jul 7, 2020

[error] stack trace is suppressed; run last Compile / avroScalaGenerate for the full output
[error] (Compile / managedSources) spray.json.DeserializationException: Object expected in field 'name'
[error] (Compile / avroScalaGenerate) Unions, beyond nullable fields, are not supported. 
[error] Found a union of more than one type

Top level in this avsc file is not a single type like usual, but 4 types are defined inside an array: #24

If the types are independent, it is not an issue to split the file in multiple avsc files.

But if there are dependencies, i do not know currently any way in Avro hugger to ensure that the avsc files are parsed in their dependency order: #137

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

No branches or pull requests

3 participants