温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Hive如何更改表的属性

发布时间:2021-12-10 14:08:53 来源:亿速云 阅读:189 作者:小新 栏目:大数据

这篇文章主要为大家展示了“Hive如何更改表的属性”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Hive如何更改表的属性”这篇文章吧。

1、修改表名
    alter table table_name rename to new_table_name;
    例1:alter table ruoze_emp rename to emp;
2、修改列名
    alter table tablename change column column_orign column_new int(修改后列的属性) comment 'column_name'
    after severity;//可以把该列放到指定列的后面,或者使用‘first’放到第一位
    将表tablename中的列column_orign修改成column_new,同时指定修改后的列名称的属性,comment是这个列的注释
    例1:alter table emp change column age uage double comment 'column age' after id;
3、增加列
    alter table tablename add columns(column1 string comment 'xxxx',column2 long comment 'yyyy')
    例1:alter table emp add columns(age int);
4、替换表
    ALTER TABLE table_name [PARTITION partition_spec] ADD|REPLACE COLUMNS (col_name data_type [COMMENT col_comment], ...) [CASCADE|RESTRICT]                         -- (Note: Hive 1.1.0 and later)
    例1:ALTER TABLE emp REPLACE COLUMNS (age int, uage int);
5、查看表的属性
    desc formatted tablename;
6、修改表的属性
    (1)alter table table_name set tblproperties('property_name'='new_value');
       将table_name表中的comment属性值修改成'new_value';
    (2)alter table emp set serdeproperties ("field.delim"="\t");
       将表table_name中的字段分割符修改成'\t',注意,这是在表没有分区的情况下
    例1:create table emp(id int,uname string)row format delimited fields terminated by '#' lines terminated by '\n' stored as textfile;
       alter table emp set serdeproperties('field.delim'='\t');这条语句将t8表中的字段分隔符'#'修改成'\t';
    例2:create table emp(id int,uname string) partitioned by(dt=string) row foramt delimited fields terminated by '\n' stored as textfile;
       alter table emp partition(dt='20180108') set serdeproperties('field.delim=\t');
    (3)alter table table_name[partition] set location 'path'
       alter table emp set TBLPROPERTIES('EXTERNAL'='TRUE');//内部表转化成外部表
       alter table emp set TBLPROPERTIES('EXTERNAL'='FALSE');//外部表转成内部表

    注意:由于emp默认是内表,所以在删除表emp时,它的数据包括文件目录全部被删除,为了防止这种情况发生,可以将表emp修改成外表,
    通过语句:alter table emp set tblproperties('EXTERNAL'='TRUE');同样也可以将外部表修改为内部表,
    可以通过语句:alter table city set tblproperties('EXTERNAL'='FALSE');
    (4)其他修改表属性的命令:
       alter table properties; alter serde properties;
       alter table/partition file format;
       alter table storage properties;
       alter table rename partition;
       alter table set location;

以上是“Hive如何更改表的属性”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI