spotify / elitzur Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
Upgrading to scio 0.95 and running into a previously-worked-around AvroConverter issue.
I have a validation type:
case class Country(data: String) extends BaseValidationType[String] {
override def checkValid: Boolean = ...
}
And a case class that uses it:
case class MyClass(
...
country: Option[Country],
...
)
And an attempt to convert:
implicitly[AvroConverter[MyClass]].toAvro(a, AvroMyClass.getClassSchema).asInstanceOf[AvroMyClass]
To this schema:
{
{
"name": "country",
"type": [
"null",
"string"
],
"default": null
},
And deep in the internals of DerivedConverter
Iโm seeing Country
being evaluated against a schema of "string"
, which should work but which instead is passed to GenericRecordBuilder
and results in:
[info] org.apache.avro.AvroRuntimeException: Not a record: "string"
[info] at org.apache.avro.Schema.getFields(Schema.java:220)
[info] at org.apache.avro.data.RecordBuilderBase.<init>(RecordBuilderBase.java:54)
[info] at org.apache.avro.generic.GenericRecordBuilder.<init>(GenericRecordBuilder.java:38)
[info] at com.spotify.elitzur.converters.avro.DerivedConverter.toAvro(AvroConverter.scala:319)
[info] at com.spotify.elitzur.converters.avro.AvroOptionConverter.toAvro(AvroConverter.scala:138)
[info] at com.spotify.elitzur.converters.avro.AvroOptionConverter.toAvro(AvroConverter.scala:125)
[info] at com.spotify.elitzur.converters.avro.DerivedConverter.toAvro(AvroConverter.scala:333)
I had previously worked around this by round-tripping to bytes which no longer works:
def toAvro[To <: SpecificRecordBase](toSchema: Schema)(implicit ac: AvroConverter[From]): To = {
val decoder = new BinaryMessageDecoder[To](new SpecificData(), toSchema)
val rec: GenericData.Record = ac.toAvro(instance, toSchema).asInstanceOf[GenericData.Record]
val bytes: ByteBuffer = new BinaryMessageEncoder[GenericData.Record](new GenericData(), toSchema).encode(rec)
val ret: To = decoder.decode(bytes)
ret
}
My suspicion is that the Option
wrapper is breaking an otherwise working path
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.