运行 sql 查询 Hadoop Java 时获取错误"mismatched input 'as' expecting FROM near ')' in from clause"



我用java代码tableHiveCelltableHiveWiFi创建了两个表。

当我尝试运行以下sql命令时:

select count(UEs.cnc) as 'Active UEs' 
                      ^
from 
(select distinct cnc from tableHiveCell wifi  
  union 
 select distinct cnc from tableHiveCell cell)
 as UEs;

我得到一个错误:

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).

我错过什么了吗?

[编辑1]

我试过了:

select count(UEs.cnc) as 'Active UEs' 
                      ^
from 
(select distinct cnc from tableHiveCell wifi)  
  union 
 (select distinct cnc from tableHiveCell cell)
 as UEs;

相同错误

[EDIT 2]

我试过了:

select count(UEs.cnc) as Active_UEs
 from (select distinct cnc from tableHiveCell wifi
  union ALL 
 select distinct cnc from tableHiveCell cell) as UEs;
                                              ^ 

得到相同的错误,但最后一个as:

 line 1:142 mismatched input 'as' expecting Identifier near ')' in subquery source

根据应答表中的要求:Hadoop在子查询中似乎存在通过AS关键字分配别名的问题,并且您可以在不使用AS关键字的情况下轻松分配别名。

示例如下:https://www.inkling.com/read/hadoop-definitive-guide-tom-white-3rd/chapter-12/querying-data

并为未来访问者报价(子查询参见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;