[jira] [Commented] (CALCITE-2344) Wrong constant reduction over windows function
[ https://issues.apache.org/jira/browse/CALCITE-2344?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16496804#comment-16496804 ] Laurent Goujon commented on CALCITE-2344: - So I guess there are two issues? 1/ the return type of some aggregate functions (min/max/... but not count) should be nullable but isn't 2/ if the return type is not nullable, a wrong inference in RexUtil causes parser to barf My patch seems to address 2/ but I didn't realize about 1/ for sure. > Wrong constant reduction over windows function > -- > > Key: CALCITE-2344 > URL: https://issues.apache.org/jira/browse/CALCITE-2344 > Project: Calcite > Issue Type: Bug >Reporter: Laurent Goujon >Assignee: Laurent Goujon >Priority: Major > > {{RexUtil}} might incorrectly infer a IS NULL predicate would cause a > reference over a window function to return null, but a window function type > is never nullable. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (CALCITE-2344) Wrong constant reduction over windows function
[ https://issues.apache.org/jira/browse/CALCITE-2344?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16496714#comment-16496714 ] Laurent Goujon commented on CALCITE-2344: - Attaching pull request with 2 test cases added to RelOptRulesTests and a possible fix > Wrong constant reduction over windows function > -- > > Key: CALCITE-2344 > URL: https://issues.apache.org/jira/browse/CALCITE-2344 > Project: Calcite > Issue Type: Bug >Reporter: Laurent Goujon >Assignee: Laurent Goujon >Priority: Major > > {{RexUtil}} might incorrectly infer a IS NULL predicate would cause a > reference over a window function to return null, but a window function type > is never nullable. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (CALCITE-2344) Wrong constant reduction over windows function
[ https://issues.apache.org/jira/browse/CALCITE-2344?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16496711#comment-16496711 ] Julian Hyde commented on CALCITE-2344: -- If an aggregate function is applied over 0 rows - i.e. an empty window - then the result is null. This applies to min, max, sum, but not count. > Wrong constant reduction over windows function > -- > > Key: CALCITE-2344 > URL: https://issues.apache.org/jira/browse/CALCITE-2344 > Project: Calcite > Issue Type: Bug >Reporter: Laurent Goujon >Assignee: Laurent Goujon >Priority: Major > > {{RexUtil}} might incorrectly infer a IS NULL predicate would cause a > reference over a window function to return null, but a window function type > is never nullable. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (CALCITE-2344) Wrong constant reduction over windows function
[ https://issues.apache.org/jira/browse/CALCITE-2344?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16496708#comment-16496708 ] Laurent Goujon commented on CALCITE-2344: - I tried the following query: {code:sql} select empno, deptno, w_count from ( select empno, deptno, count(empno) over (ROWS BETWEEN 10 PRECEDING AND 1 PRECEDING) w_count from emp ) sub_query where w_count is null {code} In {{RelOptRulesTest}} I configured a preplanner with the {{ProjectToWindowRule.PROJECT}} rule and then a planner with the {{ReduceExpressionsRule.PROJECT_INSTANCE}}. I got the following exception: {noformat} java.lang.AssertionError: Cannot add expression of different type to set: set type is RecordType(INTEGER NOT NULL EMPNO, INTEGER NOT NULL DEPTNO, BIGINT NOT NULL W_COUNT) NOT NULL expression type is RecordType(INTEGER NOT NULL EMPNO, INTEGER NOT NULL DEPTNO, BIGINT W_COUNT) NOT NULL set is rel#26:LogicalProject(input=HepRelVertex#25,EMPNO=$0,DEPTNO=$1,W_COUNT=$2) expression is LogicalProject#28 at org.apache.calcite.plan.RelOptUtil.verifyTypeEquivalence(RelOptUtil.java:410) at org.apache.calcite.plan.hep.HepRuleCall.transformTo(HepRuleCall.java:57) at org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:234) at org.apache.calcite.rel.rules.ReduceExpressionsRule$ProjectReduceExpressionsRule.onMatch(ReduceExpressionsRule.java:290) at org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:317) at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:556) at org.apache.calcite.plan.hep.HepPlanner.applyRules(HepPlanner.java:415) at org.apache.calcite.plan.hep.HepPlanner.executeInstruction(HepPlanner.java:252) at org.apache.calcite.plan.hep.HepInstruction$RuleInstance.execute(HepInstruction.java:127) at org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:211) at org.apache.calcite.plan.hep.HepPlanner.findBestExp(HepPlanner.java:198) at org.apache.calcite.test.RelOptTestBase.checkPlanning(RelOptTestBase.java:170) at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:315) at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:299) at org.apache.calcite.test.RelOptRulesTest.testIsNullPushDown2(RelOptRulesTest.java:3027) {noformat} > Wrong constant reduction over windows function > -- > > Key: CALCITE-2344 > URL: https://issues.apache.org/jira/browse/CALCITE-2344 > Project: Calcite > Issue Type: Bug >Reporter: Laurent Goujon >Assignee: Laurent Goujon >Priority: Major > > {{RexUtil}} might incorrectly infer a IS NULL predicate would cause a > reference over a window function to return null, but a window function type > is never nullable. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (CALCITE-2344) Wrong constant reduction over windows function
[ https://issues.apache.org/jira/browse/CALCITE-2344?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16496106#comment-16496106 ] Laurent Goujon commented on CALCITE-2344: - but empty is not null? > Wrong constant reduction over windows function > -- > > Key: CALCITE-2344 > URL: https://issues.apache.org/jira/browse/CALCITE-2344 > Project: Calcite > Issue Type: Bug >Reporter: Laurent Goujon >Assignee: Laurent Goujon >Priority: Major > > {{RexUtil}} might incorrectly infer a IS NULL predicate would cause a > reference over a window function to return null, but a window function type > is never nullable. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (CALCITE-2344) Wrong constant reduction over windows function
[ https://issues.apache.org/jira/browse/CALCITE-2344?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16496081#comment-16496081 ] Julian Hyde commented on CALCITE-2344: -- Not true. Windows can be empty, e.g. {{BETWEEN INTERVAL '2' MINUTE PRECEDING AND INTERVAL '1' PRECEDING}}. > Wrong constant reduction over windows function > -- > > Key: CALCITE-2344 > URL: https://issues.apache.org/jira/browse/CALCITE-2344 > Project: Calcite > Issue Type: Bug >Reporter: Laurent Goujon >Assignee: Laurent Goujon >Priority: Major > > {{RexUtil}} might incorrectly infer a IS NULL predicate would cause a > reference over a window function to return null, but a window function type > is never nullable. -- This message was sent by Atlassian JIRA (v7.6.3#76005)