Hive:NoViableAltException(283 @ [])和Parse Exception

时间:2017-05-02 14:25:28

标签: sql hadoop hive

我在hive中创建了下表。

CREATE TABLE IF NOT EXISTS employee (
   eid int,
   name String,
   salary String,
   destination String
 )
 COMMENT ‘Employee details’
 ROW FORMAT DELIMITED
 FIELDS TERMINATED BY ‘\t’
 LINES TERMINATED BY ‘\n’
 STORED AS TEXTFILE;

表格已成功创建。我正在尝试执行以下插入

insert into TABLE employee (eid,name,salary,destination) VALUES (1,'avi','100000','boston');

但是,我收到以下错误消息。

NoViableAltException(283@[])
        at org.apache.hadoop.hive.ql.parse.HiveParser.regularBody(HiveParser.java:39678)
        at org.apache.hadoop.hive.ql.parse.HiveParser.queryStatementExpressionBody(HiveParser.java:38904)
        at org.apache.hadoop.hive.ql.parse.HiveParser.queryStatementExpression(HiveParser.java:38780)
        at org.apache.hadoop.hive.ql.parse.HiveParser.execStatement(HiveParser.java:1514)
        at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:1052)
        at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:199)
        at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:389)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:303)
        at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1067)
        at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1129)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1004)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:994)
        at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:201)
        at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:153)
        at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:364)
        at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:712)
        at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:631)
        at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:570)
        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:221)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
FAILED: ParseException line 1:27 cannot recognize input near '(' 'eid' ',' in statement

我该如何解决这个问题?

3 个答案:

答案 0 :(得分:2)

INSERT INTO employee select 1, 'avi', '100000', 'boston';

您的版本似乎不支持insert列列表,也不支持values

P.S。
错误信息非常清楚 你应该专注于最后一行。

答案 1 :(得分:1)

请记住,在尝试插入字符串时需要使用引号。此外,当您为表中的所有字段插入值时,不需要字段名称。您可以尝试以下方法:

INSERT INTO TABLE employee
VALUES (1, 'avi', '100000', 'boston');

答案 2 :(得分:-1)

您不能像这样插入数据或插入命令,因为插入命令在SQL中使用。

要将数据加载到配置单元中,您必须创建一个文本文件,并且必须使用load命令上传该文件。

例如

LOAD DATA LOCAL INPATH  'YOUR TXT FILE LOCATION' OVERWRITE INTO TABLE TABLENAME;