xuzifu666 commented on code in PR #4371:
URL: https://github.com/apache/calcite/pull/4371#discussion_r2087123117
##########
core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java:
##########
@@ -354,6 +354,32 @@ private static boolean skipItem(RexNode expr) {
.check();
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-6887">[CALCITE-6887]
+ * ReduceExpressionsRule applied to 'IN subquery' should make the values
distinct
+ * if the subquery is a constant Values</a>. */
+ @Test void testReduceInValues() {
+ final String sql = "SELECT deptno, sal "
+ + "FROM EMP "
+ + "WHERE deptno IN (1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)";
Review Comment:
@mihaibudiu RelBuilder##values would call tupleList method which can only
support with Literal
```
public RelBuilder values(@Nullable String[] fieldNames, @Nullable
Object... values) {
requireNonNull(fieldNames, "fieldNames");
if (fieldNames.length == 0
|| values.length % fieldNames.length != 0
|| values.length < fieldNames.length) {
throw new IllegalArgumentException(
"Value count must be a positive multiple of field count");
}
final int rowCount = values.length / fieldNames.length;
for (Ord<@Nullable String> fieldName : Ord.zip(fieldNames)) {
if (allNull(values, fieldName.i, fieldNames.length)) {
throw new IllegalArgumentException("All values of field '" +
fieldName.e
+ "' (field index " + fieldName.i + ")"
+ " are null; cannot deduce type");
}
}
final ImmutableList<ImmutableList<RexLiteral>> tupleList =
**tupleList(fieldNames.length, values);**
assert tupleList.size() == rowCount;
final List<String> fieldNameList =
Util.transformIndexed(Arrays.asList(fieldNames), (name, i) ->
name != null ? name : SqlUtil.deriveAliasFromOrdinal(i));
return values(tupleList, fieldNameList);
}
```
RelBuilder##tupleList
```
private ImmutableList<ImmutableList<RexLiteral>> tupleList(int columnCount,
@Nullable Object[] values) {
final ImmutableList.Builder<ImmutableList<RexLiteral>> listBuilder =
ImmutableList.builder();
final List<RexLiteral> valueList = new ArrayList<>();
for (int i = 0; i < values.length; i++) {
Object value = values[i];
valueList.add(literal(value));
if ((i + 1) % columnCount == 0) {
listBuilder.add(ImmutableList.copyOf(valueList));
valueList.clear();
}
}
return listBuilder.build();
}
```
So IMO here can only handle with Literal.
--
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]