我有一个复杂的查询,我在这里给出它的简化版本。想知道它为什么不起作用。
select * from ((select 1) t1 union (select 2) t2);
获得以下错误
NoViableAltException(290@[147:5: ( ( Identifier LPAREN )=> partitionedTableFunction | tableSource | subQuerySource | virtualTableSource )])
at org.antlr.runtime.DFA.noViableAlt(DFA.java:158)
at org.antlr.runtime.DFA.predict(DFA.java:144)
at org.apache.hadoop.hive.ql.parse.HiveParser_FromClauseParser.fromSource(HiveParser_FromClauseParser.java:3654)
at org.apache.hadoop.hive.ql.parse.HiveParser_FromClauseParser.joinSource(HiveParser_FromClauseParser.java:1836)
at org.apache.hadoop.hive.ql.parse.HiveParser_FromClauseParser.fromClause(HiveParser_FromClauseParser.java:1488)
at org.apache.hadoop.hive.ql.parse.HiveParser.fromClause(HiveParser.java:44869)
at org.apache.hadoop.hive.ql.parse.HiveParser.singleSelectStatement(HiveParser.java:42035)
at org.apache.hadoop.hive.ql.parse.HiveParser.selectStatement(HiveParser.java:41720)
at org.apache.hadoop.hive.ql.parse.HiveParser.regularBody(HiveParser.java:41657)
at org.apache.hadoop.hive.ql.parse.HiveParser.queryStatementExpressionBody(HiveParser.java:40710)
at org.apache.hadoop.hive.ql.parse.HiveParser.queryStatementExpression(HiveParser.java:40586)
at org.apache.hadoop.hive.ql.parse.HiveParser.execStatement(HiveParser.java:1529)
at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:1065)
at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:201)
at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:418)
at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:312)
at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1201)
at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1296)
at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1127)
at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1115)
at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:220)
at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:172)
at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:383)
at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:775)
at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:693)
at 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)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
失败:ParseException行1:15无法识别'(''(''从源'中选择')附近的输入
答案 0 :(得分:2)
与某些数据库不同,Hive不接受查询的括号
例如。 select 1
在配置单元中是有效查询,但不是(select 1)
。
P.S。
即使是接受查询括号的数据库,在UNION组合时也不接受这些查询的别名
例如。 (select 1) union (select 2)
在某些数据库中是有效查询,但不是(select 1) t1 union (select 2) t2
与某些数据库不同,Hive需要子查询的别名
例如。 select * from (select 1) t
是一个有效的查询,但不是select * from (select 1)
编写OP查询的正确方法是 -
select * from (select 1 union select 2) t;
+-----+
| _c0 |
+-----+
| 1 |
| 2 |
+-----+