您的位置:首页 > 其它

Hive---外部分区表的创建

2016-07-22 08:59 435 查看
hive> create external table tv2(id int,name string,sex string)  partitioned by(day int)
> row format delimited
> fields terminated by '\t'
> location 'hdfs://hadoop11:9000/dir2';
OK
Time taken: 0.08 seconds
但是此时表中数据并没有显示,如下:
hive> select * from tv2;
OK
Time taken: 0.06 seconds
原因:没有加入分区
接下来我们加入分区.
hive> alter table tv2 add  partition(day=22) location 'hdfs://hadoop11:9000/dir2';
OK
Time taken: 0.216 seconds
在此查看数据:
hive> select * from tv2;
OK
1       zhang   man     22
2       ming    woman   22
3       yang    man     22
4       li      man     22
5       si      woman   22
6       youyou  man     22
7       liyou   man     22
8       haha    woman   22
1       zhang   man     22
2       ming    woman   22
3       yang    man     22
4       li      man     22
5       si      woman   22
6       youyou  man     22
7       liyou   man     22
8       haha    woman   22
Time taken: 0.176 seconds


后续我是这样操作的:

hive> create external table t4(id int,city string,name string,sex string)
> partitioned by(day int)
> row format delimited
> fields terminated by '\t';

hadoop fs -put word.txt  hdfs://ns1/user/dd_edw/zmy_test.db/t2;

指定partition:
alter table t4 add partition(day=10) location 'hdfs://ns1/user/dd_edw/zmy_test.db/t4';
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: