1

我的计数器值每次都被重写。无法弄清楚保持值递增的方法。这是一个 map Reduce 代码。需要用profileId设置counter的值。谢谢

public void map(Object key, Text value, Context context) throws IOException, InterruptedException {

    String profile;
    String pos = null;
    int count=0;
    StringTokenizer inputKey=new StringTokenizer(value.toString()," ,");

    while(inputKey.hasMoreTokens()) {
        String input=inputKey.nextToken();
        System.out.println("the input is "+ input);

        if(!input.endsWith("</id>")) {
            textInput.set(input);
            count++;
            System.out.println("value of count is " + count);
        } else {
            profile=input.substring(4,15);
            profileId.set(profile);
        }

        /*count=+count;
          int index=value.toString().indexOf(count);
          pos=Integer.toString(index);
          System.out.println("the position is " + pos);
        */
        System.out.println("the index for each word is " + pos ); 
        context.write(textInput, new Text(profileId + ", " + pos));
    }
}
4

0 回答 0