avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jaydeep Ayachit <jaydeep_ayac...@persistent.co.in>
Subject Type cast exception
Date Mon, 26 Apr 2010 14:59:33 GMT

I am trying to read from avro data file and want to use specific object (exa sample.LogMessage)
The following code gives exception mentioned below. Reader.next() when collected in Object/Record,
no exception is thrown which is expected.

Any help is appreciated.

public void testMethod5() throws Exception {
            DatumWriter<LogMessage> writer = new GenericDatumWriter<LogMessage>(LogMessage.SCHEMA$);
            DataFileWriter<LogMessage> out = new DataFileWriter<LogMessage>(writer);

            out.create(LogMessage.SCHEMA$, <File>);
            for (int i = 0; i < 100; i++) {
                  LogMessage msg = new LogMessage();
                  msg.applicationName = new Utf8("app" + i);
                  msg.userid = new Utf8("user" + i);
                  msg.message = new Utf8("this is test log message " + i);


            DataFileReader<LogMessage> reader;
            GenericDatumReader<LogMessage> din = new GenericDatumReader<LogMessage>(LogMessage.SCHEMA$);
            reader = new DataFileReader<LogMessage>(new File(<>), din);

            while (reader.hasNext()) {
                  LogMessage msg = reader.next();


java.lang.ClassCastException: org.apache.avro.generic.GenericData$Record cannot be cast to
      at com.ibm.clas.ReaderWriter.testMethod5(ReaderWriter.java:313)
      at com.ibm.clas.ReaderWriter.main(ReaderWriter.java:322)


This e-mail may contain privileged and confidential information which is the property of Persistent
Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed.
If you are not the intended recipient, you are not authorized to read, retain, copy, print,
distribute or use this message. If you have received this communication in error, please notify
the sender and delete all copies of this message. Persistent Systems Ltd. does not accept
any liability for virus infected mails.

View raw message