ITeye博客

hive修改表模式

hbjava1985 · 2015-02-06 10:58 · hive · 开源软件 · Markdown

hive用户可以通过alter语句更改table属性 Alter Partitions 增加partitions:


ALTER TABLE table_name 
      ADD [if not exists] 
      PARTITION partition_spec [location 'location1'] 
                partition_spec [location 'location2'] ...
partition_spec: 
      (partition_col = partition_col_value, partition_col = partiton_col_value, ...)

删除partitions:


ALTER TABLE table_name DROP [if exists] partition_spec, partition_spec,...

注意:

  1. hive可以同时增加或者删除多个partition
  2. 使用location关键字时,增加的partition以类似extend table数据的形式存在外部。

Alter Column 修改column属性(列名,列字段类型,列注释):


ALTER TABLE table_name 
      CHANGE [column] col_old_name col_new_name 
      column_type [comment col_comment] [first|after column_name]

增加/替换column(可以使用replace来删除不需要的字段):


ALTER TABLE table_name 
      ADD|REPLACE COLUMNS (col_name data_type [comment col_comment], ...)

注意:column alter仅仅修改table的元数据,而不会修改数据。

其它: hive alter语句还支持: 1.Alter Table Properties 2.Alter SerDe Properties 3.Alter Table/Partition File Format 4.Alter Table Storage Properties 5.Alter Table/Partition Location 6.Alter Table Touch 7.Alter Table (Un)Archive 8.Alter Table/Partition Protections 9.Alter Table Rename Partition reference:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-AlterTable%2FPartitionStatements

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。