如何在配置单元中更改列名称

时间:2019-09-20 17:20:33

标签: hive

我有一个配置单元表,其中列的名称为orderbook.timeorderbook.price等。我想从列名称中删除前缀orderbook,而无需更改列表中的其他任何内容。表。我正在使用以下命令

alter table orderbook change orderbook.time time;

但是它给了我以下错误信息

NoViableAltException(17@[])
    at org.apache.hadoop.hive.ql.parse.HiveParser_IdentifiersParser.identifier(HiveParser_IdentifiersParser.java:11568)
    at org.apache.hadoop.hive.ql.parse.HiveParser.identifier(HiveParser.java:45214)
    at org.apache.hadoop.hive.ql.parse.HiveParser.alterStatementSuffixRenameCol(HiveParser.java:10258)
    at org.apache.hadoop.hive.ql.parse.HiveParser.alterTblPartitionStatementSuffix(HiveParser.java:8533)
    at org.apache.hadoop.hive.ql.parse.HiveParser.alterTableStatementSuffix(HiveParser.java:8148)
    at org.apache.hadoop.hive.ql.parse.HiveParser.alterStatement(HiveParser.java:7192)
    at org.apache.hadoop.hive.ql.parse.HiveParser.ddlStatement(HiveParser.java:2604)
    at org.apache.hadoop.hive.ql.parse.HiveParser.execStatement(HiveParser.java:1591)
    at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:1067)
    at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:205)
    at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:170)
    at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:524)
    at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1358)
    at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1475)
    at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1287)
    at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1277)
    at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:226)
    at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:175)
    at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:389)
    at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:781)
    at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:699)
    at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:634)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:226)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:141)
FAILED: ParseException line 1:38 cannot recognize input near '.' 'time' 'time' in rename column name

我试图将旧的列名(例如orderbook.time)放在quatation中,但是我收到了相同的错误消息。如何更改列名?

1 个答案:

答案 0 :(得分:0)

缺少time column的数据类型,然后尝试使用`(反引号)

转义带有句点的列名

Try with below query:

alter table orderbook change `orderbook.time` time <data_type>;
  

In general Syntax to change column name in Hive:

alter table <db_name>.<table_name> change `<col_name>` `<new_col_name>` <data_type>;