在HIVE SQL中,我在两个不同的cloudera版本中运行了相同的查询。 Cloudera VM 5.10不会引起任何问题。但是另一个版本的cloudera -CDH-5.1.0-1.cdh5.1.0.p0.53抛出错误。

hive> select * from t;
OK
Time taken: 1.803 seconds
hive> insert into table t values (1);
NoViableAltException(26@[])
        at org.apache.hadoop.hive.ql.parse.HiveParser_SelectClauseParser.selectClause(HiveParser_SelectClauseParser.java:713)
        at org.apache.hadoop.hive.ql.parse.HiveParser.selectClause(HiveParser.java:35992)
        at org.apache.hadoop.hive.ql.parse.HiveParser.regular_body(HiveParser.java:33510)
        at org.apache.hadoop.hive.ql.parse.HiveParser.queryStatement(HiveParser.java:33389)
        at org.apache.hadoop.hive.ql.parse.HiveParser.queryStatementExpression(HiveParser.java:33169)
        at org.apache.hadoop.hive.ql.parse.HiveParser.execStatement(HiveParser.java:1284)
        at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:983)
        at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:190)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:434)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:352)
        at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:995)
        at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1038)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:931)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:921)
        at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:268)
        at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:220)
        at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:422)
        at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:790)
        at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:684)
        at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:623)
        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)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
FAILED: ParseException line 1:20 cannot recognize input near 'values' '(' '1' in select clause
hive>

任何的想法?我的学习必须选择哪个版本。请指教。

最佳答案

在CDH的较旧版本(例如CDH-5.1)中,不支持插入记录,但在CDH的新版本中,则支持该功能。
因此,与其尝试插入值,不如尝试使用Load data语句

如果您的文件在本地,则

hive> LOAD DATA LOCAL INPATH '<local-path-tofile>' INTO TABLE t;

如果您的文件在HDFS中,则
hive> LOAD DATA INPATH 'hdfs_file_or_directory_path'  INTO TABLE t;

有关更多详细信息,请参阅:-
https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-DMLOperations

关于hadoop - HIVE-SQL插入记录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48953903/

10-15 21:56