我使用hadoop 1.0.1做一些项目,我想让我的输入.txt文件成为我需要的"关键"和"值",如:
如果我有一个test.txt文件,文件内容是
1,10 10
我认为可以用"KeyValueTextInputFormat",使""是分离的符号,所以输入之后,关键是'1’和值是'10 10’.
但是,我得到的结果是所有信息都是关键,值是空的.我不知道问题出在哪里.
请给我一些帮助,谢谢!
这是示例代码:
public class WordCount{
public class WordCountMapper extends Mapper<Text, Text, Text, Text>{
public void map(Text key, Text value, Context context) throws IOException, InterruptedException {
context.write(value, value);
context.write(key, key);
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
conf.set("key.value.separator.in.input.line",",");
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
if (otherArgs.length != 2) {
System.err.println("Usage: wordcount <in> <out>");
System.exit(2);
} …Run Code Online (Sandbox Code Playgroud)