You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Feng Zhu (JIRA)" <ji...@apache.org> on 2019/07/02 05:35:00 UTC
[jira] [Commented] (CALCITE-3160) Failed to materialize when the
aggregate function uses group key
[ https://issues.apache.org/jira/browse/CALCITE-3160?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16876680#comment-16876680 ]
Feng Zhu commented on CALCITE-3160:
-----------------------------------
I have also noticed such kind of issues.
(1)When sum(empid), AggregateToAggregateUnifyRule will be matched. However, it uses "!=" to compare Projects in query and target.
{code:java}
if (query.getInput() != target.getInput()) {
return null;
}
{code}
But for the Projects matched in TrivialRule, the result still use that in query without replacing it into target. Consequently, in the next iteration, AggregateToAggregateUnifyRule cannot reuse the MV.
{code:java}
public UnifyResult apply(UnifyRuleCall call) {
if (call.query.equals(call.target)) {
return call.result(call.query);
}
return null;
}
{code}
(2)When sum(salary), ProjectToProjectUnifyRule will replace child Projects and AggregateOnProjectToAggregateUnifyRule can reuse the MV.
Therefore, I think we need to fix the logic in TrivialRule as *_call.result(call.result)_* or unify the condition as "_*!query.getInput.equals(target.getInput)*_". We also need to check other rules.
> Failed to materialize when the aggregate function uses group key
> ----------------------------------------------------------------
>
> Key: CALCITE-3160
> URL: https://issues.apache.org/jira/browse/CALCITE-3160
> Project: Calcite
> Issue Type: Bug
> Reporter: Haisheng Yuan
> Priority: Major
>
> Repro:
> {code:java}
> @Test public void testAggregateGroupSetsRollUp() {
> checkMaterialize(
> "select \"empid\", \"deptno\", count(*) as c, sum(\"empid\") as s from \"emps\" "
> + "group by \"empid\", \"deptno\"",
> "select count(*) + 1 as c, \"deptno\" from \"emps\" group by cube(\"empid\",\"deptno\")",
> HR_FKUK_MODEL,
> CalciteAssert.checkResultContains(
> "EnumerableCalc(expr#0..2=[{inputs}], expr#3=[1], "
> + "expr#4=[+($t2, $t3)], C=[$t4], deptno=[$t1])\n"
> + " EnumerableAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {1}, {}]], agg#0=[$SUM0($2)])\n"
> + " EnumerableTableScan(table=[[hr, m0]])"));
> }
> {code}
> Note that if we change sum(\"empid\") to sum("salary"), it can materialize successfully.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)