Git Product home page Git Product logo

Comments (3)

vidma avatar vidma commented on September 26, 2024

👍 I'd like this too!

from avro-scala-macro-annotations.

julianpeeters avatar julianpeeters commented on September 26, 2024

Turns out this will also fix a bug that prevents annotated case classes from being easily used as avro records when the avros are read as a stream:

    [error] (run-main-6) java.io.IOException: Not a data file.
    java.io.IOException: Not a data file.
at org.apache.avro.file.DataFileStream.initialize(DataFileStream.java:102)
at org.apache.avro.file.DataFileStream.<init>(DataFileStream.java:84)

" When deserializing from a stream, the Avro reader expects the read-mark to point to the schema. If we use a GenericRecord reader to read in the schema first, the read-mark points to the records so the read-mark needs to be reset (and the stream needs to allow it). For some reason this does not seem to be an issue when reading from Files." - Raj Kumar

Current workaround from Raj Kumar:

def deserialize[R]( is: InputStream): Iterator[R] = {
    val bis = if( is.markSupported ) is
              else new BufferedInputStream( is )
    bis.mark( MAX_SCHEMA_SIZE )
    val schema = new DataFileStream( bis, new GenericDatumReader[R]).getSchema
    bis.reset
    val dr = new SpecificDatumReader[R]( schema )
    val dfr= new DataFileStream[R]( bis, dr)
    dfr.iterator
  }

Again, the bug and the workaround will be obviated when SCHEMA$ is introduced as a field of the companion object of the avro record case class, a la:

val schema = MyRecord.SCHEMA$
def deserialize[R]( schema: Schema, is: InputStream): Iterator[R] = {
    val dr = new SpecificDatumReader[R]( schema )
    val dfr= new DataFileStream[R]( bis, dr)
    dfr.iterator
  }

from avro-scala-macro-annotations.

julianpeeters avatar julianpeeters commented on September 26, 2024

Fixed in version 0.7

from avro-scala-macro-annotations.

Related Issues (20)

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.