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

£神魔★判官ぃ 2023-06-29 12:57 96阅读 0赞

分区表新增字段注意事项

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

  1. alter table table_name
  2. [partition partition_spec]
  3. add|replace columns (col_name data_type [comment col_comment], ...)
  4. [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选项,实际可参考如下例子

  1. alter table database.tablename add columns(
  2. col1 string comment '备注1'
  3. ,col2 string comment '备注2'
  4. ,col3 string comment '备注3'
  5. ,col4 string comment '备注4'
  6. ,col5 string comment '备注5'
  7. ) cascade;

发表评论

表情:
评论列表 (有 0 条评论,96人围观)

还没有评论,来说两句吧...

相关阅读

    相关 hive分区

    分区表 1 为什么出现分区表? 假设有海量的数据保存在hdfs的某一个hive表明对应的目录下,使用hive进行操作的时候,往往会搜索这个目录下的所有文件,这有时会

    相关 hive注意事项

    (1)hive中创建的表存储在mysql中和hdfs的/user/hive/warehouse路径下 表中的元数据存储在mysql中 (2)hive中创建的外部表在工作中最

    相关 hive 分区

    hive中创建分区表没有什么复杂的分区类型(范围分区、列表分区、hash分区、混合分区等)。分区列也不是表中的一个实际的字段,而是一个或者多个伪列。意思是说在表的数据文件中实际