from http://blog.csdn.net/azhao_dn/article/details/7713017
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/';
- alter table test add partition (year='2010', month='04', day='18') location '2010/04/18';
ps:分区的名称不能和字段的名称重复
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
- bin/hadoop fs -put /tmp/test.txt /tmp/test/2010/04/18/
- 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>