Hive外部分区表加载flume打到hdfs上文件,读不到.tmp文件

原创
2016/04/01 19:00
阅读数 5K

    flume打到hdfs上时,按照文件大小生成文件,在达到指定大小之前数据都是以.tmp文件形式保存在hdfs上,hive外部表也会加载这些文件,但是当文件完成后.tmp会消失,这时候hive会报找不到文件的错误。解决方法是自己写hive的pathfilter类,hive加载数据的时候把tmp文件过滤掉不加载即可。

 错误信息如下:

自定义PathFilter类如下:

/**
 * 
   * @Title: FileFilterExcludeTmpFiles.java 
   * @Description: hive加载分区表时会加载.tmp的文件,该类型文件在flume滚动数据之后就会消失,此时hive找不到该文件就会报错
   * 			         该类会将.tmp的文件过滤掉,不加载进hive的分区表中 
   * @version V0.1.0
   * @see
 */
public class FileFilterExcludeTmpFiles implements PathFilter{
	private static final Logger logger = LoggerFactory.getLogger(FileFilterExcludeTmpFiles.class);
	public boolean accept(Path path) {
		// TODO Auto-generated method stub
		return !name.startsWith("_") && !name.startsWith(".") && !name.endsWith(".tmp");
	}

}



编写完后,打成jar包上传服务器,再修改hive-site.xml文件,修改如下:

<property>

    <name>hive.aux.jars.path</name><value>file:///usr/lib/mylib/FilterTmpPath.jar</value>

    <description>The location of the plugin jars that contain implementations of user defined functions and serdes.</description>

  </property>

  <property>

    <name>mapred.input.pathFilter.class</name>

    <value>cn.utils.hive.FileFilterExcludeTmpFiles</value>

  </property>



切记:不能有回车换行这样的字符,要不然回报一些乱七八糟的错误,博主就被坑的七零八碎的!!!!

展开阅读全文
加载中

作者的其它热门文章

打赏
1
0 收藏
分享
打赏
0 评论
0 收藏
1
分享
返回顶部
顶部