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