我无法创建hive表。 以下是代码
CREATE TABLE NYSE(exchange STRING, stock_symbol STRING, stock_date DATE,
stock_price_open FLOAT, stock_price_high FLOAT, stock_price_low FLOAT,
stock_price_close FLOAT, stock_volume INT, stock_price_avg_close FLOAT)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
这会返回以下错误消息:
NoViableAltException(332@[2189:1: columnNameTypeOrPKOrFK : ( ( foreignKeyWithName ) | ( primaryKeyWithName ) | ( primaryKeyWithoutName ) | ( foreignKeyWithoutName ) | ( columnNameType ) );])
at org.antlr.runtime.DFA.noViableAlt(DFA.java:158)
at org.antlr.runtime.DFA.predict(DFA.java:116)
at org.apache.hadoop.hive.ql.parse.HiveParser.columnNameTypeOrPKOrFK(HiveParser.java:42212)
at org.apache.hadoop.hive.ql.parse.HiveParser.columnNameTypeOrPKOrFKList(HiveParser.java:37938)
at org.apache.hadoop.hive.ql.parse.HiveParser.createTableStatement(HiveParser.java:5259)
at org.apache.hadoop.hive.ql.parse.HiveParser.ddlStatement(HiveParser.java:2763)
at org.apache.hadoop.hive.ql.parse.HiveParser.execStatement(HiveParser.java:1756)
at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:1178)
at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:204)
at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:404)
at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:329)
at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1158)
at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1253)
at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1084)
at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1072)
at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:232)
at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:183)
at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:399)
at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:776)
at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:714)
at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:641)
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:18 cannot recognize input near 'exchange' 'STRING' ,' in column name or primary key or foreign key
我正在使用Hive 2.1.0和Hadoop 2.7.3
请帮帮我。
答案 0 :(得分:3)
您不能在列名定义中使用“exchange”Reserved keywords。
尝试给出像exchange_1或使用`转到你的第一个列名。
尝试以下步骤:
USE your_DB_Name;
DROP TABLE IF EXISTS NYSE PURGE;
CREATE TABLE NYSE (`exchange` STRING, stock_symbol STRING, stock_date DATE, stock_price_open FLOAT, stock_price_high FLOAT, stock_price_low FLOAT, stock_price_close FLOAT, stock_volume INT, stock_price_avg_close FLOAT) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' ;
答案 1 :(得分:1)
Exchange是HIVE中的保留关键字
您可以使用反引号(``)符号
来转义它这应该有效:
CREATE TABLE NYSE(
`exchange` STRING
,stock_symbol STRING
,stock_date DATE
,stock_price_open FLOAT
,stock_price_high FLOAT
,stock_price_low FLOAT
,stock_price_close FLOAT
,stock_volume INT
,stock_price_avg_close FLOAT)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
答案 2 :(得分:0)
exchange是hive中的关键字,因此您无法使用。而不是使用交换或其他任何东西。 试试这个..
create table nyse(exchangee String,stock_symbol String,stock_date String,stock_price_open double,stock_price_high double,stock_price_low double,stock_price_close double,stock_volume double,stock_price_adj_close double)行格式分隔的字段 以“,”结束;