flume打到hdfs上时,按照文件大小生成文件,在达到指定大小以前数据都是以.tmp文件形式保存在hdfs上,hive外部表也会加载这些文件,可是当文件完成后.tmp会消失,这时候hive会报找不到文件的错误。解决方法是本身写hive的pathfilter类,hive加载数据的时候把tmp文件过滤掉不加载便可。 java
错误信息以下: 服务器
自定义PathFilter类以下: code
/** * * @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"); } }
<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>切记:不能有回车换行这样的字符,要否则回报一些乱七八糟的错误,博主就被坑的七零八碎的!!!!