Code Monkey home page Code Monkey logo

elitzur's People

Contributors

andersonreyes avatar anne-decusatis avatar benkonz avatar catherinejelder avatar clairemcginty avatar csharma214 avatar idreeskhan avatar jackdingilian avatar kellen avatar monzalo14 avatar regadas avatar rustedbones avatar scala-steward avatar shnapz avatar skippadabitflippa avatar steveroy0226 avatar stormy-ua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

elitzur's Issues

Failing AvroConverter conversion for optional-wrapped validation type

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.