Mijatovic Mijatovic - 5 months ago 11
Java Question

Understanding LongWritable

I'm sorry if this is a foolish question, but I couldn't find answer with a Google search.
How I can understand

LongWritable
type? What is it? Can anybody link to a schema or other helpful page.

Answer

Hadoop needs to be able to serialise data in and out of Java types via DataInput and DataOutput objects (IO Streams usually). The Writable classes do this by implementing two methods `write(DataOuput) and readFields(DataInput).

Specifically LongWritable is a Writable class that wraps a java long.

Most of the time (especially just starting out) you can mentally replace LongWritable -> Long i.e. it's just a number. If you get to defining your own datatypes you will start to become every familiar with implementing the writable interface:

Which looks some thing like:

public interface Writable {

       public void write(DataOutput out) throws IOException;

       public void readFields(DataInput in) throws IOException;
}
Comments