abhishekagarwal87 commented on code in PR #3735:
URL: https://github.com/apache/calcite/pull/3735#discussion_r1527052740
##########
core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml:
##########
@@ -2856,6 +2856,32 @@ LogicalAggregate(group=[{}], EXPR$0=[MIN($1) FILTER $3],
EXPR$1=[COUNT($0) FILTE
LogicalAggregate(group=[{1, 2}], groups=[[{1, 2}, {}]], EXPR$0=[SUM($0)],
$g=[GROUPING($1, $2)])
LogicalProject(COMM=[$6], SAL=[$5], $f2=[>($5, 1000)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ </TestCase>
+ <TestCase name="testDistinctWithFilterWithoutGroupByUsingJoin">
+ <Resource name="sql">
+ <![CDATA[SELECT SUM(comm), COUNT(DISTINCT sal) FILTER (WHERE sal > 1000)
+FROM emp]]>
+ </Resource>
+ <Resource name="planBefore">
+ <![CDATA[
+LogicalAggregate(group=[{}], EXPR$0=[SUM($0)], EXPR$1=[COUNT(DISTINCT $1)
FILTER $2])
+ LogicalProject(COMM=[$6], SAL=[$5], $f2=[>($5, 1000)])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ <Resource name="planAfter">
+ <![CDATA[
+LogicalJoin(condition=[true], joinType=[inner])
Review Comment:
The filter is not being applied to the sum. There is an additional `project`
for the count aggregator that looks at the result of the filter condition and
projects another column that gets counted. If the filter were being applied to
the sum, I would imagine this `case` project being on the left side of the
join, too.
I haven't looked at these plans before, but please let me know if I am
misinterpreting them. I have also verified this fix in `apache/druid` and I
could see the native druid plan adding the filter only to the count.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]