如何更改 hive 中的列名
Posted
技术标签:
【中文标题】如何更改 hive 中的列名【英文标题】:How to change a column name in hive 【发布时间】:2019-09-20 17:20:33 【问题描述】:我有一个 hive 表,其中列的名称是 orderbook.time
、orderbook.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】:您缺少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>;
【讨论】:
以上是关于如何更改 hive 中的列名的主要内容,如果未能解决你的问题,请参考以下文章