diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyRange.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyRange.java index 98d752facb464a..d17a1cda0aa567 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyRange.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyRange.java @@ -494,6 +494,7 @@ public Expression toExpression() { for (int i = 1; i < sourceValues.size(); i++) { result = mergeExprOp.apply(result, sourceValues.get(i).toExpression()); } + expr.transferState(result); return result; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/AbstractTreeNode.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/AbstractTreeNode.java index 92bbcdb9b38fd0..27b1fb25133d65 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/AbstractTreeNode.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/AbstractTreeNode.java @@ -76,4 +76,8 @@ public void setMutableState(String key, Object state) { public int arity() { return children.size(); } + + public void transferState(AbstractTreeNode target) { + target.mutableState = mutableState.clone(); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/MutableState.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/MutableState.java index 528c19576bb40e..e617bef4b344c2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/MutableState.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/MutableState.java @@ -34,6 +34,7 @@ public interface MutableState { Optional get(String key); MutableState set(String key, Object value); + MutableState clone(); /** EmptyMutableState */ class EmptyMutableState implements MutableState { @@ -50,6 +51,11 @@ public Optional get(String key) { public MutableState set(String key, Object value) { return new SingleMutableState(key, value); } + + @Override + public MutableState clone () { + return INSTANCE; + } } /** SingleMutableState */ @@ -80,6 +86,11 @@ public MutableState set(String key, Object value) { multiMutableState.set(key, value); return multiMutableState; } + + @Override + public MutableState clone() { + return new SingleMutableState(key, value); + } } /** MultiMutableState */ @@ -96,5 +107,14 @@ public MutableState set(String key, Object value) { states.put(key, value); return this; } + + @Override + public MutableState clone() { + MutableState target = new MultiMutableState(); + for (String key : states.keySet()) { + target = target.set(key, states.get(key)); + } + return target; + } } }