Reputation: 567
I created the following table in 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;
The table is created successfully. I am trying to do the following insert
insert into TABLE employee (eid,name,salary,destination) VALUES (1,'avi','100000','boston');
However, I am getting the following error messages.
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
How can I fix this?
Upvotes: 2
Views: 11325
Reputation: 1
You can't insert the data like this or insert command because insert command use in SQL.
For loading data into hive you have to create a one text file and you have to upload that file using load command.
For example
LOAD DATA LOCAL INPATH 'YOUR TXT FILE LOCATION' OVERWRITE INTO TABLE TABLENAME;
Upvotes: -1
Reputation: 44921
INSERT INTO employee select 1, 'avi', '100000', 'boston';
It seems your version does not support insert
columns list nor values
.
P.s.
The error message is very clear.
You should focus on the last line.
Upvotes: 3
Reputation: 544
Remember you need quotation marks as you are trying to insert Strings. Also, the field names are not necessary as you are inserting a value for all fields in your table. You might simply try the following:
INSERT INTO TABLE employee
VALUES (1, 'avi', '100000', 'boston');
Upvotes: 1