TJ Banghart created CALCITE-4761: ------------------------------------ Summary: simplifyingOrs with an "UNKNOWN" return type reference throws `IllegalArgumentException` when . Key: CALCITE-4761 URL: https://issues.apache.org/jira/browse/CALCITE-4761 Project: Calcite Issue Type: Bug Components: core Affects Versions: 1.27.0 Reporter: TJ Banghart
[This checkArgument|https://github.com/apache/calcite/blob/017c974e07dd48919e6890dea69320e6ffc406ef/core/src/main/java/org/apache/calcite/rex/RexLiteral.java#L232] may throw an `IllegalArgumentException` while simplifying ORs if the operator's return type is "UNKNOWN". For example this test fails with the exception: {code:java} @Test void testSimplifyLikeOrNullWithUnknownType() { final SqlOperator unknownOp = new SqlSpecialOperator( "unknown", SqlKind.OTHER_FUNCTION, 0, false, null, null, null) { @Override public RelDataType inferReturnType(SqlOperatorBinding opBinding) { return typeFactory.createUnknownType(); } }; final RexNode unknownRef = rexBuilder.makeCall(unknownOp); final RexNode test = or( isNull(unknownRef), isNotNull(unknownRef)); checkSimplify(test, "true"); }{code} Here's the trace: {code:java} java.lang.IllegalArgumentException at com.google.common.base.Preconditions.checkArgument(Preconditions.java:128) at org.apache.calcite.rex.RexLiteral.<init>(RexLiteral.java:232) at org.apache.calcite.rex.RexBuilder.makeLiteral(RexBuilder.java:993) at org.apache.calcite.rex.RexBuilder.makeSearchArgumentLiteral(RexBuilder.java:1088) at org.apache.calcite.rex.RexSimplify$SargCollector.fix(RexSimplify.java:2937) at org.apache.calcite.rex.RexSimplify.lambda$simplifyOrs$7(RexSimplify.java:1964) at java.util.ArrayList.forEach(ArrayList.java:1257) at org.apache.calcite.rex.RexSimplify.simplifyOrs(RexSimplify.java:1963) at org.apache.calcite.rex.RexSimplify.simplifyOr(RexSimplify.java:1937) at org.apache.calcite.rex.RexSimplify.simplify(RexSimplify.java:281) at org.apache.calcite.rex.RexSimplify.simplifyUnknownAs(RexSimplify.java:248) at org.apache.calcite.rex.RexProgramTestBase.checkSimplifyAs(RexProgramTestBase.java:152) at org.apache.calcite.rex.RexProgramTestBase.checkSimplify3_(RexProgramTestBase.java:136) at org.apache.calcite.rex.RexProgramTestBase.checkSimplify(RexProgramTestBase.java:95) at org.apache.calcite.rex.RexProgramTest.testSimplifyLikeOrNullWithUnknownType(RexProgramTest.java:3157){code} Certainly an edge case but thought I'd record it since it wasn't obvious why this exception was being thrown. Perhaps this is intended behavior. -- This message was sent by Atlassian Jira (v8.3.4#803005)