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)