Hive外部表使用分区partition
1)创建外部表
create external table test(username String,work string) PARTITIONED BY(year String, month String, day String) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/tmp/test/';
2)修改表创建分区
alter table test add partition (year='2010', month='04', day='18') location '2010/04/18';
3)查看外部表目录变化- [Hadoop@hadoopmaster hadoop-1.0.3]$ bin/hadoop fs -mkdir /tmp/test/
- [hadoop@hadoopmaster hadoop-1.0.3]$ bin/hadoop fs -ls /tmp/test/
- Found 1 items
- drwxr-xr-x - hadoop supergroup 0 2012-07-03 19:17 /tmp/test/2010
- [hadoop@hadoopmaster hadoop-1.0.3]$ bin/hadoop fs -ls /tmp/test/2010
- Found 1 items
- drwxr-xr-x - hadoop supergroup 0 2012-07-03 19:17 /tmp/test/2010/04
- [hadoop@hadoopmaster hadoop-1.0.3]$ bin/hadoop fs -ls /tmp/test/2010/04
- Found 1 items
- drwxr-xr-x - hadoop supergroup 0 2012-07-03 19:17 /tmp/test/2010/04/18
4)给外部表加载数据
bin/hadoop fs -put /tmp/test.txt /tmp/test/2010/04/18/
5)执行测试查询
- hive> select * from test limit 10;
- OK
- zzz it 2010 04 18
- xxx edu 2010 04 18
- Time taken: 0.42 seconds
- hive> select * from test where year='2010' and month='04' and day='18' limit 10;
- OK
- zzz it 2010 04 18
- xxx edu 2010 04 18
- Time taken: 0.287 seconds
- hive> select * from test where year='2010' and month='04' and day='19' limit 10;
- OK
- Time taken: 0.113 seconds
- hive>
相关推荐
IT之家 2020-03-11
graseed 2020-10-28
zbkyumlei 2020-10-12
SXIAOYI 2020-09-16
jinhao 2020-09-07
impress 2020-08-26
liuqipao 2020-07-07
淡风wisdon大大 2020-06-06
yoohsummer 2020-06-01
chenjia00 2020-05-29
baike 2020-05-19
扭来不叫牛奶 2020-05-08
hxmilyy 2020-05-11
黎豆子 2020-05-07
xiongweiwei00 2020-04-29
Cypress 2020-04-25
冰蝶 2020-04-20