libenchao commented on code in PR #2853:
URL: https://github.com/apache/calcite/pull/2853#discussion_r997163233


##########
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:
   I'm not sure your new commit addressed Julian's comment, but per my 
understanding, I prefer the below way (and this is how I understand Julian's 
comment), what do you think?
   
   ```java
       RelDataType expected = typeFactory.createSqlType(SqlTypeName.DECIMAL, 6, 
1);
       assertEquals(sarg.getType(), expected);
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to