You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Ruben Q L (Jira)" <ji...@apache.org> on 2021/09/13 14:02:00 UTC

[jira] [Created] (CALCITE-4773) RelDecorrelator's RemoveSingleAggregateRule produces result with wrong row type

Ruben Q L created CALCITE-4773:
----------------------------------

             Summary: RelDecorrelator's RemoveSingleAggregateRule produces result with wrong row type
                 Key: CALCITE-4773
                 URL: https://issues.apache.org/jira/browse/CALCITE-4773
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.27.0
            Reporter: Ruben Q L
            Assignee: Ruben Q L
             Fix For: 1.28.0


The problem can be reproduced with the following test (to be added to {{unnest.iq}}):
{noformat}
SELECT unnested_outer.val, COUNT(1) AS count_val
FROM
(
    SELECT *
    FROM (VALUES (1, array [3, 5]), (2, array [6, 4, 6]))
    AS u(x, y)
) AS t, UNNEST(t.y) AS unnested_outer(val)
WHERE
(
    SELECT COUNT(unnested_inner.val) > 0
    FROM UNNEST(t.y) AS unnested_inner(val)
    WHERE unnested_inner.val = 4
)
GROUP BY unnested_outer.val
ORDER BY count_val DESC, unnested_outer.val ASC;
+-----+-----------+
| VAL | COUNT_VAL |
+-----+-----------+
|   6 |         2 |
|   4 |         1 |
+-----+-----------+
(2 rows)

!ok
{noformat}

When the test is executed, it fails with the following error:
{noformat}
> java.lang.AssertionError: Cannot add expression of different type to set:
> set type is RecordType(BOOLEAN NOT NULL $f0) NOT NULL
> expression type is RecordType(BOOLEAN $f0) NOT NULL
> set is rel#24436:LogicalAggregate.NONE.[](input=HepRelVertex#24435,group={},agg#0=SINGLE_VALUE($0))
> expression is LogicalProject($f0=[CAST(>($0, 0)):BOOLEAN])
>   LogicalAggregate(group=[{}], agg#0=[COUNT()])
>     LogicalFilter(condition=[=($0, 4)])
>       LogicalProject(VAL=[$0])
>         Uncollect
>           LogicalProject(Y=[$cor1.Y])
>             LogicalValues(tuples=[[{ 0 }]])
249a254,325
> 	at org.apache.calcite.plan.RelOptUtil.verifyTypeEquivalence(RelOptUtil.java:391)
> 	at org.apache.calcite.plan.hep.HepRuleCall.transformTo(HepRuleCall.java:60)
> 	at org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:269)
> 	at org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:284)
> 	at org.apache.calcite.sql2rel.RelDecorrelator$RemoveSingleAggregateRule.onMatch(RelDecorrelator.java:1923)
> 	at org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:341)
> 	at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:565)
> 	at org.apache.calcite.plan.hep.HepPlanner.applyRules(HepPlanner.java:428)
> 	at org.apache.calcite.plan.hep.HepPlanner.executeInstruction(HepPlanner.java:251)
> 	at org.apache.calcite.plan.hep.HepInstruction$RuleInstance.execute(HepInstruction.java:130)
> 	at org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:208)
> 	at org.apache.calcite.plan.hep.HepPlanner.findBestExp(HepPlanner.java:195)
> 	at org.apache.calcite.sql2rel.RelDecorrelator.removeCorrelationViaRule(RelDecorrelator.java:378)
> 	at org.apache.calcite.sql2rel.RelDecorrelator.decorrelateQuery(RelDecorrelator.java:221)
...
{noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)