You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "yujun777 (via GitHub)" <gi...@apache.org> on 2025/05/13 06:22:13 UTC

Re: [PR] [feat](nereids) Add constant propagation [doris]

yujun777 commented on code in PR #49982:
URL: https://github.com/apache/doris/pull/49982#discussion_r2086006645


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalUnion.java:
##########
@@ -206,7 +213,53 @@ public void computeUnique(DataTrait.Builder builder) {
 
     @Override
     public void computeUniform(DataTrait.Builder builder) {
-        // don't propagate uniform slots
+        CascadesContext tempCascadeContext = CascadesContext.initContext(
+                ConnectContext.get().getStatementContext(), this, PhysicalProperties.ANY);
+        ExpressionRewriteContext context = new ExpressionRewriteContext(tempCascadeContext);
+        for (int i = 0; i < getOutputs().size(); i++) {
+            Optional<Literal> value = Optional.empty();
+            if (!constantExprsList.isEmpty()) {
+                value = ExpressionUtils.checkConstantExpr(constantExprsList.get(0).get(i), context);
+                if (!value.isPresent()) {
+                    continue;
+                }
+                final int fi = i;
+                Literal literal = value.get();
+                if (constantExprsList.stream()
+                        .map(exprs -> ExpressionUtils.checkConstantExpr(exprs.get(fi), context))
+                        .anyMatch(val -> !val.isPresent() || !val.get().equals(literal))) {
+                    continue;
+                }
+            }
+            for (int childIdx = 0; childIdx < children.size(); childIdx++) {
+                // TODO: use originOutputs = child(childIdx).getOutput() ?
+                List<? extends Slot> originOutputs = regularChildrenOutputs.get(childIdx);
+                Slot slot = originOutputs.get(i);
+                Optional<Expression> childValue = child(childIdx).getLogicalProperties()
+                        .getTrait().getUniformValue(slot);
+                if (childValue == null || !childValue.isPresent() || !childValue.get().isConstant()) {
+                    value = Optional.empty();
+                    break;
+                }
+                Expression childExpr = childValue.get();
+                if (!childExpr.isLiteral()) {
+                    childExpr = FoldConstantRule.evaluate(childExpr, context);
+                    if (!childExpr.isLiteral()) {
+                        continue;

Review Comment:
   fix



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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org