Khurram Faraaz created DRILL-4808:
-------------------------------------

             Summary: CTE query with window function results in AssertionError
                 Key: DRILL-4808
                 URL: https://issues.apache.org/jira/browse/DRILL-4808
             Project: Apache Drill
          Issue Type: Bug
          Components: Query Planning & Optimization
    Affects Versions: 1.8.0
            Reporter: Khurram Faraaz


Below query that uses CTE and window functions results in AssertionError
Same query over same data works on Postgres.
MapR Drill 1.8.0 commit ID : 34ca63ba

{noformat}
0: jdbc:drill:schema=dfs.tmp> WITH v1 ( a, b, c, d ) AS
. . . . . . . . . . . . . . > (
. . . . . . . . . . . . . . >     SELECT col0, col8, MAX(MIN(col8)) over 
(partition by col7 order by col8) as max_col8, col7 from `allTypsUniq.parquet` 
GROUP BY col0,col7,col8
. . . . . . . . . . . . . . > )
. . . . . . . . . . . . . . > select * from ( select a, b, c, d from v1 where c 
> 'IN' GROUP BY a,b,c,d order by a,b,c,d);
Error: SYSTEM ERROR: AssertionError: Internal error: Type 'RecordType(ANY col0, 
ANY col8, ANY max_col8, ANY col7)' has no field 'a'


[Error Id: 5c058176-741a-42cd-8433-0cd81115776b on centos-01.qa.lab:31010] 
(state=,code=0)
{noformat}

Stack trace from drillbit.log for above failing query

{noformat}
2016-07-26 16:57:04,627 [2868699e-ae56-66f4-9439-8db2132ef265:foreman] INFO  
o.a.drill.exec.work.foreman.Foreman - Query text for query id 
2868699e-ae56-66f4-9439-8db2132ef265: WITH v1 ( a, b, c, d ) AS
(
    SELECT col0, col8, MAX(MIN(col8)) over (partition by col7 order by col8) as 
max_col8, col7 from `allTypsUniq.parquet` GROUP BY col0,col7,col8
)
select * from ( select a, b, c, d from v1 where c > 'IN' GROUP BY a,b,c,d order 
by a,b,c,d)
2016-07-26 16:57:04,666 [2868699e-ae56-66f4-9439-8db2132ef265:foreman] ERROR 
o.a.drill.exec.work.foreman.Foreman - SYSTEM ERROR: AssertionError: Internal 
error: Type 'RecordType(ANY col0, ANY col8, ANY max_col8, ANY col7)' has no 
field 'a'


[Error Id: 5c058176-741a-42cd-8433-0cd81115776b on centos-01.qa.lab:31010]
org.apache.drill.common.exceptions.UserException: SYSTEM ERROR: AssertionError: 
Internal error: Type 'RecordType(ANY col0, ANY col8, ANY max_col8, ANY col7)' 
has no field 'a'


[Error Id: 5c058176-741a-42cd-8433-0cd81115776b on centos-01.qa.lab:31010]
        at 
org.apache.drill.common.exceptions.UserException$Builder.build(UserException.java:543)
 ~[drill-common-1.8.0-SNAPSHOT.jar:1.8.0-SNAPSHOT]
        at 
org.apache.drill.exec.work.foreman.Foreman$ForemanResult.close(Foreman.java:791)
 [drill-java-exec-1.8.0-SNAPSHOT.jar:1.8.0-SNAPSHOT]
        at 
org.apache.drill.exec.work.foreman.Foreman.moveToState(Foreman.java:901) 
[drill-java-exec-1.8.0-SNAPSHOT.jar:1.8.0-SNAPSHOT]
        at org.apache.drill.exec.work.foreman.Foreman.run(Foreman.java:271) 
[drill-java-exec-1.8.0-SNAPSHOT.jar:1.8.0-SNAPSHOT]
        at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
[na:1.7.0_101]
        at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
[na:1.7.0_101]
        at java.lang.Thread.run(Thread.java:745) [na:1.7.0_101]
Caused by: org.apache.drill.exec.work.foreman.ForemanException: Unexpected 
exception during fragment initialization: Internal error: Type 'RecordType(ANY 
col0, ANY col8, ANY max_col8, ANY col7)' has no field 'a'
        ... 4 common frames omitted
Caused by: java.lang.AssertionError: Internal error: Type 'RecordType(ANY col0, 
ANY col8, ANY max_col8, ANY col7)' has no field 'a'
        at org.apache.calcite.util.Util.newInternal(Util.java:777) 
~[calcite-core-1.4.0-drill-r14.jar:1.4.0-drill-r14]
        at 
org.apache.calcite.rex.RexBuilder.makeFieldAccess(RexBuilder.java:167) 
~[calcite-core-1.4.0-drill-r14.jar:1.4.0-drill-r14]
        at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertIdentifier(SqlToRelConverter.java:3225)
 ~[calcite-core-1.4.0-drill-r14.jar:1.4.0-drill-r14]
        at 
org.apache.calcite.sql2rel.SqlToRelConverter.access$1500(SqlToRelConverter.java:185)
 ~[calcite-core-1.4.0-drill-r14.jar:1.4.0-drill-r14]
        at 
org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:4181)
 ~[calcite-core-1.4.0-drill-r14.jar:1.4.0-drill-r14]
        at 
org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:3603)
 ~[calcite-core-1.4.0-drill-r14.jar:1.4.0-drill-r14]
        at org.apache.calcite.sql.SqlIdentifier.accept(SqlIdentifier.java:274) 
~[calcite-core-1.4.0-drill-r14.jar:1.4.0-drill-r14]
        at 
org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.convertExpression(SqlToRelConverter.java:4062)
 ~[calcite-core-1.4.0-drill-r14.jar:1.4.0-drill-r14]
        at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectList(SqlToRelConverter.java:3433)
 ~[calcite-core-1.4.0-drill-r14.jar:1.4.0-drill-r14]
        at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectImpl(SqlToRelConverter.java:627)
 ~[calcite-core-1.4.0-drill-r14.jar:1.4.0-drill-r14]
        at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertSelect(SqlToRelConverter.java:583)
 ~[calcite-core-1.4.0-drill-r14.jar:1.4.0-drill-r14]
        at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:2795)
 ~[calcite-core-1.4.0-drill-r14.jar:1.4.0-drill-r14]
        at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:537)
 ~[calcite-core-1.4.0-drill-r14.jar:1.4.0-drill-r14]
        at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertWith(SqlToRelConverter.java:3504)
 ~[calcite-core-1.4.0-drill-r14.jar:1.4.0-drill-r14]
        at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:2809)
 ~[calcite-core-1.4.0-drill-r14.jar:1.4.0-drill-r14]
        at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:537)
 ~[calcite-core-1.4.0-drill-r14.jar:1.4.0-drill-r14]
        at 
org.apache.drill.exec.planner.sql.SqlConverter.toRel(SqlConverter.java:251) 
~[drill-java-exec-1.8.0-SNAPSHOT.jar:1.8.0-SNAPSHOT]
        at 
org.apache.drill.exec.planner.sql.handlers.DefaultSqlHandler.convertToRel(DefaultSqlHandler.java:620)
 ~[drill-java-exec-1.8.0-SNAPSHOT.jar:1.8.0-SNAPSHOT]
        at 
org.apache.drill.exec.planner.sql.handlers.DefaultSqlHandler.validateAndConvert(DefaultSqlHandler.java:195)
 ~[drill-java-exec-1.8.0-SNAPSHOT.jar:1.8.0-SNAPSHOT]
        at 
org.apache.drill.exec.planner.sql.handlers.DefaultSqlHandler.getPlan(DefaultSqlHandler.java:164)
 ~[drill-java-exec-1.8.0-SNAPSHOT.jar:1.8.0-SNAPSHOT]
        at 
org.apache.drill.exec.planner.sql.DrillSqlWorker.getPlan(DrillSqlWorker.java:94)
 ~[drill-java-exec-1.8.0-SNAPSHOT.jar:1.8.0-SNAPSHOT]
        at org.apache.drill.exec.work.foreman.Foreman.runSQL(Foreman.java:978) 
[drill-java-exec-1.8.0-SNAPSHOT.jar:1.8.0-SNAPSHOT]
        at org.apache.drill.exec.work.foreman.Foreman.run(Foreman.java:257) 
[drill-java-exec-1.8.0-SNAPSHOT.jar:1.8.0-SNAPSHOT]
        ... 3 common frames omitted
{noformat}

Results from Postgres

{noformat}
postgres=# WITH v1 ( a, b, c, d ) AS
postgres-# (
postgres(#     SELECT col0, col8, MAX(MIN(col8)) over (partition by col7 order 
by col8) as max_col8, col7 from fewrwspqq_101 GROUP BY col0,col7,col8
postgres(# )
postgres-# select * from ( select a, b, c, d from v1 where c > 'IN' GROUP BY 
a,b,c,d order by a,b,c,d) sub_query;
     a      | b  | c  | d 
------------+----+----+---
     -65535 | NJ | NJ | f
         -1 | VT | VT | t
          0 | KS | KS | f
          2 | WI | WI | t
          3 | NY | NY | f
          5 | TX | TX | f
          8 | SD | SD | t
          9 | RI | RI | f
         19 | WY | WY | t
         23 | SC | SC | t
         29 | NC | NC | f
        109 | NE | NE | t
      65535 | MN | MN | t
   10000000 | OR | OR | t
 1073741823 | MA | MA | f
(15 rows)
{noformat}



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

Reply via email to