Java 为什么我无法获取文件名&;在Hadoop中以格式(Word文件名计数)显示它?
输入是一个名为Wiki-micro.txt的文本文件。。。字数计算程序运行正常。。我需要修改它&将其输出格式从(单词计数)更改为(单词#####文件名计数) 我想要我的输出格式(Word######Filename count),你能告诉我哪里出了问题吗?我使用了输入拆分,但它不起作用。。请帮帮我Java 为什么我无法获取文件名&;在Hadoop中以格式(Word文件名计数)显示它?,java,hadoop,mapreduce,Java,Hadoop,Mapreduce,输入是一个名为Wiki-micro.txt的文本文件。。。字数计算程序运行正常。。我需要修改它&将其输出格式从(单词计数)更改为(单词#####文件名计数) 我想要我的输出格式(Word######Filename count),你能告诉我哪里出了问题吗?我使用了输入拆分,但它不起作用。。请帮帮我 public static class Map extends Mapper<LongWritable , Text , Text , IntWritable > { pri
public static class Map extends Mapper<LongWritable , Text , Text , IntWritable > {
private final static IntWritable one = new IntWritable( 1);
private Text word = new Text();
private static final Pattern WORD_BOUNDARY = Pattern .compile("\\s*\\b\\s*");
public void map( LongWritable offset, Text lineText, Context context)
throws IOException, InterruptedException {
String line = lineText.toString();
Text currentWord = new Text();
InputSplit input_split = context.getInputSplit();
String FName = ((FileSplit) input_split).getPath().getName();
for ( String word : WORD_BOUNDARY .split(line)) {
if (word.isEmpty()) {
continue;
}
currentWord = new Text(word);
context.write(currentWord, one);
context.write(new Text(FName), one);
}
}
公共静态类映射扩展映射器{
私有最终静态IntWritable one=新的IntWritable(1);
私有文本字=新文本();
私有静态最终模式WORD\u BOUNDARY=Pattern.compile(“\\s*\\b\\s*”);
公共无效映射(可长写偏移量、文本行文本、上下文)
抛出IOException、InterruptedException{
String line=lineText.toString();
Text currentWord=新文本();
InputSplit input_split=context.getInputSplit();
字符串FName=((FileSplit)input_split).getPath().getName();
for(字符串字:字_边界。拆分(行)){
if(word.isEmpty()){
继续;
}
currentWord=新文本(word);
上下文。写(currentWord,一个);
编写(新文本(FName),一个);
}
}
}不确定,但如果更换最后3行,会发生什么情况:
currentWord = new Text(word);
context.write(currentWord, one);
context.write(new Text(FName), one);
与
请提供更多信息,而不仅仅是“它不起作用”。它是否编译,是否运行?它有产出吗?输入和预期的样本输出是什么?感谢您的回复。。。它运行。。它显示输出&输出是(字计数器),它不显示文件名。输入是一个名为Wiki-micro.txt的文本文件。。。字数计算程序运行正常。。我需要的是修改它&将其输出格式从(单词数)更改为(单词#####文件名数)。mapreduce是一个要求吗?例如,为什么不使用Hive?MapReduce是一项要求。什么都不会发生。。。相同的输出。。我不知道为什么连“谢谢兄弟,你说得对。这个问题已经解决了。再次感谢。
currentWord = new Text(word + "####" + FName);
context.write(currentWord, one);
context.write(new Text(FName), one);