运行 sql 查询 Hadoop Java 时出现错误“不匹配的输入 'as' 期望在 from 子句中的 FROM 附近 ')'”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18204232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get error "mismatched input 'as' expecting FROM near ')' in from clause" when run sql query Hadoop Java
提问by Maxim Shoustin
I created two tables from java code tableHiveCell
and tableHiveWiFi
.
我从 java 代码tableHiveCell
和tableHiveWiFi
.
When I try to run followed sql command:
当我尝试运行以下 sql 命令时:
select count(UEs.cnc) as 'Active UEs'
^
from
(select distinct cnc from tableHiveCell wifi
union
select distinct cnc from tableHiveCell cell)
as UEs;
I get an error:
我收到一个错误:
java.sql.SQLException:
Query returned non-zero code: 11,
cause: FAILED: Parse Error: line 1:22 mismatched input 'as' expecting FROM near ')' in from clause
at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:189).
Did I miss something?
我错过了什么?
[EDIT 1]
[编辑 1]
I tried:
我试过:
select count(UEs.cnc) as 'Active UEs'
^
from
(select distinct cnc from tableHiveCell wifi)
union
(select distinct cnc from tableHiveCell cell)
as UEs;
Same error
同样的错误
[EDIT 2]
[编辑 2]
I tried:
我试过:
select count(UEs.cnc) as Active_UEs
from (select distinct cnc from tableHiveCell wifi
union ALL
select distinct cnc from tableHiveCell cell) as UEs;
^
Get the same error but last as
:
得到同样的错误,但最后as
:
line 1:142 mismatched input 'as' expecting Identifier near ')' in subquery source
采纳答案by Najzero
As requested in Answer form:
Hadoop seems to have problems with aliases via AS
keyword on subqueries and you can easily assign the alias without the AS
Keyword.
正如回答形式中的要求:Hadoop 似乎在通过AS
子查询上的关键字使用别名时遇到问题,您可以轻松地分配别名而无需使用AS
关键字。
Example can be found here: https://www.inkling.com/read/hadoop-definitive-guide-tom-white-3rd/chapter-12/querying-data
示例可以在这里找到:https: //www.inkling.com/read/hadoop-definitive-guide-tom-white-3rd/chapter-12/querying-data
And quoted for future visitors ( see mt
alias for subquery ):
并为未来的访问者引用(请参阅mt
子查询的别名):
SELECT station, year, AVG(max_temperature)
FROM (
SELECT station, year, MAX(temperature) AS max_temperature
FROM records2
WHERE temperature != 9999
AND (quality = 0 OR quality = 1 OR quality = 4 OR quality = 5 OR quality = 9)
GROUP BY station, year
) mt
GROUP BY station, year;