You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2022/10/07 05:58:42 UTC

[GitHub] [calcite] libenchao commented on a diff in pull request #2853: [CALCITE-4632] SARG datatype should be less restictive than any of the input types

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


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1355,10 +1356,14 @@ public RexNode makeIn(RexNode arg, List<? extends RexNode> ranges) {
     if (areAssignable(arg, ranges)) {
       final Sarg sarg = toSarg(Comparable.class, ranges, RexUnknownAs.UNKNOWN);
       if (sarg != null) {
-        final RexNode range0 = ranges.get(0);
+        final List<RelDataType> types = ranges.stream()
+            .map(RexNode::getType)
+            .collect(Collectors.toList());
+        RelDataType searchType = typeFactory.leastRestrictive(types);
+        searchType = searchType == null ? ranges.get(0).getType() : searchType;

Review Comment:
   If`searchType == null` is `true`, do we really need to proceed with `ranges.get(0).getType()`?



##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -1252,6 +1253,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() {

Review Comment:
   As discussed in the JIRA, the root cause is not from `RelToSqlConverter`, so I'm not sure this is the right place to add tests. How about we add more tests in `RexBuilderTest` and assert the `RexNode`'s type returned from `RexBuilder#makeIn`?



-- 
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-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org