在hadoop中使用Reducer类

时间:2015-06-01 20:29:11

标签: java hadoop mapreduce reduce

我正在制作地图减少工作。

问题是比较工作不正常。

如何比较这些字符串?

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);
}

1 个答案:

答案 0 :(得分:1)

正如copeg所说,它不依赖于Hadoop,也不依赖于Reducer。问题来自你的字符串比较。在Java中,您应该使用

  

val1.toString()。等于( “观察”)