Hive修改表模式

php中文网
发布: 2016-06-07 17:29:00
原创
1126人浏览过

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,...

可自行修改点亮模式的星级评分
可自行修改点亮模式的星级评分

可自行修改点亮模式的星级评分

可自行修改点亮模式的星级评分 23
查看详情 可自行修改点亮模式的星级评分

示例:

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数据的形式存在外部。

linux

相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号