morrySnow commented on code in PR #27051:
URL: https://github.com/apache/doris/pull/27051#discussion_r1408668354


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/joinorder/hypergraph/receiver/PlanReceiver.java:
##########
@@ -378,7 +379,9 @@ private List<Plan> proposeProject(List<Plan> allChild, 
List<Edge> edges, long le
                 .collect(Collectors.toList());
         if (!outputSet.equals(new HashSet<>(projects))) {
             LogicalProperties projectProperties = new LogicalProperties(
-                    () -> projects.stream().map(p -> 
p.toSlot()).collect(Collectors.toList()));
+                    () -> projects.stream()
+                            .map(p -> p.toSlot())
+                            .collect(Collectors.toList()), () -> 
FunctionalDependencies.EMPTY_FUNC_DEPS);

Review Comment:
   NIT: use ImmutableList collector



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/properties/FunctionalDependencies.java:
##########
@@ -0,0 +1,232 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.properties;
+
+import org.apache.doris.nereids.trees.expressions.Slot;
+
+import com.google.common.collect.ImmutableSet;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Record functional dependencies, aka func deps, including
+ * 1. unique slot: it means the column that has ndv = row count, can be null
+ * 2. uniform slotL it means the column that has ndv = 1, can be null
+ */
+public class FunctionalDependencies {
+    public static final FunctionalDependencies EMPTY_FUNC_DEPS
+            = new FunctionalDependencies(new NestedSet().toImmutable(), new 
NestedSet().toImmutable());

Review Comment:
   add a blank between public and private static var



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalCatalogRelation.java:
##########
@@ -113,4 +118,18 @@ public String qualifiedName() {
         }
         return Utils.qualifiedName(qualifier, table.getName());
     }
+
+    @Override
+    public FunctionalDependencies computeFuncDeps(Supplier<List<Slot>> 
outputSupplier) {
+        Builder fdBuilder = new Builder();
+        if (table instanceof OlapTable && ((OlapTable) 
table).getKeysType().isAggregationFamily()) {
+            ImmutableSet<Slot> slotSet = computeOutput().stream()
+                    .filter(SlotReference.class::isInstance)

Review Comment:
   nit: add a map to cast to SlotReference



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalCheckPolicy.java:
##########
@@ -46,7 +47,8 @@
 /**
  * Logical Check Policy
  */
-public class LogicalCheckPolicy<CHILD_TYPE extends Plan> extends 
LogicalUnary<CHILD_TYPE> {
+public class LogicalCheckPolicy<CHILD_TYPE extends Plan> extends 
LogicalUnary<CHILD_TYPE> implements

Review Comment:
   nit: wrap before implements is better



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/joinorder/hypergraph/receiver/PlanReceiver.java:
##########
@@ -378,7 +379,9 @@ private List<Plan> proposeProject(List<Plan> allChild, 
List<Edge> edges, long le
                 .collect(Collectors.toList());
         if (!outputSet.equals(new HashSet<>(projects))) {
             LogicalProperties projectProperties = new LogicalProperties(
-                    () -> projects.stream().map(p -> 
p.toSlot()).collect(Collectors.toList()));
+                    () -> projects.stream()
+                            .map(p -> p.toSlot())

Review Comment:
   nit: use lambda style 



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/properties/FunctionalDependencies.java:
##########
@@ -0,0 +1,232 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.properties;
+
+import org.apache.doris.nereids.trees.expressions.Slot;
+
+import com.google.common.collect.ImmutableSet;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Record functional dependencies, aka func deps, including
+ * 1. unique slot: it means the column that has ndv = row count, can be null
+ * 2. uniform slotL it means the column that has ndv = 1, can be null
+ */
+public class FunctionalDependencies {
+    public static final FunctionalDependencies EMPTY_FUNC_DEPS
+            = new FunctionalDependencies(new NestedSet().toImmutable(), new 
NestedSet().toImmutable());
+    private final NestedSet uniqueSet;
+    private final NestedSet uniformSet;
+
+    private FunctionalDependencies(NestedSet uniqueSet, NestedSet uniformSet) {
+        this.uniqueSet = uniqueSet;
+        this.uniformSet = uniformSet;
+    }
+
+    public boolean isEmpty() {
+        return uniformSet.isEmpty() && uniqueSet.isEmpty();
+    }
+
+    public boolean isUnique(Slot slot) {
+        return uniqueSet.contains(slot);
+    }
+
+    public boolean isUnique(Set<Slot> slotSet) {
+        return !slotSet.isEmpty() && uniqueSet.containsAnySub(slotSet);
+    }
+
+    public boolean isUniform(Slot slot) {
+        return uniformSet.contains(slot);
+    }
+
+    public boolean isUniform(ImmutableSet<Slot> slotSet) {
+        return !slotSet.isEmpty()
+                && (uniformSet.contains(slotSet) || 
slotSet.stream().allMatch(uniformSet::contains));
+    }
+
+    public boolean isUniqueAndNotNull(Slot slot) {
+        return !slot.nullable() && isUnique(slot);
+    }
+
+    public boolean isUniqueAndNotNull(Set<Slot> slotSet) {
+        return slotSet.stream().noneMatch(Slot::nullable) && isUnique(slotSet);
+    }
+
+    public boolean isUniformAndNotNull(Slot slot) {
+        return !slot.nullable() && isUniform(slot);
+    }
+
+    public boolean isUniformAndNotNull(ImmutableSet<Slot> slotSet) {
+        return slotSet.stream().noneMatch(Slot::nullable) && 
isUniform(slotSet);
+    }
+
+    @Override
+    public String toString() {
+        return "uniform:" + uniformSet

Review Comment:
   nit: use uniform style toString as Plan is better



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

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


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

Reply via email to