【问题标题】:Why am i unable to getFileName & display it in format (Word Filename Counts) In Hadoop?为什么我无法在 Hadoop 中获取文件名并以格式(Word 文件名计数)显示它?
【发布时间】:2020-06-19 20:44:03
【问题描述】:

输入是一个名为 Wiki-micro.txt 的文本文件……字数统计程序运行良好……我需要修改它并将其输出格式从 (Word count) 更改为 (Word### #文件名计数) 我想要我的输出格式(Word#####Filename 计数),你能告诉我哪里出错了吗?我使用了输入拆分,但它不起作用..请帮助我。

  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);
     }
  }

}

【问题讨论】:

  • 请提供更多信息,而不仅仅是“它不工作”。它编译,它运行吗?它会产生任何输出吗?输入和预期的样本输出是什么?
  • 感谢您的回复......它运行......它显示输出并且输出是(字计数器)它不显示文件名。
  • 输入是一个名为 Wiki-micro.txt 的文本文件......字数统计程序运行良好......我需要修改它并将其输出格式从(字数)更改为(字数####文件名计数)。
  • mapreduce 是必需的吗?例如,为什么不使用 Hive?
  • MapReduce 是一项要求。

标签: java hadoop mapreduce


【解决方案1】:

不确定,但如果替换最后 3 行会发生什么:

        currentWord  = new Text(word);
        context.write(currentWord, one);
        context.write(new Text(FName), one);

        currentWord  = new Text(word + "####" + FName);
        context.write(currentWord, one);
        context.write(new Text(FName), one);

【讨论】:

  • 什么都没有发生...相同的输出..我不知道为什么它甚至没有连接“###”
  • 谢谢兄弟,你是对的。问题已解决。再次感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-17
相关资源
最近更新 更多