Hive Alter table change Column Name

前端 未结 3 1748
庸人自扰
庸人自扰 2020-12-23 21:00

I am trying to rename a columnName in Hive. Is there a way to rename column name in Hive .

tableA (column1 ,_c1,_c2) to tableA(column1,column2,column3) ??

相关标签:
3条回答
  • 2020-12-23 21:39

    Change Column Name/Type/Position/Comment:

    ALTER TABLE table_name CHANGE [COLUMN] col_old_name col_new_name column_type [COMMENT col_comment] [FIRST|AFTER column_name]

    Example:

    CREATE TABLE test_change (a int, b int, c int);
    
    // will change column a's name to a1
    ALTER TABLE test_change CHANGE a a1 INT;
    
    0 讨论(0)
  • 2020-12-23 21:58

    Command works only if "use" -command has been first used to define the database where working in. Table column renaming syntax using DATABASE.TABLE throws error and does not work. Version: HIVE 0.12.

    EXAMPLE:

    hive> ALTER TABLE databasename.tablename CHANGE old_column_name new_column_name;
    
      MismatchedTokenException(49!=90)
            at org.antlr.runtime.BaseRecognizer.recoverFromMismatchedToken(BaseRecognizer.java:617)
            at org.antlr.runtime.BaseRecognizer.match(BaseRecognizer.java:115)
            at org.apache.hadoop.hive.ql.parse.HiveParser.alterStatementSuffixExchangePartition(HiveParser.java:11492)
            ...
    
    hive> use databasename;
    
    hive> ALTER TABLE tablename CHANGE old_column_name new_column_name;
    
    OK
    
    0 讨论(0)
  • 2020-12-23 22:01
    alter table table_name change old_col_name new_col_name new_col_type;
    

    Here is the example

    hive> alter table test change userVisit userVisit2 STRING;      
        OK
        Time taken: 0.26 seconds
        hive> describe test;                                      
        OK
        uservisit2              string                                      
        category                string                                      
        uuid                    string                                      
        Time taken: 0.213 seconds, Fetched: 3 row(s)
    
    0 讨论(0)
提交回复
热议问题