vlsi commented on a change in pull request #1848: [CALCITE-3845] CASE WHEN expression with nullability CAST is considered as reduced wrongly in ReduceExpressionsRule URL: https://github.com/apache/calcite/pull/1848#discussion_r389754090
########## File path: core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java ########## @@ -3480,6 +3481,51 @@ private void checkReduceNullableToNotNull(ReduceExpressionsRule rule) { sql(sql).with(program).check(); } + @Test public void testReduceCaseWhenWithCast() { + final RelBuilder relBuilder = RelBuilder.create(RelBuilderTest.config().build()); + final RexBuilder rexBuilder = relBuilder.getRexBuilder(); + final RelDataType type = rexBuilder.getTypeFactory().createSqlType(SqlTypeName.BIGINT); + + RelNode left = relBuilder + .values(new String[]{"x", "y"}, 1, 2).build(); + RexNode ref = rexBuilder.makeInputRef(left, 0); + RexNode literal1 = rexBuilder.makeLiteral(1, type, false); + RexNode literal2 = rexBuilder.makeLiteral(2, type, false); + RexNode literal3 = rexBuilder.makeLiteral(3, type, false); + + // CASE WHEN x % 2 = 1 THEN x < 2 + // WHEN x % 3 = 2 THEN x < 1 + // ELSE x < 3 + final RexNode caseRexNode = rexBuilder.makeCall(SqlStdOperatorTable.CASE, + rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, + rexBuilder.makeCall(SqlStdOperatorTable.MOD, ref, literal2), literal1), + rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN, ref, literal2), + rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, + rexBuilder.makeCall(SqlStdOperatorTable.MOD, ref, literal3), literal2), + rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN, ref, literal1), + rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN, ref, literal3)); Review comment: What I mean is signal to noise ratio leaves much to be desired here. The dance of `rexBuilder.makeCall(SqlStdOperatorTable` repeats again and again :( ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services