Git Product home page Git Product logo

Comments (3)

julianpeeters avatar julianpeeters commented on September 27, 2024

Hi Sutram,

Thanks for trying out this library.

Use the schema as an argument to the datumwriter:

    val sw = new SpecificDatumWriter[AtomicSlice](AtomicSlice.SCHEMA$)

The above is how I see SpecificDatumWriters used in this Avro test and in an hbase example (according to a quick web search). Without specifying a schema, I get the same error in Java too(see below).

I consider this an Avro gotcha because SpecificDatumWriters need to be constructed differently for writing files than for writing straight binary, but we get no help from the compiler. All avro writing requires a schema at some point. DataFileWriters require a schema be specified upon file creation, so it doesn't matter if their datumwriters were constructed with schemas or not. Meanwhile, Encoders don't allow a schema to be specified: if its datumwriter was constructed without one, its schema never gets set and hence the null pointer exception when a write is actually perfomed.

At least this is how things appear to me; although I don't exactly see where things fall through to generic... perhaps the schema didn't match a class name because the schema was null, but why didn't that show up in the stack trace?

Anyways, hope this helps,
-Julian

The error in java:

mvn exec:java -Dexec.mainClass="com.example.Main"  
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building avro-encoder-example 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:1.4.0:java (default-cli) @ avro-encoder-example ---
[WARNING] 
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:87)
at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:58)
at com.example.Main.main(Main.java:38)

from avro-scala-macro-annotations.

sutram avatar sutram commented on September 27, 2024

Thanks, that fixed it!

I really appreciate this project.

I have a couple more issues I wanted to run by you so I'll create those as separate issues.

from avro-scala-macro-annotations.

julianpeeters avatar julianpeeters commented on September 27, 2024

great!

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.