.nabble.com/ArrayWritable-usage-tp3138520p3576386.html
Sent from the Hadoop lucene-users mailing list archive at Nabble.com.
I'm having some difficulty with using ArrayWritable in the following test
code:
ArrayWritable array = new ArrayWritable(IntWritable.class);
IntWritable[] ints = new IntWritable[4];
for (int i =0 ; i 4; i++) {
ints[i] = new IntWritable(i);
}
ArrayWritable doesn't serialize type information. You need to subclass it
(e.g. IntArrayWritable) and create a no arg constructor which calls
super(IntWritable.class).
Use this instead of ArrayWritable directly. If you want to store more than
one type, look at the source for MapWritable to see
Thanks, your answer and the documentation at
http://hadoop.apache.org/common/docs/current/api/org/apache/hadoop/io/ArrayWritable.htmlfixed
the issue.
For others benefit, I have reproduced the solution below.
Modified test code:
SequenceFile.Writer writer = SequenceFile.createWriter(fs,