记一次mapreduce读取不到输入文件的问题
2017-05-04 11:29
429 查看
hdfs上输入文件所在包含两个目录,分别是: /20170503/shoplast/
/20170503/shop/
但是我想过滤掉shop,只把shoplast作为输入
故我实现了过滤器如下:
结果 Total input paths to process : 0 输入文件数为0! 这什么鬼!
-----------------------------
看了源码之后感觉自己是个弱智啊。源码如下:
好吧,接下来修改下过滤器吧。
结论:过滤器不光针对最终的文件,输入路径的父目录也要应用过滤器。
/20170503/shop/
但是我想过滤掉shop,只把shoplast作为输入
故我实现了过滤器如下:
public static class FileNameFilter implements PathFilter { @Override public boolean accept(Path path) { if (path.getName().endsWith("last")) { return true; } else { return false; } } }然后mapreduce的输入设为 /20170503/*, 开始执行。。。
结果 Total input paths to process : 0 输入文件数为0! 这什么鬼!
-----------------------------
看了源码之后感觉自己是个弱智啊。源码如下:
protected List<FileStatus> listStatus(JobContext job ) throws IOException { List<FileStatus> result = new ArrayList<FileStatus>(); Path[] dirs = getInputPaths(job); if (dirs.length == 0) { throw new IOException("No input paths specified in job"); } // get tokens for all the required FileSystems.. TokenCache.obtainTokensForNamenodes(job.getCredentials(), dirs, job.getConfiguration()); // Whether we need to recursive look into the directory structure boolean recursive = getInputDirRecursive(job); List<IOException> errors = new ArrayList<IOException>(); // creates a MultiPathFilter with the hiddenFileFilter and the // user provided one (if any). List<PathFilter> filters = new ArrayList<PathFilter>(); filters.add(hiddenFileFilter); PathFilter jobFilter = getInputPathFilter(job); if (jobFilter != null) { filters.add(jobFilter); } PathFilter inputFilter = new MultiPathFilter(filters); for (int i=0; i < dirs.length; ++i) { Path p = dirs[i]; FileSystem fs = p.getFileSystem(job.getConfiguration()); FileStatus[] matches = fs.globStatus(p, inputFilter); if (matches == null) { errors.add(new IOException("Input path does not exist: " + p)); } else if (matches.length == 0) { errors.add(new IOException("Input Pattern " + p + " matches 0 files")); } else { for (FileStatus globStat: matches) { if (globStat.isDirectory()) { RemoteIterator<LocatedFileStatus> iter = fs.listLocatedStatus(globStat.getPath()); while (iter.hasNext()) { LocatedFileStatus stat = iter.next(); if (inputFilter.accept(stat.getPath())) { if (recursive && stat.isDirectory()) { addInputPathRecursively(result, fs, stat.getPath(), inputFilter); } else { result.add(stat); } } } } else { result.add(globStat); } } } } if (!errors.isEmpty()) { throw new InvalidInputException(errors); } LOG.info("Total input paths to process : " + result.size()); return result; }仔细看这段
for (FileStatus globStat: matches) { if (globStat.isDirectory()) { RemoteIterator<LocatedFileStatus> iter = fs.listLocatedStatus(globStat.getPath()); while (iter.hasNext()) { LocatedFileStatus stat = iter.next(); if (inputFilter.accept(stat.getPath())) { if (recursive && stat.isDirectory()) { addInputPathRecursively(result, fs, stat.getPath(), inputFilter); } else { result.add(stat); } } } } else { result.add(globStat); } }以为过滤器是针对最终的输入文件名。如果输入的路径为目录,它会跟进里面的文件的
好吧,接下来修改下过滤器吧。
public static class FileNameFilter implements PathFilter { @Override public boolean accept(Path path) { if (path.getParent().getName().endsWith("last")) { return true; } else { return false; } } }再次运行,当当当
cause:org.apache.hadoop.mapreduce.lib.input.InvalidInputException: Input Pattern hdfs://20170503/* matches 0 files Exception in thread "main" org.apache.hadoop.mapreduce.lib.input.InvalidInputException: Input Pattern hdfs://20170503/* matches 0 files还是读取不到输入文件,这是什么原因呢?看源码吧,还是上面贴出的那个方法。
Path p = dirs[i]; FileSystem fs = p.getFileSystem(job.getConfiguration()); FileStatus[] matches = fs.globStatus(p, inputFilter); if (matches == null) { errors.add(new IOException("Input path does not exist: " + p)); } else if (matches.length == 0) { errors.add(new IOException("Input Pattern " + p + " matches 0 files")); }不继续跟进globStatus方法了,想了解的自己去看源码吧。总之,这里是针对父目录的也应用了过滤器
结论:过滤器不光针对最终的文件,输入路径的父目录也要应用过滤器。
相关文章推荐
- 文件输入中的good()函数读取不到最后一个字符的问题
- mybatis3.0x升级整合spring问题(读取不到properties文件属性)
- [Python] 中文编码问题:raw_input输入、文件读取、变量比较等str、unicode、utf-8转换问题
- 基于maven管理的项目中spring+mybatis配置数据源读取不到properties属性文件的问题
- spring中mybatis配置数据源读取不到properties属性文件的问题
- shell脚本格式问题导致读取不到文件状态
- thinkPHP5隐藏入口文件index.php后 读取不到资源问题
- 以不同用户身份运行程序,/savecred只需要输入一次密码(GetTokenByName取得EXPLORER.EXE的令牌,然后调用CreateProcessAsUser,而且使用LoadUserProfile解决另存文件的问题)good
- C++文件读取及输入问题
- [Python爬虫] 中文编码问题:raw_input输入、文件读取、变量比较等str、unicode、utf-8转换问题
- Eclipse中通过FileSystemXmlApplicationContext读取不到配置文件问题
- 中文编码问题:raw_input输入、文件读取、变量比较等str、unicode、utf-8转换问题
- IT咨询顾问:一次吐血的项目救火 java或判断优化小技巧 asp.net core Session的测试使用心得 【.NET架构】BIM软件架构02:Web管控平台后台架构 NetCore入门篇:(十一)NetCore项目读取配置文件appsettings.json 使用LINQ生成Where的SQL语句 js_jquery_创建cookie有效期问题_时区问题
- opencv cvLoadImage(mPath)通过打开文件读取图片,读不到图片问题
- mapreduce中map方法一次读取整个文件
- 获取TXT文件,解决读取TXT乱码问题,查找所输入字是否在TXT文件中,
- 读取属性文件时提示FileNotFound或路径查找不到时遇到的问题备忘
- c++读取文件及输入到文件的相关问题
- 用C语言读取大文件的问题
- 解决Java读取properties文件的中文问题的新办法(不使用native2ascii.exe及其他工具)