This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
commit ca59579bf691b37f09568395086b36146c6254b3 Author: 谢健 <jianx...@gmail.com> AuthorDate: Tue Mar 5 14:54:40 2024 +0800 fix](Nereids): support max_value in range partition (#31721) --- .../plans/commands/UpdateMvByPartitionCommand.java | 22 +++++---- .../commands/UpdateMvByPartitionCommandTest.java | 56 ++++++++++++++++++++++ 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UpdateMvByPartitionCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UpdateMvByPartitionCommand.java index e9a67d83281..0c976506a87 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UpdateMvByPartitionCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UpdateMvByPartitionCommand.java @@ -33,6 +33,7 @@ import org.apache.doris.nereids.trees.expressions.GreaterThanEqual; import org.apache.doris.nereids.trees.expressions.InPredicate; import org.apache.doris.nereids.trees.expressions.LessThan; import org.apache.doris.nereids.trees.expressions.Slot; +import org.apache.doris.nereids.trees.expressions.literal.BooleanLiteral; import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.algebra.Sink; @@ -112,25 +113,30 @@ public class UpdateMvByPartitionCommand extends InsertOverwriteTableCommand { .collect(ImmutableSet.toImmutableSet()); } + private static Expression convertPartitionKeyToLiteral(PartitionKey key) { + return Literal.fromLegacyLiteral(key.getKeys().get(0), + Type.fromPrimitiveType(key.getTypes().get(0))); + } + private static Expression convertPartitionItemToPredicate(PartitionItem item, Slot col) { if (item instanceof ListPartitionItem) { List<Expression> inValues = ((ListPartitionItem) item).getItems().stream() - .map(key -> Literal.fromLegacyLiteral(key.getKeys().get(0), - Type.fromPrimitiveType(key.getTypes().get(0)))) + .map(UpdateMvByPartitionCommand::convertPartitionKeyToLiteral) .collect(ImmutableList.toImmutableList()); return new InPredicate(col, inValues); } else { Range<PartitionKey> range = item.getItems(); List<Expression> exprs = new ArrayList<>(); - if (range.hasLowerBound()) { + if (range.hasLowerBound() && !range.lowerEndpoint().isMinValue()) { PartitionKey key = range.lowerEndpoint(); - exprs.add(new GreaterThanEqual(col, Literal.fromLegacyLiteral(key.getKeys().get(0), - Type.fromPrimitiveType(key.getTypes().get(0))))); + exprs.add(new GreaterThanEqual(col, convertPartitionKeyToLiteral(key))); } - if (range.hasUpperBound()) { + if (range.hasUpperBound() && !range.upperEndpoint().isMaxValue()) { PartitionKey key = range.upperEndpoint(); - exprs.add(new LessThan(col, Literal.fromLegacyLiteral(key.getKeys().get(0), - Type.fromPrimitiveType(key.getTypes().get(0))))); + exprs.add(new LessThan(col, convertPartitionKeyToLiteral(key))); + } + if (exprs.isEmpty()) { + return BooleanLiteral.of(true); } return ExpressionUtils.and(exprs); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/UpdateMvByPartitionCommandTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/UpdateMvByPartitionCommandTest.java new file mode 100644 index 00000000000..af00d8ae464 --- /dev/null +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/UpdateMvByPartitionCommandTest.java @@ -0,0 +1,56 @@ +// 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.trees.plans.commands; + +import org.apache.doris.analysis.PartitionValue; +import org.apache.doris.catalog.Column; +import org.apache.doris.catalog.PartitionItem; +import org.apache.doris.catalog.PartitionKey; +import org.apache.doris.catalog.PrimitiveType; +import org.apache.doris.catalog.RangePartitionItem; +import org.apache.doris.common.AnalysisException; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.GreaterThanEqual; +import org.apache.doris.nereids.trees.expressions.Slot; +import org.apache.doris.nereids.trees.expressions.SlotReference; +import org.apache.doris.nereids.types.IntegerType; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Range; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +class UpdateMvByPartitionCommandTest { + @Test + void testMaxMin() throws AnalysisException, NoSuchMethodException, InvocationTargetException, + IllegalAccessException { + Method m = UpdateMvByPartitionCommand.class.getDeclaredMethod("convertPartitionItemToPredicate", PartitionItem.class, + Slot.class); + m.setAccessible(true); + Column column = new Column("a", PrimitiveType.INT); + PartitionKey upper = PartitionKey.createPartitionKey(ImmutableList.of(PartitionValue.MAX_VALUE), ImmutableList.of(column)); + PartitionKey lower = PartitionKey.createPartitionKey(ImmutableList.of(new PartitionValue(1L)), ImmutableList.of(column)); + Range<PartitionKey> range = Range.closedOpen(lower, upper); + RangePartitionItem rangePartitionItem = new RangePartitionItem(range); + Expression expr = (Expression) m.invoke(null, rangePartitionItem, new SlotReference("s", IntegerType.INSTANCE)); + Assertions.assertTrue(expr instanceof GreaterThanEqual); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org