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

来源:互联网 发布:金马网络服装批发城 编辑:程序博客网 时间:2024/05/18 11:13

摘要 flume打到hdfs上时,按照文件大小生成文件,在达到指定大小之前数据都是以.tmp文件形式保存在hdfs上,hive外部表也会加载这些文件,但是当文件完成后.tmp会消失,这时候hive会报找不到文件的错误。类似于:Caused by:org.apache.ahdoop.ipc.RemoteException(java.io.FileNotFoundException):File does not exist:/......../..../..xxx.log.tmp

hive外部分区表加载不到flume的临时文件hive自定义Pathfilter过滤加载数据的方式hive过滤数据文件


 

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

 错误信息如下:

自定义PathFilter类如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
 
   * @Title: FileFilterExcludeTmpFiles.java 
   * @Description: hive加载分区表时会加载.tmp的文件,该类型文件在flume滚动数据之后就会消失,此时hive找不到该文件就会报错
   *                     该类会将.tmp的文件过滤掉,不加载进hive的分区表中 
   * @version V0.1.0
   * @see
 */public class FileFilterExcludeTmpFilesimplements PathFilter{
    privatestatic final Logger logger = LoggerFactory.getLogger(FileFilterExcludeTmpFiles.class);
    publicboolean accept(Path path) {
        // TODO Auto-generated method stub        return!name.startsWith("_") && !name.startsWith(".") && !name.endsWith(".tmp");
    }
  
}



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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<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>



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