mihaibudiu commented on code in PR #4242:
URL: https://github.com/apache/calcite/pull/4242#discussion_r1992487277
##########
core/src/main/java/org/apache/calcite/rel/core/Values.java:
##########
@@ -66,7 +66,7 @@ public abstract class Values extends AbstractRelNode
implements Hintable {
//~ Instance fields --------------------------------------------------------
- public final ImmutableList<ImmutableList<RexLiteral>> tuples;
+ public ImmutableList<ImmutableList<RexLiteral>> tuples;
Review Comment:
this is very dangerous.
all these classes are immutable for a reason.
##########
core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java:
##########
@@ -738,6 +740,20 @@ protected static boolean reduceExpressionsInternal(RelNode
rel,
// Replace predicates on CASE to CASE on predicates.
boolean changed = new CaseShuttle().mutate(expList);
+ // distinct for IN rexNode
+ for (RexNode rexNode : predicates.pulledUpPredicates) {
+ if (rexNode.isA(SqlKind.IN)) {
+ RexSubQuery rexSubQuery = (RexSubQuery) rexNode;
+ List<ImmutableList<RexLiteral>> collect =
+ ((LogicalValues) rexSubQuery.rel).tuples
+ .stream().distinct().collect(Collectors.toList());
+ // In would transform to RexSubQuery and rel should be LogicalValues
+ if (rexSubQuery.rel instanceof LogicalValues) {
+ ((LogicalValues) rexSubQuery.rel).tuples =
ImmutableList.copyOf(collect);
Review Comment:
you cannot mutate the fields of a subquery; that subquery may be used by
other objects as well.
you have to create a new object.
--
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]