修改表定义
仅修改Hive元数据,不会触动表中的数据,用户需要确定实际的数据布局符合元数据的定义。
修改表名:
ALTER TABLE table_name RENAME TO new_table_name
示例:alter table t_1 rename to t_x;
修改分区名:
alter table t_partition partition(department='xiangsheng',sex='male',howold=20) rename to partition(department='1',sex='1',howold=20);
添加分区:
alter table t_partition add partition (department='2',sex='0',howold=40);
删除分区:
alter table t_partition drop partition (department='2',sex='2',howold=24);
修改表的文件格式定义:
ALTER TABLE table_name [PARTITION partitionSpec] SET FILEFORMAT file_format
修改表的某个文件格式定义:
alter table t_partition partition(department='2',sex='0',howold=40 ) set fileformat sequencefile;
修改列名定义:
ALTER TABLE table_name CHANGE [COLUMN] col_old_name col_new_name column_type [COMMENTcol_comment] [FIRST|(AFTER column_name)]
alter table t_user change price jiage float first;
增加/替换列:
ALTER TABLE table_name ADD|REPLACE COLUMNS (col_name data_type[COMMENT col_comment], ...)
alter table t_user add columns (sex string,addr string);
alter table t_user replace columns (id string,age int,price float);