Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Problem

Currently HIVE doesn't support subqueries in SELECT statement e.g. following query will not run on HIVE

...

Recently a lot of work has been done to extend support for subqueries(HIVE-15456). But this work primarily targeted to extend subquery support in WHERE and HAVING clause. We plan to continue the work done in HIVE-15456 to support subqueries in SELECT list.

 

Assumptions

We plan to limit the scope with following assumption/limitations

...

  • Scalar subquery can only return at most one row. HIVE will check for this case at runtime and throw an error if not satisfied. e.g. following query is invalid

    Code Block
    languagesql
    SELECT customer.customer_num,
    	(SELECT ship_charge 
    		FROM orders
    		WHERE customer.customer_num = orders.customer_num
    	) AS total_ship_chg
    FROM customer 
  • Scalar subquery can only have one column. HIVE will check for this case during compilation and throw an error. e.g following query is invalid

    Code Block
    languagesql
    SELECT customer.customer_num,
    	(SELECT ship_charge, customer_num
    		FROM orders LIMIT 1
    	) AS total_ship_chg
    FROM customer

Design

Given the assumptions above following kind of subqueries could be used in select 

...