替换配置单元中的列

时间:2017-10-27 04:19:34

标签: hive hiveql

我在hive中创建了一个表,现在我正在尝试使用 REPLACE COLUMNS 替换列名。 更改查询是:

**ALTER TABLE emp1 REPLACE COLUMNS (
id INT eid int,
name STRING ename string,
sal INT esal int,
city string ecity string,
country string ecountry string);**

MismatchedTokenException异常(26!= 301)     在org.antlr.runtime.BaseRecognizer.recoverFromMismatchedToken(BaseRecognizer.java:617)     在org.antlr.runtime.BaseRecognizer.match(BaseRecognizer.java:115)     在org.apache.hadoop.hive.ql.parse.HiveParser.alterStatementSuffixAddCol(HiveParser.java:9898)     在org.apache.hadoop.hive.ql.parse.HiveParser.alterTblPartitionStatementSuffix(HiveParser.java:8524)     在org.apache.hadoop.hive.ql.parse.HiveParser.alterTableStatementSuffix(HiveParser.java:8139)     在org.apache.hadoop.hive.ql.parse.HiveParser.alterStatement(HiveParser.java:7190)     在org.apache.hadoop.hive.ql.parse.HiveParser.ddlStatement(HiveParser.java:2602)     在org.apache.hadoop.hive.ql.parse.HiveParser.execStatement(HiveParser.java:1589)     在org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:1065)     在org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:201)     在org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)     在org.apache.hadoop.hive.ql.Driver.compile(Driver.java:462)     在org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1276)     在org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1393)     在org.apache.hadoop.hive.ql.Driver.run(Driver.java:1205)     在org.apache.hadoop.hive.ql.Driver.run(Driver.java:1195)     在org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:220)     在org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:172)     在org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:383)     在org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:775)     在org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:693)     在org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:628)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:606)     在org.apache.hadoop.util.RunJar.run(RunJar.java:221)     在org.apache.hadoop.util.RunJar.main(RunJar.java:136) FAILED:ParseException第2行:7输入不匹配' eid'期待)' INT'在添加列声明

请帮帮我。我正在学习蜂巢

2 个答案:

答案 0 :(得分:0)

ALTER TABLE <TableName> REPLACE COLUMNS删除所有现有列并添加新的列集。

ALTER TABLE <TableName> REPLACE COLUMNS (EID INT, EName STRING);

REPLACE COLUMNS

对于您的方案,您可以使用ALTER TABLE <TableName> CHANGE <ColumnName>

ALTER TABLE <TableName> CHANGE ID EID INT;

此页面将为您提供大量信息ALTER COLUMNS

答案 1 :(得分:0)

REPLACE用于要在表中使用完全不同的列。否则,最好在alter语句中使用CHANGE选项重命名column_name。