hive建外部表正常指向一个文件或者文件夹时很简单,然而需求是指向两个不同的文件夹起上级目录中还有其他文件不能直接指定上级目录,特此记录。
- 新建外部分区表
//新建外部分区表 create external table test(content string) partitioned by(date string);
-
将不同的文件/文件夹指向不同分区即可
//递归读取文件夹中的文件 set hive.mapred.supports.subdirectories=true; set mapred.input.dir.recursive=true; alter table test add partition(date= '2018-11-20') location '/dir1'; alter table test add partition(date= '2018-11-21') location '/dir2';
然后在表中就可以查看这两个文件夹下面的所有数据。