1. 程式人生 > >Hive表 增改刪欄位

Hive表 增改刪欄位

基本語法:

ALTER TABLE name RENAME TO new_name
ALTER TABLE name ADD COLUMNS (col_spec[, col_spec ...])
ALTER TABLE name DROP [COLUMN] column_name
ALTER TABLE name CHANGE column_name new_name new_type
ALTER TABLE name REPLACE COLUMNS (col_spec[, col_spec ...])
refer: https://www.yiibai.com/hive/hive_alter_table.html

自己實驗:

1. alter table d_extra.dm_usr_mxdai_risk_analysis add columns(test1 int, test2 int);   ------works

    desc d_extra.dm_usr_mxdai_risk_analysis; 

   可以看出新欄位已經新增成功

1.1. alter table d_extra.dm_usr_mxdai_risk_analysis add column test1 int; ------doesn't work

2. alter table d_extra.dm_usr_mxdai_risk_analysis drop

column test1;  -----doesn't work

報錯:

Error: Error while compiling statement: FAILED: ParseException line 1:52 mismatched input 'column' expecting PARTITION near 'drop' in drop partition statement (state=42000,code=40000)

是不是隻能drop partition 而不能drop column??


3. alter table d_extra.dm_usr_mxdai_risk_analysis change
test1 risk_1_138 string;  ------works