Hive的表屬性操作
阿新 • • 發佈:2019-01-05
修改表名
alter table table_name rename to new_table_name
增加列
alter table tablename add columns(c1 string comment 'xxxx',
c2 long comment 'yyyy')
修改列名
alter table tablename change column c_Old c_New int comment 'XXXXXX'
after severity;
//可以把該列放到指定列的後而,或者使用’first’放到第一位。
修改表屬性tblproperties
alter table tablename set tblproperties(
property_name=property_value,property_name=property_value,…
);
修改表屬性serdeproperties
注意:針對無分割槽表與有分割槽表不同。
無分割槽
alter table tablename set serdeproperties(
'field.delim'='\t'
);
有分割槽
alter table tablename partition(dt='xxxx') set serdeproperties
('field.delim' ='\t');
修改location
佈置只有外部表可以指定location,內部表也可以指定location。
alter table table_name [partition(...)] set location 'path'
驗證:
select * from city;
刪除表同樣也會將指定位置的檔案目錄刪除。
內部錶轉外部表
alter table tablename set TBLPROPERTIES ('EXTERNAL' = 'TRUE');
外部錶轉內部表
alter table table_name set TBLPROPERTIES('EXTERNAL'='FALSE');