You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Jiatao Tao (Jira)" <ji...@apache.org> on 2020/10/20 02:37:00 UTC

[jira] [Comment Edited] (CALCITE-4345) SUM CASE WHEN xxx THEN 1 without "ELSE" throws NPE in AggregateCaseToFilterRule

    [ https://issues.apache.org/jira/browse/CALCITE-4345?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17217219#comment-17217219 ] 

Jiatao Tao edited comment on CALCITE-4345 at 10/20/20, 2:36 AM:
----------------------------------------------------------------

Hi [~julianhyde] 

"sum(case when b then 1 else null end)" is exactly the same as "sum(case when b then 1 end)", so this fix is also applied.

I'll add test for `sum(case when b then 1 else null end)`, other UT is already in RelOptRulesTest#testAggregateCaseToFilter.


was (Author: aron.tao):
[~julianhyde] I'll add test for these.

> SUM CASE WHEN xxx THEN 1 without "ELSE" throws NPE in AggregateCaseToFilterRule
> -------------------------------------------------------------------------------
>
>                 Key: CALCITE-4345
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4345
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Jiatao Tao
>            Assignee: Jiatao Tao
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: image-2020-10-19-16-59-44-900.png
>
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> Add a test in CsvTest:
>  
> {code:java}
> @Test void testSumCaseWhenWithoutElse() throws SQLException {
>   sql("model", "select sum( CASE WHEN empno=10 THEN 1 END ) from EMPS").ok();
> }
> {code}
> Will throw NPE
>  Caused by: java.lang.RuntimeException: Error while applying rule AggregateCaseToFilterRule, args [rel#18:LogicalAggregate.NONE.[](input=RelSubset#17,group={},EXPR$0=SUM($0)), rel#16:LogicalProject.NONE.[](input=RelSubset#15,exprs=[CASE(=($0, 10), 1, null:INTEGER)])] Caused by: java.lang.RuntimeException: Error while applying rule AggregateCaseToFilterRule, args [rel#18:LogicalAggregate.NONE.[](input=RelSubset#17,group={},EXPR$0=SUM($0)), rel#16:LogicalProject.NONE.[](input=RelSubset#15,exprs=[CASE(=($0, 10), 1, null:INTEGER)])] at org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:257) at org.apache.calcite.plan.volcano.IterativeRuleDriver.drive(IterativeRuleDriver.java:58) at org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:511) at org.apache.calcite.tools.Programs.lambda$standard$3(Programs.java:271) at org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:331) at org.apache.calcite.prepare.Prepare.optimize(Prepare.java:166) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:299) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:208) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:642) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:508) at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:478) at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:231) at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:558) at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675) at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156) ... 63 more Caused by: java.lang.NullPointerException at org.apache.calcite.rex.RexLiteral.intValue(RexLiteral.java:1152) at org.apache.calcite.rel.rules.AggregateCaseToFilterRule.transform(AggregateCaseToFilterRule.java:231) at org.apache.calcite.rel.rules.AggregateCaseToFilterRule.onMatch(AggregateCaseToFilterRule.java:115) at org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:230) ... 77 more



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