zoukankan      html  css  js  c++  java
  • hadoop拾遗(二)---- 文件模式

      在单个操作中处理一批文件,这是一个常见的要求。举例来说,处理日志的MapReduce作业可能需要分析一个月内包含在大量目录中的日志文件。在一个表达式中使用通配符来匹配多个文件是比较方便的,无需列举第个文件 和目录来指定输入,该操作称为"通配"(globbing)。Hadoop 为执行通配提供了两个FileSystem方法:

    public FileStatus[] globStatus(Path pathPattern) throws IOException

    public FileStatus[] globStatus(Paht pathPattern , PathFileter filter) throws IOException

    globStatus()方法返回与路径相匹配的所有文件的 FileStatus 对象数据,并按Hadoop支持的通配符与Unix bash相同

      PathFilter 对象

      通配符模式并不总能够精确地描述我们想要访问的文件集。比如,使用通配格式排除一个特定的文件就不太可能。FileSystem中的listStatus()和globStatus()方法提供了可先的PathFilter对象,使我们能够通过编程方式控制通配符:

    import org.apache.hadoop.fs.Path;
    import org.apache.hadoop.fs.PathFilter;
    
    public class RegexExcludePathFilter implements PathFilter {
    
    	private final String regex;
    	
    	public RegexExcludePathFilter(String regex)
    	{
    		this.regex = regex;
    	}
    	
    	public boolean accept(Path path)
    	{
    		return !path.toString().matches(regex);
    	}
    }
    

     

    //按如下方式获得筛选后的路径

    fs.globStatus(new Path("/2007/*/*") , new RegexExcludeFilter("^.*/2007/12/31$"));

  • 相关阅读:
    element 树形控件使用
    js粘贴图片并显示
    vue-element Tree树形控件通过id默认选中
    解决win10shift+右键显示在此处打开powershell而不是命令窗口的问题
    maven安装与配置
    解决dos窗口中文乱码问题
    vue单页面应用刷新网页后vuex的state数据丢失的解决方案
    vue 单个倒计时组件
    js将秒转换为时分秒
    vue3.0用vue-awesome-swiper
  • 原文地址:https://www.cnblogs.com/nocml/p/3293015.html
Copyright © 2011-2022 走看看