java - Hadoop Map减少Java

标签 java hadoop mapreduce

public static class TokenizerMapper extends Mapper<Object, Text, Text, Text> {
    public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
        StringTokenizer itr = new StringTokenizer(value.toString(), " *$&#/\t\n\f\"'\\,.:;?![](){}<>~-_");
        while (itr.hasMoreTokens()) {
            String term = itr.nextToken().toLowerCase();
            List<Pair<String, Pair<Integer, Integer>>> map = new ArrayList<Pair<String, Pair<Integer, Integer>>>();
            /*here i am performing some operations*/
            for (Pair<String, Pair<Integer, Integer>> i : map){
                String w1 = i.getKey();
                Text word = new Text(w1);
                Pair<Integer, Integer> newValue = i.getValue();
                String merge = String.valueOf(newValue.getKey()) + " " + String.valueOf(newValue.getValue());
                Text val = new Text(merge);
                /*sending both the arguments as text into my context.*/
                context.write(word, val);
            }
        }
    }
}

public static class Reducer1 extends Reducer<Text, Text, Text, Text> {
    public void reduce(Text key, Text values, Context context) throws IOException, InterruptedException {
        /* here i want to extract the values, i tried using for loop but its saying cannot iterate, its expecting something iterable.*/
        for (Text t : values)
        {
            /*this is not working. I know we can use Iterable<IntWritable> for integers but in my case it is text.
        }
        //context.write(key, values);
    }
}

请查看注释行以更好地了解我的问题。
有什么方法可以提取化简器中的Text值。 For循环需要iterable

最佳答案

在化简器中,您将得到一个Iterable<Text>,您必须在其上循环并在一个空格上分割以为映射器编写的每个merge字符串重新创建String值。

注意:如果 map 中的newValue.getKey()包含字符串本身,则在空格上分割将不是很可靠

关于java - Hadoop Map减少Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52159056/

相关文章:

hadoop - yarn Hadoop运行缓慢

java - 在 netbeans 中的 JButton 上使用 Enabled 属性

java - Docker 中的 Tomcat

hadoop - 关于 hive 的问题

hadoop - 减少功能包含操作

hadoop - 流数据和 Hadoop? (不是 Hadoop 流)

sorting - 如何对map reduce hadoop中的数据进行排序?

java - 用手指在安卓屏幕上画画

java - 如何按对象值整数对自定义arraylist进行排序

eclipse - 线程 “main”中的异常java.io.IOException:无法初始化群集