Elena
Elena

Reputation: 181

Integer and IntWritable types existence

My question could be very stupid but please bear with me for a while.

In Java int is a Data type and Integer is a type in which int gets wrapped. If we talk about Hadoop, there is IntWritable is available intstead of Integer. (If am not wrong)

While studying most of the time its said that, in hadoop they use IntWritable because its good to transport large amount of data over network. Its okay..!

One thing I came across while doing this, whether its Integer or IntWritable, How differently they gets wrapped around int ? Where I can see the code which could show the wrapped difference around int ? If I see IntWritable class or Integer class, they seems to be a simple classes, but where the difference is happening when int gets egrained by Integer or IntWritable ?

I'm thinking as of now int as a core type of Java, and looking for what happens when int sits inside Integer or IntWritable in backend ? How it flows to become Integer or IntWritable ? I hope my question is cleared..! :)

Upvotes: 2

Views: 736

Answers (1)

Raj
Raj

Reputation: 727

Yes there is a difference.

IntWritable is the Hadoop variant of Integer which has been optimized for serialization in the Hadoop environment. An integer would use the default Java Serialization which is very costly in Hadoop environment.

IntWritable implements Comparable<IntWritable>, Writable, WritableComparable<IntWritable> interfaces.

  • Comparable is the interface whose abstract methods give us the flexibility to compare two objects.
  • Writable is meant for writing the data to local disk and it's a serialization format. One can implement own Writables in Hadoop. Java’s serialization is too bulky and slow on the system. That’s why Hadoop community had put Writable in place.
  • WritableComparable is a combination of the above two interfaces.

More reference :

Why does Hadoop need classes like Text or IntWritable instead of String or Integer?

For Internal structure of Integer class :

https://www.geeksforgeeks.org/java-lang-integer-class-java/

Hadoop Documentation for IntWriable :

http://hadoop.apache.org/docs/r2.7.1/api/org/apache/hadoop/io/IntWritable.html

Upvotes: 4

Related Questions