[ 
https://issues.apache.org/jira/browse/CALCITE-3244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16907182#comment-16907182
 ] 

Volodymyr Vysotskyi commented on CALCITE-3244:
----------------------------------------------

[~julianhyde], your assumption about DAG helped to discover one more issue in 
{{RelDecorrelator}}. The following test (added {{EXISTS}} clause)
{code:java}
  @Test public void testDecorrelateExists() throws Exception {
    final String sql = "select \n"
        + "   exists (select count(t2.id) \n"
        + "    from (values(1), (2)) t2(id) where t2.id = t1.id)\n"
        + "    from (values(3), (4)) t1(id)";
    checkSubQuery(sql).withLateDecorrelation(true).check();
  }
{code}
fails with the error:
{noformat}
java.lang.AssertionError: Cannot add expression of different type to set:
set type is RecordType(INTEGER NOT NULL ID, BOOLEAN i) NOT NULL
expression type is RecordType(INTEGER NOT NULL ID, BOOLEAN NOT NULL i) NOT NULL
set is 
rel#44:LogicalCorrelate(left=HepRelVertex#36,right=HepRelVertex#43,correlation=$cor0,joinType=left,requiredColumns={0})
expression is LogicalProject(ID=[$0], i=[true])
  LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{0}])
    LogicalValues(tuples=[[{ 3 }, { 4 }]])
    LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
      LogicalFilter(condition=[=($0, $cor0.ID)])
        LogicalValues(tuples=[[{ 1 }, { 2 }]])


        at 
org.apache.calcite.plan.RelOptUtil.verifyTypeEquivalence(RelOptUtil.java:384)
        at 
org.apache.calcite.plan.hep.HepRuleCall.transformTo(HepRuleCall.java:57)
        at 
org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:236)
        at 
org.apache.calcite.sql2rel.RelDecorrelator$AdjustProjectForCountAggregateRule.onMatch2(RelDecorrelator.java:2538)
        at 
org.apache.calcite.sql2rel.RelDecorrelator$AdjustProjectForCountAggregateRule.onMatch(RelDecorrelator.java:2451)
        at 
org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:319)
        at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:560)
        at 
org.apache.calcite.plan.hep.HepPlanner.applyRules(HepPlanner.java:419)
        at 
org.apache.calcite.plan.hep.HepPlanner.executeInstruction(HepPlanner.java:256)
        at 
org.apache.calcite.plan.hep.HepInstruction$RuleInstance.execute(HepInstruction.java:127)
        at 
org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:215)
        at 
org.apache.calcite.plan.hep.HepPlanner.findBestExp(HepPlanner.java:202)
        at 
org.apache.calcite.sql2rel.RelDecorrelator.decorrelate(RelDecorrelator.java:249)
        at 
org.apache.calcite.sql2rel.RelDecorrelator.decorrelateQuery(RelDecorrelator.java:214)
        at 
org.apache.calcite.test.RelOptTestBase.checkPlanning(RelOptTestBase.java:213)
        at 
org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:338)
        at 
org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:321)
        at 
org.apache.calcite.test.RelOptRulesTest.testDecorrelateExists(RelOptRulesTest.java:5565)
{noformat}

Regarding the original query, the plan is not changed.

> RelDecorrelator unable to decorrelate expression with filter and aggregate on 
> top
> ---------------------------------------------------------------------------------
>
>                 Key: CALCITE-3244
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3244
>             Project: Calcite
>          Issue Type: Improvement
>    Affects Versions: 1.20.0
>            Reporter: benj
>            Assignee: Danny Chan
>            Priority: Major
>
> Some very useful type of requests currently failed with:
> {code:java}
> SYSTEM ERROR: UnsupportedOperationException: Adding Implicit RowID column is 
> not supported for ValuesPrel operator 
> {code}
> Examples from DRILL-7050:
> {code:sql}
> select t1.id,
>      (select count(t2.id) 
>      from (
>          select 1 as id 
>          union all 
>          select 2 as id
>      ) t2 where t2.id = t1.id)
>  from (
>      select 1 as id 
>      union all 
>      select 2 as id
>  ) t1
> {code}
> {code:sql}
> SELECT t,
> (SELECT count(*) FROM
>  (SELECT split(r,' ') AS r FROM
>   (SELECT sub.t AS r)) AS x
>  ,LATERAL(SELECT $unnest AS u FROM unnest(x.r))
>  /* WHERE ... */) t2
> FROM
> (SELECT 'unnest is useful' AS t) sub
> {code}
>  
> _Please note that in 1.18 the error for these requests was:_
> {code:java}
> Error: PLAN ERROR: Cannot convert RexNode to equivalent Drill expression. 
> RexNode Class: org.apache.calcite.rex.RexCorrelVariable, RexNode Digest: $cor0
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to