gpt4 book ai didi

java - Hadoop 使用 KeyValueTextInputFormat

转载 作者:可可西里 更新时间:2023-11-01 14:14:14 24 4
gpt4 key购买 nike

我使用 hadoop 1.0.1 做一些项目,我想让我的输入 .txt 文件成为“关键”并且我需要的“值(value)”,例如:

如果我有一个test.txt文件,文件内容是

1, 10 10

我想我可以使用“KeyValueTextInputFormat”并使“,”成为分隔符号,因此输入后,key“1”“10 10”

但是,我得到的结果是所有信息都是key,value是空的。我不知道问题出在哪里。

请帮帮我,谢谢!

这是示例代码:

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);
}
Job job = new Job(conf, "word count");
job.setJarByClass(WordCount.class);
job.setMapperClass(WordCountMapper.class);
job.setInputFormatClass(KeyValueTextInputFormat.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
KeyValueTextInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}

最佳答案

分隔符可以在属性名mapreduce.input.keyvaluelinerecordreader.key.value.separator下指定,默认分隔符是制表符('\t')。因此,在您的情况下,将行 conf.set("key.value.separator.in.input.line",",");
更改为

conf.set("mapreduce.input.keyvaluelinerecordreader.key.value.separator",",");

这样就可以了

关于java - Hadoop 使用 KeyValueTextInputFormat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12540145/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com