【问题标题】:Reading from a specific file from a directory containing many files in hadoop从包含hadoop中许多文件的目录中读取特定文件
【发布时间】:2014-12-30 05:01:56
【问题描述】:

我想根据文件名从 hadoop 中存在的文件列表中读取特定文件。如果文件名与我的名字匹配,我想处理该文件数据。这是我在地图方法中尝试过的以下方式

public void map(LongWritable key,Text value,Context con) throws IOException, InterruptedException
        {
            FileSplit fs =(FileSplit) con.getInputSplit(); 
            String filename= fs.getPath().getName();
            filename=filename.split("-")[0];
            if(filename.equals("aak"))
            {
                    String[] tokens = value.toString().split("\t");
                    String name=tokens[0];
                    con.write(new Text("mrs"), new Text("filename"));
            }

        }

【问题讨论】:

    标签: hadoop mapreduce hadoop-yarn


    【解决方案1】:

    您需要编写自定义 PathFilter 实现,然后在驱动程序代码中对 FileInputFormat 使用 setInputPathFilter。请看下面的链接:

    https://hadoopi.wordpress.com/2013/07/29/hadoop-filter-input-files-used-for-mapreduce/

    【讨论】:

      【解决方案2】:

      要么使用 PathFilter,正如 Arani 建议的那样(为此 +1),或者,
      如果您选择输入文件的标准只是以字符串“aak-”开头,那么我认为,您可以通过更改主方法(驱动程序类)中的输入路径轻松地做您想做的事情,如下所示:

      替换:

      String inputPath = "/your/input/path"; //containing the file /your/input/path/aak-00000   
      FileInputFormat.setInputPaths(conf, new Path(inputPath));
      

      与:

      String inputPath = "/your/input/path"; //containing the file /your/input/path/aak-00000
      FileInputFormat.setInputPaths(conf, new Path(inputPath+"/aak-*"))
      

      【讨论】:

        猜你喜欢
        • 2014-09-14
        • 2017-03-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-19
        • 2019-07-10
        • 1970-01-01
        相关资源
        最近更新 更多