Hive分区表新增字段注意事项

分区表新增字段注意事项

对Hive表新增字段时,官方给出语法结构如下

alter table table_name
  [partition partition_spec]                
  add|replace columns (col_name data_type [comment col_comment], ...)
  [cascade|restrict]


其中cascade选项为选填的字段,但是对于分区表,一定要加上,否则其历史分区的元数据信息(metadata)将无法正常更新,导致访问历史分区时会报莫名的错误

对此,官方给出的使用建议为:

alter table add or replace columns cascade will override the table partition’s column metadata regardless of the table or partition’s protection mode. use with discretion.

本数仓由于大量表都是分区表,因此建议在增加字段时,记得增加CASCADE选项,实际可参考如下例子

alter table database.tablename add columns(
     col1       string  comment '备注1'
    ,col2       string  comment '备注2'
    ,col3       string  comment '备注3'
    ,col4       string  comment '备注4'
    ,col5       string  comment '备注5'
) cascade;
发布了106 篇原创文章 · 获赞 3 · 访问量 6104

猜你喜欢

转载自blog.csdn.net/qq_22049773/article/details/103950249