hadoop-common-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha <m...@umail.ucsb.edu>
Subject Writable Class with an Array
Date Thu, 17 Mar 2011 21:04:46 GMT

  I'm stuck with this for two days now ...I found a previous post discussing this, but not
with arrays.

 I know how to write Writable class with primitive type elements but this time I'm using an
ARRAY of primitive type element, here it is in a simplified version for easy readability :

public class twoIntegersArrayWritable implements Writable {

	private int vectorSize;
	private twoIntegers[] vector ;
	/* CONSTRUCTORS */  ===================================================

	twoIntegersArrayWritable () {}

	twoIntegersArrayWritable (int size, twoIntegers[] vec) {
		this.vectorSize = size;		
		this.vector = vec;

	/* WRITE FUNCTION */  ===================================================	

	public void write(DataOutput out) {	

		for(int i=0;i<this.vectorSize;i++){
			out.writeInt( vector[i]. getFirstIntger());
			out.writeInt( vector[i]. getSecondIneger());

	/* READ FUNCTION */  ===================================================	
	public void readFields(DataInput in) throws IOException {
		this.vectorSize = in.readInt();		
		this.CreateNewVector (this.vectorSize);
		for(int i=0;i< this.vectorSize;i++){ 				

The errors I get:
	at twoIntegersArrayWritable.readFields(twoIntegersArrayWritable.java:46)
	at org.apache.hadoop.io.SequenceFile$Reader.getCurrentValue(SequenceFile.java:1751)
	at org.apache.hadoop.io.SequenceFile$Reader.next(SequenceFile.java:1879)
	at SequenceFileReader_Integers.main(SequenceFileReader_Integers.java:49)

Or it would work fine but array size is always 0. So it won't read the integer fields.

It would be helpful if someone already has an example of using array in their Writable class.
I appreciate any thought. 


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message