Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert String object to IntWritable Object in Hadoop

Tags:

java

hadoop

I want to convert String object to IntWritable Object in Hadoop. any process is available for conversion.

like image 357
Sujana Avatar asked Oct 17 '13 11:10

Sujana


People also ask

How do you change a String object into an object?

We can convert String to Object in java with assignment operator. Each class is internally a child class of Object class. So you can assign string to Object directly. You can also convert String to Class type object using Class.

What is IntWritable in Mapreduce Hadoop?

IntWritable is the Hadoop flavour of Integer, which is optimized to provide serialization in Hadoop. Java Serialization is too big or too heavy for Hadoop, hence the box classes in Hadoop implements serialization through the Interface called Writable. Writable can serialize the object in a very light way.


1 Answers

IntWritable value = new IntWritable(Integer.parseInt(someString))

... and deal with the possibility that parseInt may throw a NumberFormatException.


Someone asked:

How to overcome this NumberFormatException ???

The exception will occur if someString does not represent an integer.

What do you do?

You catch it and handle it of course! How you handle it (i.e. what you should code your application to do) will depending on the context. We can't advise on that.

Java exceptions and exception handling are described in the Oracle Java Tutorials - here.

like image 134
Stephen C Avatar answered Oct 10 '22 22:10

Stephen C