如何在Reduce函数

时间:2016-01-27 05:26:58

标签: json hadoop mapreduce

我能够在hadoop中使用mapreduce解析Json数据,我想在reduce函数中显示2个字符串变量,下面是我试过的代码

  public static class Map extends Mapper<LongWritable, Text, Text, Text>{
    public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException{

        Double overall;
        String reviewtime;
        String line = value.toString();
        //line  = line.replaceAll("\\s+","");
        String[] tuple = line.split("\\n");            
        try{
            for(int i=0;i<tuple.length; i++){
               JSONObject obj = new JSONObject(tuple[i]);
               overall = obj.getDouble("overall");
               reviewtime = obj.getString("reviewTime");
               context.write(new Text(String.valueOf(overall)), new Text(reviewtime));

            }
        }catch(JSONException e){
            e.printStackTrace();
        }
    }
}

在Reduce函数中写什么,以便我可以在reduce函数中显示2个以上的字符串变量...我是mapreduce和hadoop的新手,请帮帮我,下面是reduce函数体

 public static class Reduce extends Reducer<Text,Text,NullWritable,Text>{

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

        try{



        }catch(JSONException e){
            e.printStackTrace();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我明白了,这是正确的,

    getAllLevelsCount : {
    value: function (elements, n) {
  return function () {
    return elements.count(function (count) {
      return count >= n;
    });
  };
}
browser.wait(dashboard.getAllLevelsCount($$("cssid"), 3) , 10000);