1.修改表名稱:
hive > alter table log_messages to logmsgs;
2.增加列:
hive > alter table log_messages add coloumns(
app_name string comment 'Application name',
session_id long comment 'The current session id'
);
增加列的表的最后一個字段之后竟痰,在分區(qū)字段之前添加窿祥。
3.修改列
我們可以對某個字段進(jìn)行重命名相叁,并修改其位置党涕、類型或者注釋:
hive > alter table log_messages
change column hms hours_minutes_seconds int
comment 'The hours,minutes and seconds part of the timestamp' afer severity;
即使字段名或者字段類型沒有改變放典,用戶也需要完全指定舊的字段名逝变,并給出新的字段名及新的字段類型。
關(guān)鍵字column和comment子句都是可選的奋构。
4.刪除列:
Hive沒有刪除指定列的命令壳影,Hive通過replace命令變向?qū)崿F(xiàn)刪除列的功能。
replace命令將用新的列信息替換之前的列信息弥臼,相當(dāng)于刪除之前全部的列宴咧,再用新的列代替。
hive > alter table log_messages replace columns (
hours_mins_secs int comment 'hour,minute,seconds from timestamp',
severity string comment 'The message severity',
message string comment 'The rest of the message'
)