Aaaaaaron commented on a change in pull request #2225:
URL: https://github.com/apache/calcite/pull/2225#discussion_r509968795
##########
File path:
core/src/main/java/org/apache/calcite/rel/rules/AggregateCaseToFilterRule.java
##########
@@ -227,8 +227,11 @@ protected AggregateCaseToFilterRule(RelBuilderFactory
relBuilderFactory,
RelCollations.EMPTY, aggregateCall.getType(),
aggregateCall.getName());
} else if (kind == SqlKind.SUM // Case B
- && isIntLiteral(arg1) && RexLiteral.intValue(arg1) == 1
- && isIntLiteral(arg2) && RexLiteral.intValue(arg2) == 0) {
+ && isIntLiteral(arg1)
+ && RexLiteral.intValue(arg1) == 1
+ && isIntLiteral(arg2)
+ && !RexLiteral.isNullLiteral(arg2)
Review comment:
The origin NPE is `isIntLiteral(arg2)` return true but arg2's value is
null, you can run this in CsvTest.
```
@Test void testSumCaseWhenWithoutElse() throws SQLException {
sql("model", "select sum( CASE WHEN empno=10 THEN 1 END ) from EMPS").ok();
}
```
`isIntLiteral` doesn't consider the value:
```
return rexNode instanceof RexLiteral &&
SqlTypeName.INT_TYPES.contains(rexNode.getType().getSqlTypeName());
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]