我正在尝试将以下数据作为 Hadoop 中的键值对读取。
name: "Clooney, George", release: "2013", movie: "Gravity",
name: "Pitt, Brad", release: "2004", movie: "Ocean's 12",
name: Clooney, George", release: "2004", movie: "Ocean's 12",
name: "Pitt, Brad", release: "1999", movie: "Fight Club"
我需要如下输出:
name: "Clooney, George", movie: "Gravity, Ocean's 12",
name: "Pitt, Brad", movie: "Ocean's 12, Fight Club",
我写了一个Mapper和Reducer如下:
public static class MyMapper
extends Mapper<Text, Text, Text, Text>{
private Text word = new Text();
public void map(Text key, Text value, Context context
) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString(),",");
while (itr.hasMoreTokens()) {
word.set(itr.nextToken());
context.write(key, word);
}
}
}
public static class MyReducer
extends Reducer<Text,Text,Text,Text> {
private Text result = new Text();
public void reduce(Text key, Iterable<Text> values,
Context context
) throws IOException, InterruptedException {
String actors = "";
for (Text val : values) {
actors += val.toString();
}
result.set(actors);
context.write(key, result);
}
}
我还添加了以下配置细节:
Configuration conf = new Configuration();
conf.set("mapreduce.input.keyvaluelinerecordreader.key.value.separator", ",");
我得到以下输出:
name: "Clooney George" release: "2013" movie: "Gravity" George" release: "2004" movie: "Ocean's 12"
name: "Pitt Brad" release: "2004" movie: "Ocean's 12" Brad" release: "1999" movie: "Fight Club"
似乎我什至无法正确读取基本的键值对。Hadoop 中的键值对处理如何?有人可以详细说明这一点并指出我哪里出错了吗?
谢谢。TM值