[
https://issues.apache.org/jira/browse/CALCITE-4817?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17426099#comment-17426099
]
Ziwei Liu edited comment on CALCITE-4817 at 10/8/21, 10:26 AM:
---------------------------------------------------------------
this change may have some problem, consider this case
final String mv = ""
+ "select "name", "deptno", "empid", min("commission")\n"
+ "from "emps" group by "name", "deptno", "empid"";
final String query = ""
+ "select "name", max("deptno"), count(distinct "empid"), min("commission")\n"
+ "from "emps" group by "name"";
mv already has a column of min(commission), but it's getDistinctOptionality is
Ignore, then it will not use a RollUp aggregation,
if ((aggregateCall.isDistinct() || aggregation.getDistinctOptionality() ==
Optionality.IGNORED)
&& aggregateCall.getArgList().size() == 1)
this condition need be like
if ((aggregateCall.isDistinct() || aggregation.getDistinctOptionality() ==
Optionality.IGNORED && target.aggCalls.indexOf(aggregateCall) < 0)
&& aggregateCall.getArgList().size() == 1)
was (Author: ziwei liu):
this change may have some problem, consider this case
final String mv = ""
+ "select "name", "deptno", "empid", min("commission")\n"
+ "from "emps" group by "name", "deptno", "empid"";
final String query = ""
+ "select "name", max("deptno"), count(distinct "empid"), min("commission")\n"
+ "from "emps" group by "name"";
mv already has a column of min(commission), but it's getDistinctOptionality is
Ignore, then it will not use a RollUp aggregation,
if ((aggregateCall.isDistinct()
|| aggregation.getDistinctOptionality() == Optionality.IGNORED)
&& aggregateCall.getArgList().size() == 1)
this condition need be like
if ((aggregateCall.isDistinct()
|| aggregation.getDistinctOptionality() == Optionality.IGNORED &&
target.aggCalls.indexOf(aggregateCall) < 0)
&& aggregateCall.getArgList().size() == 1)
> Expand SubstitutionVisitor of Aggregate with max/min, which column is the
> group by list of target
> -------------------------------------------------------------------------------------------------
>
> Key: CALCITE-4817
> URL: https://issues.apache.org/jira/browse/CALCITE-4817
> Project: Calcite
> Issue Type: Bug
> Components: core
> Reporter: Xurenhe
> Assignee: Xurenhe
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.28.0
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> Now, SubstitutionVisitor support `Query with distinct aggregate on the column
> is matched to the group list existing in target`, as CALCITE-4374 describes.
> But. It's fail, when query aggregate with max/min based on the column, which
> is in the group by list of target.
> Materialized view recognition should also success.
> {code:java}
> //代码占位符
> @Test void testQueryNoDistinctOptionalityAggCallColInTargetGroupBy1() {
> final String mv = ""
> + "select \"name\", \"deptno\" "
> + "from \"emps\" group by \"name\", \"deptno\"";
> final String query = ""
> + "select \"name\", min(\"deptno\")\n"
> + "from \"emps\" group by \"name\"";
> sql(mv, query).ok();
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)