Is there a way to alter column type in hive table?

前端 未结 3 778
梦毁少年i
梦毁少年i 2020-12-24 06:15

The current schema is:

hive> describe tableA;
OK
id      int
ts      timestamp

I want to change ts column to be BIGIN

相关标签:
3条回答
  • 2020-12-24 06:49

    Found the solution:

    ALTER TABLE tableA CHANGE ts ts BIGINT AFTER id;
    

    See this for complete details: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-AlterColumn

    0 讨论(0)
  • 2020-12-24 06:51

    It's simple usually to change/modify the exesting table use this syntax in Hive.

    ALTER TABLE table_name CHANGE old_col_name new_col_name new_data_type
    

    Here you can change your column name and data type at a time. If you don't want to change col_name simply makes old_col_name and new_col_name are same. Ok.

    Come to your problem. If you want to change ts column to be BIGINT.It means column-type you are changing. so simply run this query.

    ALTER TABLE tableA CHANGE ts ts BIGINT;
    

    Here ts and ts are same, means you are not changing column name, but changing column-type; if you wish to change column name also simply run it.

    ALTER TABLE tableA CHANGE ts new_col BIGINT;
    

    Now run

    hive> describe tableA;
    OK
    id      int
    new_col      bigint
    0 讨论(0)
  • 2020-12-24 06:56
    ALTER TABLE table_name CHANGE col_name col_name newType
    
    0 讨论(0)
提交回复
热议问题