gpt4 book ai didi

hadoop - 子查询中的子查询在配置单元中不起作用

转载 作者:可可西里 更新时间:2023-11-01 16:28:58 24 4
gpt4 key购买 nike

我有一个复杂的查询,我在这里给出了它的简化版本。想知道为什么它不起作用。

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 无法识别 '(' '(' 'select' in from source 附近的输入

最佳答案

1

与某些数据库不同,Hive 不接受将查询括起来的括号。
例如。 select 1 是 hive 中的有效查询,但不是 (select 1)

附言
即使是接受括号括起查询的数据库,在由 UNION 组合时也不接受这些查询的别名。
例如。 (select 1) union (select 2) 在某些数据库中是有效查询,但不是 (select 1) t1 union (select 2) t2

2

与某些数据库不同,Hive 需要子查询的别名。
例如。 select * from (select 1) t 是 hive 中的有效查询,但不是 select * from (select 1)


编写 OP 查询的正确方法是 -
select * from (select 1 union select 2) t;


+-----+
| _c0 |
+-----+
| 1 |
| 2 |
+-----+

关于hadoop - 子查询中的子查询在配置单元中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44946609/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com