CREATE TABLE table_a ( id int, name string comment '姓名',) comment '表A' PARTITIONED BY (dt string) ROW format delimited fields terminated by '\t' lines terminated by '\n' stored as textfile;
现在新建一个表B,建表语句和表A完全一样,把表A的数据导入到表B,可以这么做:
1 2
INSERT OVERWRITE TABLE table_b partition(dt) select * from table_a
alter table table_name partition(dt='20151014') rename to partition(dt='20151014old');
删除表
1
drop table if exists table_name;
删除/添加分区
1 2 3
alter table table_name drop partition(dt='20151014'); alter table table_name add if not exists partition(dt='20151018'); alter table table_name add if not exists partition(dt<'20151018'); # 批量删除分区
清空表数据
1
insert overwrite table table_name select * from table_name where 1=0;
删除指定条件的数据
1 2 3 4
# 把Hive表中link_end_date字段为'2099-12-31'的数据删掉,即只要不等于这个值就再插回源表中 insert overwrite table ap_fuwu_tb_complaint_his select * from ap_fuwu_tb_complaint_his where link_end_date<>'2099-12-31';
将数据插入到指定分区
1 2 3
alter table table_name add if not exists partition(dt='20151021old'); insert overwrite table table_name partition(dt='20151021old') SELECT * FROM table_name WHERE dt='20151021';
注意: 如果列不等,则把*换成对应的列。
重命名列名
1 2 3 4 5 6 7 8
alter table table_name CHANGE old_col_name new_col_name field_type;