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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/MultiColumnBound.java:
##########
@@ -0,0 +1,54 @@
+// 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.rules.expression.rules;
+
+import java.util.List;
+
+/** MultiColumnBound */
+public class MultiColumnBound implements Comparable<MultiColumnBound> {
+    private final List<ColumnBound> columnBounds;
+
+    public MultiColumnBound(List<ColumnBound> columnBounds) {
+        this.columnBounds = columnBounds;

Review Comment:
   need immutable?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SortedPartitionRanges.java:
##########
@@ -0,0 +1,46 @@
+// 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.rules.expression.rules;
+
+import org.apache.doris.catalog.PartitionItem;
+
+import com.google.common.collect.RangeSet;
+
+import java.util.List;
+
+/** SortedPartitionRanges */
+public class SortedPartitionRanges<K> {
+    public final List<PartitionItemAndRange<K>> sortedPartitions;
+
+    public SortedPartitionRanges(List<PartitionItemAndRange<K>> 
sortedPartitions) {
+        this.sortedPartitions = sortedPartitions;

Review Comment:
   check null and immutable?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/PartitionPruner.java:
##########
@@ -105,19 +108,25 @@ public Expression 
visitComparisonPredicate(ComparisonPredicate cp, Void context)
     public <K> List<K> prune() {
         Builder<K> scanPartitionIdents = ImmutableList.builder();
         for (OnePartitionEvaluator partition : partitions) {
-            if (!canBePrunedOut(partition)) {
+            if (!canBePrunedOut(partitionPredicate, partition)) {
                 scanPartitionIdents.add((K) partition.getPartitionIdent());
             }
         }
         return scanPartitionIdents.build();
     }
 
+    public static <K> List<K> prune(List<Slot> partitionSlots, Expression 
partitionPredicate,
+            Map<K, PartitionItem> idToPartitions, CascadesContext 
cascadesContext,
+            PartitionTableType partitionTableType) {
+        return prune(partitionSlots, partitionPredicate, idToPartitions, 
cascadesContext, partitionTableType, null);
+    }
+
     /**
      * prune partition with `idToPartitions` as parameter.
      */
     public static <K> List<K> prune(List<Slot> partitionSlots, Expression 
partitionPredicate,
             Map<K, PartitionItem> idToPartitions, CascadesContext 
cascadesContext,
-            PartitionTableType partitionTableType) {
+            PartitionTableType partitionTableType, SortedPartitionRanges<K> 
sortedPartitionRanges) {

Review Comment:
   use Optional<SortedPartitionRanges<K>> ?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/PartitionPredicateToRange.java:
##########
@@ -0,0 +1,249 @@
+// 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.rules.expression.rules;
+
+import org.apache.doris.nereids.trees.expressions.And;
+import org.apache.doris.nereids.trees.expressions.EqualTo;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.GreaterThan;
+import org.apache.doris.nereids.trees.expressions.GreaterThanEqual;
+import org.apache.doris.nereids.trees.expressions.InPredicate;
+import org.apache.doris.nereids.trees.expressions.IsNull;
+import org.apache.doris.nereids.trees.expressions.LessThan;
+import org.apache.doris.nereids.trees.expressions.LessThanEqual;
+import org.apache.doris.nereids.trees.expressions.Not;
+import org.apache.doris.nereids.trees.expressions.NullSafeEqual;
+import org.apache.doris.nereids.trees.expressions.Or;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.SlotReference;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.trees.expressions.literal.MaxLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
+import 
org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionVisitor;
+
+import com.google.common.collect.BoundType;
+import com.google.common.collect.ImmutableRangeSet;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Range;
+import com.google.common.collect.RangeSet;
+import com.google.common.collect.TreeRangeSet;
+import org.apache.hadoop.util.Lists;
+
+import java.util.List;
+import java.util.Set;
+
+/** PartitionPredicateToRange */
+public class PartitionPredicateToRange extends 
DefaultExpressionVisitor<RangeSet<MultiColumnBound>, Void> {
+    private List<Slot> columns;
+    private Set<Integer> slotIds;

Review Comment:
   final and immutable?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/PartitionItemToRange.java:
##########
@@ -0,0 +1,78 @@
+// 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.rules.expression.rules;
+
+import org.apache.doris.analysis.LiteralExpr;
+import org.apache.doris.catalog.ListPartitionItem;
+import org.apache.doris.catalog.PartitionItem;
+import org.apache.doris.catalog.PartitionKey;
+import org.apache.doris.catalog.RangePartitionItem;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Range;
+import com.google.common.collect.TreeRangeSet;
+
+import java.util.List;
+
+/** PartitionItemToRange */
+public class PartitionItemToRange {
+    /** toRangeSets */
+    public static TreeRangeSet<MultiColumnBound> toRangeSets(PartitionItem 
partitionItem) {
+        if (partitionItem instanceof RangePartitionItem) {
+            Range<PartitionKey> range = partitionItem.getItems();
+            TreeRangeSet<MultiColumnBound> oneRangePartitionRanges = 
TreeRangeSet.create();
+            PartitionKey lowerKey = range.lowerEndpoint();
+            ImmutableList.Builder<ColumnBound> lowerBounds
+                    = 
ImmutableList.builderWithExpectedSize(lowerKey.getKeys().size());
+            for (LiteralExpr key : lowerKey.getKeys()) {
+                Literal literal = Literal.fromLegacyLiteral(key, 
key.getType());

Review Comment:
   how about save a nereids literal in memory when create PartitionKey object?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/MultiColumnBound.java:
##########
@@ -0,0 +1,54 @@
+// 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.rules.expression.rules;
+
+import java.util.List;
+
+/** MultiColumnBound */
+public class MultiColumnBound implements Comparable<MultiColumnBound> {
+    private final List<ColumnBound> columnBounds;
+
+    public MultiColumnBound(List<ColumnBound> columnBounds) {
+        this.columnBounds = columnBounds;
+    }
+
+    @Override
+    public int compareTo(MultiColumnBound o) {
+        for (int i = 0; i < columnBounds.size(); i++) {
+            ColumnBound columnBound = columnBounds.get(i);
+            ColumnBound otherColumnBound = o.columnBounds.get(i);

Review Comment:
   do we need to check o.columnBounds.size() for in case?



-- 
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