2

I am new to Hadoop and writing mapreduce code and in mapper class i am using one if condition in following way:-

public class FilmDataMapperClass extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable>
{
    private Text word = new Text();
    public void map(LongWritable key, Text values,
            OutputCollector<Text, IntWritable> output, Reporter reporter)
            throws IOException
            {
                String line = values.toString();
                String [] data = line.split(",");
                word.set(data[3]);
                float rating = Float.valueOf(data[3]);
                if(rating > 3.0)
                {
                    output.collect(word, new IntWritable(1));
                }
            }
}

When i am using above code without any if condition then i am getting output but with if condition i am not getting any output.

Please tell me how to implement above to get desired output.

Sumit Singh
  • 15,743
  • 6
  • 59
  • 89
CK__
  • 1,252
  • 1
  • 11
  • 25
  • Floating point values using direct conditional operators may not be accurate. Check [this similar] question. – bprasanna Dec 18 '14 at 11:40
  • you can use `Float.compare(f1,f2);` for comparing two float values. It will returns the value 0 if f1 is numerically equal to f2; a value less than 0 if f1 is numerically less than f2; and a value greater than 0 if f1 is numerically greater than f2. – Rockstar Dec 18 '14 at 11:45
  • please share the link of similar question @learningloop – CK__ Dec 18 '14 at 11:53
  • @ChandanMishra Sorry, My bad. Following is the [link](http://stackoverflow.com/questions/6837007/comparing-float-double-values-using-operator) – bprasanna Dec 18 '14 at 12:00
  • `Float.compare(f1, f2)` is also not working @Rockstar – CK__ Dec 18 '14 at 12:03
  • i also tried to use compare() function but this also did not work - @learningloop – CK__ Dec 18 '14 at 12:09
  • So what value are you getting at `float rating = Float.valueOf(data[3]);` try to log and check. – Rockstar Dec 18 '14 at 12:31
  • i am getting float value. And when i am putting `system.out.println(rating)` inside if condition then i am getting proper output but i am not getting anything in `output.collect(word, new IntWritable(1))` @Rockstar @learningloop – CK__ Dec 18 '14 at 13:01

0 Answers0