Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'<EOF>' in subquery source in Hive query

Tags:

sql

hive

I am running a query on Hive similar to:

SELECT *
FROM (SELECT a
      FROM b
      WHERE
      sex = 'M'
      AND   degree = 'Bs'
      AND   age = 15
      AND   name LIKE 'L%'
      );

the error is:

cannot recognize input near '<EOF>' '<EOF>' '<EOF>' in subquery source
like image 485
Cyrus Avatar asked Apr 05 '17 16:04

Cyrus


People also ask

How does Hive handle subquery?

Hive supports subqueries only in the FROM clause (through Hive 0.12). The subquery has to be given a name because every table in a FROM clause must have a name. Columns in the subquery select list must have unique names.

Does hive allow subqueries?

Hive supports subqueries in FROM clauses and in WHERE clauses of SQL statements. A subquery is a SQL expression that is evaluated and returns a result set. Then that result set is used to evaluate the parent query. The parent query is the outer query that contains the child subquery.

Does Hive support nested subqueries?

Hive doesn't support nested subqueries.


2 Answers

Adding a table alias for your subquery is necessary for Hive. Below I use 't1' as the alias:

SELECT *
FROM (SELECT a
  FROM b
  WHERE
  sex = 'M'
  AND   degree = 'Bs'
  AND   age = 15
  AND   name LIKE 'L%'
  ) t1 ;
like image 144
a m Sreekanth Avatar answered Oct 08 '22 07:10

a m Sreekanth


All the down-votes are unjustified. Hive often does not produce correct error and throws lazy "EOF" at you. In this case you just need to specify table alias for your sub-query. SELECT * FROM (.....) tbl_alias

like image 45
Abay Bektursun Avatar answered Oct 08 '22 09:10

Abay Bektursun