This is an automated email from the ASF dual-hosted git repository.

jakevin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 13b1f92c63 [enhancement](Nereids) add output set and output exprid set 
cache (#14151)
13b1f92c63 is described below

commit 13b1f92c6335643e4f472274a56c86fe58b09369
Author: morrySnow <[email protected]>
AuthorDate: Mon Nov 14 11:24:57 2022 +0800

    [enhancement](Nereids) add output set and output exprid set cache (#14151)
---
 .../nereids/properties/LogicalProperties.java      | 35 ++++++++++++----------
 .../doris/nereids/trees/plans/AbstractPlan.java    |  5 ++++
 .../trees/plans/logical/AbstractLogicalPlan.java   |  7 -----
 .../rules/analysis/BindSlotReferenceTest.java      |  4 ++-
 4 files changed, 28 insertions(+), 23 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/LogicalProperties.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/LogicalProperties.java
index cf8921e843..bdfd22cbe1 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/LogicalProperties.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/LogicalProperties.java
@@ -24,6 +24,7 @@ import org.apache.doris.nereids.trees.expressions.Slot;
 
 import com.google.common.base.Supplier;
 import com.google.common.base.Suppliers;
+import com.google.common.collect.Sets;
 
 import java.util.HashSet;
 import java.util.List;
@@ -36,10 +37,10 @@ import java.util.stream.Collectors;
  */
 public class LogicalProperties {
     protected final Supplier<List<Slot>> outputSupplier;
-    protected final Supplier<HashSet<ExprId>> outputSetSupplier;
+    protected final Supplier<List<Id>> outputExprIdsSupplier;
+    protected final Supplier<Set<Slot>> outputSetSupplier;
+    protected final Supplier<Set<ExprId>> outputExprIdSetSupplier;
     private Integer hashCode = null;
-    private Set<ExprId> outputExprIdSet;
-    private List<Id> outputExprIds;
 
     /**
      * constructor of LogicalProperties.
@@ -51,8 +52,15 @@ public class LogicalProperties {
         this.outputSupplier = Suppliers.memoize(
                 Objects.requireNonNull(outputSupplier, "outputSupplier can not 
be null")
         );
+        this.outputExprIdsSupplier = Suppliers.memoize(
+                () -> 
this.outputSupplier.get().stream().map(NamedExpression::getExprId).map(Id.class::cast)
+                        .collect(Collectors.toList())
+        );
         this.outputSetSupplier = Suppliers.memoize(
-                () -> 
outputSupplier.get().stream().map(NamedExpression::getExprId)
+                () -> Sets.newHashSet(this.outputSupplier.get())
+        );
+        this.outputExprIdSetSupplier = Suppliers.memoize(
+                () -> 
this.outputSupplier.get().stream().map(NamedExpression::getExprId)
                         .collect(Collectors.toCollection(HashSet::new))
         );
     }
@@ -61,19 +69,16 @@ public class LogicalProperties {
         return outputSupplier.get();
     }
 
+    public Set<Slot> getOutputSet() {
+        return outputSetSupplier.get();
+    }
+
     public Set<ExprId> getOutputExprIdSet() {
-        if (outputExprIdSet == null) {
-            outputExprIdSet = this.outputSupplier.get().stream()
-                    
.map(NamedExpression::getExprId).collect(Collectors.toSet());
-        }
-        return outputExprIdSet;
+        return outputExprIdSetSupplier.get();
     }
 
     public List<Id> getOutputExprIds() {
-        if (outputExprIds == null) {
-            outputExprIds = 
getOutputExprIdSet().stream().map(Id.class::cast).collect(Collectors.toList());
-        }
-        return outputExprIds;
+        return outputExprIdsSupplier.get();
     }
 
     public LogicalProperties withOutput(List<Slot> output) {
@@ -89,13 +94,13 @@ public class LogicalProperties {
             return false;
         }
         LogicalProperties that = (LogicalProperties) o;
-        return Objects.equals(outputSetSupplier.get(), 
that.outputSetSupplier.get());
+        return Objects.equals(outputExprIdSetSupplier.get(), 
that.outputExprIdSetSupplier.get());
     }
 
     @Override
     public int hashCode() {
         if (hashCode == null) {
-            hashCode = Objects.hash(outputSetSupplier.get());
+            hashCode = Objects.hash(outputExprIdSetSupplier.get());
         }
         return hashCode;
     }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/AbstractPlan.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/AbstractPlan.java
index cb5302e23c..b266a554de 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/AbstractPlan.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/AbstractPlan.java
@@ -124,6 +124,11 @@ public abstract class AbstractPlan extends 
AbstractTreeNode<Plan> implements Pla
         return getLogicalProperties().getOutput();
     }
 
+    @Override
+    public Set<Slot> getOutputSet() {
+        return getLogicalProperties().getOutputSet();
+    }
+
     @Override
     public Set<ExprId> getOutputExprIdSet() {
         return getLogicalProperties().getOutputExprIdSet();
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/AbstractLogicalPlan.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/AbstractLogicalPlan.java
index d59363c341..bd75d9624c 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/AbstractLogicalPlan.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/AbstractLogicalPlan.java
@@ -20,12 +20,10 @@ package org.apache.doris.nereids.trees.plans.logical;
 import org.apache.doris.nereids.memo.GroupExpression;
 import org.apache.doris.nereids.properties.LogicalProperties;
 import org.apache.doris.nereids.properties.UnboundLogicalProperties;
-import org.apache.doris.nereids.trees.expressions.Slot;
 import org.apache.doris.nereids.trees.plans.AbstractPlan;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.PlanType;
 
-import java.util.List;
 import java.util.Optional;
 
 /**
@@ -46,11 +44,6 @@ public abstract class AbstractLogicalPlan extends 
AbstractPlan implements Logica
         super(type, groupExpression, logicalProperties, null, children);
     }
 
-    @Override
-    public List<Slot> getOutput() {
-        return getLogicalProperties().getOutput();
-    }
-
     @Override
     public LogicalProperties computeLogicalProperties() {
         boolean hasUnboundChild = 
children.stream().map(Plan::getLogicalProperties)
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindSlotReferenceTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindSlotReferenceTest.java
index c8dbeb3aea..cfd1433af7 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindSlotReferenceTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindSlotReferenceTest.java
@@ -61,6 +61,8 @@ class BindSlotReferenceTest {
 
         AnalysisException exception = 
Assertions.assertThrows(AnalysisException.class,
                 () -> 
PlanChecker.from(MemoTestUtils.createConnectContext()).analyze(project));
-        Assertions.assertEquals("id is ambiguous: id#8, id#12.", 
exception.getMessage());
+        Assertions.assertTrue(exception.getMessage().contains("id is 
ambiguous: "));
+        Assertions.assertTrue(exception.getMessage().contains("id#4"));
+        Assertions.assertTrue(exception.getMessage().contains("id#0"));
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to