0

I am building a map reduce job.

The problem is that comparing is not working correctly.

How can I compare these Strings?

public void reduce(Text key, Iterable<Text> values,
        Context context) throws IOException, InterruptedException {

    int numItems1 = 0;

    for (Text val1 : values) {
        if(val1.toString()  == "view")   /// if not working
        {
            numItems1 = numItems1+1;
            numItems2 = 0;
            numItems3 = 0;
            result1.set( numItems1 );
            // val1.set(   result1 + "," + numItems2 + "," +   numItems3  );
        }
    }

    val1.set(result1 + ",");
    context.write(key,val1);
}
resueman
  • 10,510
  • 10
  • 31
  • 45
2Big2BeSmall
  • 1,288
  • 2
  • 19
  • 38

1 Answers1

1

As copeg said, it does not rely on Hadoop, nor on Reducer. The problem comes from your strings comparison. In Java, you should use

val1.toString().equals("view")

Yann
  • 361
  • 2
  • 7