avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <cutt...@apache.org>
Subject Re: reading avro data file on HDFS
Date Mon, 10 Jan 2011 20:34:30 GMT
Tatsuya,

Are you sure that the schema in weather.avro file is named 
"test.Weather"?  In trunk, if SpecificDatumReader cannot find the class 
named in a schema, it will use GenericData$Record.  What version of Avro 
are you using?

Doug

On 01/08/2011 12:35 AM, Tatsuya Mori wrote:
> Hi,
>
> I am trying to read avro data file on HDFS. The following code gives
> the error attached at the bottom, even though I use
> SpecificDatumReader. The Weather class is taken from test of
> org.apache.avro.mapred.
> Any comments/suggestions are highly appreciated. Thanks.
>
> Tatsuya
>
> [code]
>          String input = "hdfs:/user/mori/weather.avro";
>          Path inPath = new Path(input);
>
>          FileSystem fs = FileSystem.get(URI.create(input),
>                                         new Configuration());
>          BufferedInputStream inStream =
>              new BufferedInputStream(fs.open(inPath));
>
>          DatumReader<Weather>  reader =
>              new SpecificDatumReader<Weather>(Weather.class);
>          DataFileStream<Weather>  fileReader =
>              new DataFileStream<Weather>(inStream, reader);
>
>          while (fileReader.hasNext()) {
>              Weather w = (Weather) FileReader.next();
>              System.out.printf("%s\n", w.station);
>          }
>
> [error]
> Exception in thread "main" java.lang.ClassCastException:
> org.apache.avro.generic.GenericData$Record cannot be cast to
> test.Weather
> 	at TestWeather.main(TestWeather.java:103)
> 	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:616)
> 	at org.apache.hadoop.util.RunJar.main(RunJar.java:156)

Mime
View raw message