Hive 修改表结构常用操作

it2026-03-13  6

添加列  add columns

    alter table table_name add columns (id int comment '主键ID' ) ;

    默认在表所有字段之后,分区字段之前。

替换列 replace columns ,会替换所有列,慎用!

    alter table table_name replace columns (id int comment '主键ID' ) ;

修改字段名称、类型、注释 change 

    1. 修改字段注释

      alter table table_name change id id int comment '订单号'; 

    2. 修改列名, id 改成 tab_id

      alter table table_name change id tab_id int comment '订单号'; 

删除表分区

    alter table table_name drop if exists partition (statis_date='20151015'); 

    -- 删除20180101之前的所有分区

    alter table example_table_name drop if exists partition (dt <'20180101');

删除文件(如果是外部表)  

    Hive 模式: dfs -rm -r -f /user/kimbo/table_name/statis_date=${date_7} ;

    命令行模式: hadoop fs -rm -r  /user/kimbo/table_name/statis_date=${date_7} ;

转载于:https://www.cnblogs.com/shujuxiong/p/9979892.html

最新回复(0)