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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]