参考:http://blog.csdn.net/liweiwei71/article/details/23434189
对于分区表
drop table track_log;
create table track_log (
id string ,
url string ,
referer string ,
keyword string ,
type string ,
guid string ,
pageId string ,
moduleId string ,
linkId string ,
attachedInfo string ,
sessionId string ,
trackerU string ,
trackerType string ,
ip string ,
trackerSrc string ,
cookie string ,
orderCode string ,
trackTime string ,
endUserId string ,
firstLink string ,
sessionViewNo string ,
productId string ,
curMerchantId string ,
provinceId string ,
cityId string )
PARTITIONED BY (ds string,hour string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
不能再用--hive-table, --hive-partition-key, --hive-partition-value这三个参数。因为这样只能向单个分区导入数据,无法指定多个分区;其次,--where条件中没有用and。
所以可以分两步解决这个问题:
-m 1
--target-dir /user/hive/warehouse/track_log/ds=20150827/hour=18
--fields-terminated-by '\t' //这个也很重要,否则查询一列时会返回多列
结果:
开始没结果
hive> select id from track_log limit 2;
OK
Time taken: 0.584 seconds
加入分区就好了
hive> alter table track_log add partition(ds='20150828' ,hour='18') location '/user/hive/warehouse/track_log/ds=20150828/hour=18';
OK
Time taken: 0.759 seconds
hive> select id from track_log limit 2;
OK
121508281810000000
121508281810000001