Victoria Markman created DRILL-3801:
---------------------------------------

             Summary: Extend support for scalar subqueries
                 Key: DRILL-3801
                 URL: https://issues.apache.org/jira/browse/DRILL-3801
             Project: Apache Drill
          Issue Type: New Feature
            Reporter: Victoria Markman


In current drill implementation we only consider subquery scalar when scalar 
aggregate is present and as I discovered recently, we also consider subquery to 
return scalar result if you have 1 column, and 1 row (limit 1)

However, if subquery does return one row during runtime, we currently don't  
detect that and we throw an error early during planning time:

{code}
0: jdbc:drill:schema=dfs> select * from t2 where a2 = 0;
+-----+------+-------------+
| a2  |  b2  |     c2      |
+-----+------+-------------+
| 0   | zzz  | 2014-12-31  |
+-----+------+-------------+
1 row selected (0.283 seconds)

0: jdbc:drill:schema=dfs> select * from t1 where a1 >= (select a2 from t2 where 
a2 = 0);
Error: UNSUPPORTED_OPERATION ERROR: Non-scalar sub-query used in an expression
See Apache Drill JIRA: DRILL-1937
[Error Id: 9e26af25-b0c4-42f9-a839-b76f759c94ab on atsqa4-133.qa.lab:31010] 
(state=,code=0)
{code}

Because of this limitation we can't run TPCDS query 44  (inner subquery has 
just one group):

{code}
...
...
SELECT ss_item_sk         item_sk, 
                              Avg(ss_net_profit) rank_col 
                       FROM   store_sales ss1 
                       WHERE  ss_store_sk = 4 
                       GROUP  BY ss_item_sk 
                       HAVING Avg(ss_net_profit) > 0.9 * 
                              (SELECT Avg(ss_net_profit) 
                                      rank_col 
                               FROM   store_sales 
                               WHERE  ss_store_sk = 4 
                                      AND ss_cdemo_sk IS 
                                          NULL 
                               GROUP  BY ss_store_sk))V2)
{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to