Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get error "mismatched input 'as' expecting FROM near ')' in from clause" when run sql query Hadoop Java

Tags:

java

sql

hadoop

I created two tables from java code tableHiveCell and tableHiveWiFi.

When I try to run followed sql command:

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]

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]

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:

 line 1:142 mismatched input 'as' expecting Identifier near ')' in subquery source
like image 882
Maxim Shoustin Avatar asked Aug 13 '13 08:08

Maxim Shoustin


1 Answers

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.

Example can be found here: 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 ):

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;
like image 181
Najzero Avatar answered Oct 31 '22 11:10

Najzero