Could this be AVRO-1240?  What version of Avro are you using?

https://issues.apache.org/jira/browse/AVRO-1240

Doug

On Tue, Jul 2, 2013 at 10:05 AM, TrevniUser <[email protected]> wrote:
> I am facing this same issue while using SortedKeyValueFile. Could you please
> provide some pointers why in the first place is GenericRecord being picked
> up and not SpecificRecord?
>
> @Test
>     public void testSortedKeyValueFile() throws IOException {
>         Path filePath = new Path(test.getMethodName());
>
>         Schema keySchema = ReflectData.get().getSchema(Long.class);
>         Schema valSchema =
> ReflectData.get().getSchema(DataSinkChangeLogContent.class);
>
>         SortedKeyValueFile.Writer.Options opts = new Options();
>         opts.withKeySchema(keySchema);
>         opts.withValueSchema(valSchema);
>         opts.withConfiguration(conf);
>         opts.withPath(filePath);
>         SortedKeyValueFile.Writer<Long, DataSinkChangeLogContent> writer =
> new SortedKeyValueFile.Writer<Long, DataSinkChangeLogContent>(
>                 opts);
>         for (long i = 0; i < 10; i++) {
>             writer.append(i, new DataSinkChangeLogContent(eType.toString(),
> eKey.toString(), i, 15L));
>         }
>         writer.close();
>
>         SortedKeyValueFile.Reader.Options readerOpts = new
> SortedKeyValueFile.Reader.Options();
>         readerOpts.withKeySchema(keySchema);
>         readerOpts.withValueSchema(valSchema);
>         readerOpts.withConfiguration(conf);
>         readerOpts.withPath(filePath);
>         SortedKeyValueFile.Reader<Long, DataSinkChangeLogContent> reader =
> new SortedKeyValueFile.Reader<Long, DataSinkChangeLogContent>(
>                 readerOpts);
>         Iterator<AvroKeyValue&lt;Long, DataSinkChangeLogContent>> i = null;
>         if (reader.get(5L) != null) {
>             i = reader.iterator();
>         }
>         while (i != null && i.hasNext()) {
>             AvroKeyValue<Long, DataSinkChangeLogContent> keyValue =
> i.next();
>             System.out.println("---------------------------- Clock: " +
> keyValue.getValue());
>         }
> *        DataSinkChangeLogContent e = reader.get(5L);* // FAILS AT THIS LINE
>         reader.close();
>     }
>
> EXCEPTION:
>
> java.lang.ClassCastException: org.apache.avro.generic.GenericData$Record
> cannot be cast to com.abc.kepler.datasink.DataSinkChangeLogContent
>         at
> com.abc.kepler.datasink.hdfs.HDFSDataSinkChangeLogScannerTest.testSortedKeyValueFile(HDFSDataSinkChangeLogScannerTest.java:926)
>
>
>
> --
> View this message in context: 
> http://apache-avro.679487.n3.nabble.com/Type-cast-exception-tp756884p4027727.html
> Sent from the Avro - Users mailing list archive at Nabble.com.

Reply via email to