Hive修改表模式
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Hive修改表模式,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3241字,纯文字阅读大概需要5分钟。
内容图文
![Hive修改表模式](/upload/InfoBanner/zyjiaocheng/548/5fea6194946d4146bca7b682e73f61a9.jpg)
Hive用户可以通过alter语句更改table属性 Alter Partitions增加partitions: ALTER TABLE table_name ADD [IF NOT EXISTS]
Hive用户可以通过alter语句更改table属性
Alter Partitions
增加partitions:
ALTER TABLE table_name
ADD [IF NOT EXISTS]
PARTITION partition_spec [LOCATION 'location1']
partition_spec [LOCATION 'location2'] ...
partition_spec:
(partition_col = partition_col_value, partition_col = partiton_col_value, ...)
删除partitions:
ALTER TABLE table_name DROP [IF EXISTS] partition_spec, partition_spec,...
示例:
hive> create table alter_test(id INT, name STRING)
> partitioned by(dt STRING)
> row format delimited fields terminated by ',';
OK
Time taken: 0.259 seconds
hive> create table alter_tmp(id INT, name STRING,dt STRING)
> row format delimited fields terminated by ',';
OK
Time taken: 2.078 seconds
hive> load data local inpath '/home/work/data/alter_test.txt' into table alter_tmp;
Copying data from file:/home/work/data/alter_test.txt
Copying file: file:/home/work/data/alter_test.txt
Loading data to table default.alter_tmp
OK
Time taken: 2.71 seconds
hive> set hive.exec.dynamic.partition.mode=nonstrict;
hive> set hive.exec.dynamic.partition=true;
hive> insert overwrite table alter_test partition(dt)
> select id,name,dt
> from alter_tmp;
OK
Time taken: 25.988 seconds
$ cat alter_test2.txt
1,zxm,2012-08-13
2,ljz,2012-08-13
$ Hadoop fs -put alter_test2.txt /data/
hive> alter table alter_test add partition(dt='2012-08-13') location '/data';
OK
Time taken: 8.717 seconds
$ hadoop fs -ls /user/hive/warehouse/alter_test/
Found 3 items
drwxr-xr-x - work supergroup 0 2012-08-12 20:50 /user/hive/warehouse/alter_test/dt=2012-08-10
drwxr-xr-x - work supergroup 0 2012-08-12 20:50 /user/hive/warehouse/alter_test/dt=2012-08-11
drwxr-xr-x - work supergroup 0 2012-08-12 20:50 /user/hive/warehouse/alter_test/dt=2012-08-12
hive> select * from alter_test where dt='2012-08-13';
OK
1 zxm 2012-08-13
2 ljz 2012-08-13
Time taken: 6.064 seconds
$ hadoop fs -rmr /data
hive> select * from alter_test where dt='2012-08-13';
OK
Time taken: 1.903 seconds
hive> show partitions alter_test;
OK
dt=2012-08-10
dt=2012-08-11
dt=2012-08-12
dt=2012-08-13
Time taken: 0.546 seconds
> alter table alter_test add partition(dt='2012-08-14') partition(dt='2012-08-15');
OK
Time taken: 0.57 seconds
hive> alter table alter_test drop partition(dt='2012-08-10');
Dropping the partition dt=2012-08-10
OK
Time taken: 4.509 seconds
$ hadoop fs -ls /user/hive/warehouse/alter_test/
Found 4 items
drwxr-xr-x - work supergroup 0 2012-08-12 20:50 /user/hive/warehouse/alter_test/dt=2012-08-11
drwxr-xr-x - work supergroup 0 2012-08-12 20:50 /user/hive/warehouse/alter_test/dt=2012-08-12
drwxr-xr-x - work supergroup 0 2012-08-13 02:15 /user/hive/warehouse/alter_test/dt=2012-08-14
drwxr-xr-x - work supergroup 0 2012-08-13 02:15 /user/hive/warehouse/alter_test/dt=2012-08-15
注意:
1. hive可以同时增加或者删除多个partition
2. 使用location关键字时,,增加的partition以类似extend table数据的形式存在外部。
内容总结
以上是互联网集市为您收集整理的Hive修改表模式全部内容,希望文章能够帮你解决Hive修改表模式所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。