abhishek-das-gupta commented on code in PR #2853: URL: https://github.com/apache/calcite/pull/2853#discussion_r996345727
########## core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java: ########## @@ -1258,6 +1259,26 @@ private static String toSql(RelNode root, SqlDialect dialect, relFn(relFn).optimize(rules, null).ok(expected); } + /** Test case for + * <a href="https://issues.apache.org/jira/browse/CALCITE-4632">[CALCITE-4632] + * Find the least restrictive datatype for SARG</a>. */ + @Test void testLeastRestrictiveTypeForSarg() { + final Function<RelBuilder, RelNode> relFn = b -> b + .scan("EMP") + .filter( + b.or(b.isNull(b.field("COMM")), + b.in( + b.field("COMM"), + b.literal(new BigDecimal("1.0")), b.literal(new BigDecimal("20000.0"))) + ) + ) Review Comment: Sorry about this. Addressed this. ########## core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java: ########## @@ -624,6 +624,29 @@ private void checkDate(RexLiteral literal) { assertThat(inCall.getKind(), is(SqlKind.SEARCH)); } + /** Test case for + * <a href="https://issues.apache.org/jira/browse/CALCITE-4632">[CALCITE-4632] + * Find the least restrictive datatype for SARG</a>. */ + @Test void testLeastRestrictiveTypeForSarg() { + final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT); + final RexBuilder rexBuilder = new RexBuilder(typeFactory); + final RelDataType decimalType = typeFactory.createSqlType(SqlTypeName.DECIMAL); + RexNode left = rexBuilder.makeInputRef(decimalType, 0); + final RexNode literal1 = rexBuilder.makeExactLiteral(new BigDecimal("1.0")); + final RexNode literal2 = rexBuilder.makeExactLiteral(new BigDecimal("20000.0")); + + RexNode inCall = rexBuilder.makeIn(left, ImmutableList.of(literal1, literal2)); + assertThat(inCall.getKind(), is(SqlKind.SEARCH)); + + final RexNode sarg = ((RexCall) inCall).operands.get(1); + final RelDataType leastRestrictiveType = + typeFactory.leastRestrictive(ImmutableList.of(literal1.getType(), literal2.getType())); Review Comment: ACK -- 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. To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org