You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2024/03/07 08:20:01 UTC
(doris) 28/38: [fix](mtmv) support null value in partition for updating (#31843)
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 73ebeb24a3c1f176d5ff9c4bc794d4d9522b39bb
Author: 谢健 <ji...@gmail.com>
AuthorDate: Thu Mar 7 11:18:37 2024 +0800
[fix](mtmv) support null value in partition for updating (#31843)
---
.../plans/commands/UpdateMvByPartitionCommand.java | 19 ++++++++++++++++++-
.../commands/UpdateMvByPartitionCommandTest.java | 21 +++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletion(-)
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 0c976506a87..f6bd39ac838 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
@@ -31,10 +31,12 @@ import org.apache.doris.nereids.parser.NereidsParser;
import org.apache.doris.nereids.trees.expressions.Expression;
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.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.expressions.literal.NullLiteral;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.algebra.Sink;
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
@@ -54,6 +56,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
/**
* Update mv by partition
@@ -123,7 +126,21 @@ public class UpdateMvByPartitionCommand extends InsertOverwriteTableCommand {
List<Expression> inValues = ((ListPartitionItem) item).getItems().stream()
.map(UpdateMvByPartitionCommand::convertPartitionKeyToLiteral)
.collect(ImmutableList.toImmutableList());
- return new InPredicate(col, inValues);
+ List<Expression> predicates = new ArrayList<>();
+ if (inValues.stream().anyMatch(NullLiteral.class::isInstance)) {
+ inValues = inValues.stream()
+ .filter(e -> !(e instanceof NullLiteral))
+ .collect(Collectors.toList());
+ Expression isNullPredicate = new IsNull(col);
+ predicates.add(isNullPredicate);
+ }
+ if (!inValues.isEmpty()) {
+ predicates.add(new InPredicate(col, inValues));
+ }
+ if (predicates.isEmpty()) {
+ return BooleanLiteral.of(true);
+ }
+ return ExpressionUtils.or(predicates);
} else {
Range<PartitionKey> range = item.getItems();
List<Expression> exprs = new ArrayList<>();
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
index af00d8ae464..b7374565da1 100644
--- 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
@@ -19,6 +19,7 @@ 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.ListPartitionItem;
import org.apache.doris.catalog.PartitionItem;
import org.apache.doris.catalog.PartitionKey;
import org.apache.doris.catalog.PrimitiveType;
@@ -26,6 +27,7 @@ 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.IsNull;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.SlotReference;
import org.apache.doris.nereids.types.IntegerType;
@@ -53,4 +55,23 @@ class UpdateMvByPartitionCommandTest {
Expression expr = (Expression) m.invoke(null, rangePartitionItem, new SlotReference("s", IntegerType.INSTANCE));
Assertions.assertTrue(expr instanceof GreaterThanEqual);
}
+
+ @Test
+ void testNull() 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 v = PartitionKey.createListPartitionKeyWithTypes(ImmutableList.of(new PartitionValue("NULL", true)), ImmutableList.of(column.getType()), false);
+ ListPartitionItem listPartitionItem = new ListPartitionItem(ImmutableList.of(v));
+ Expression expr = (Expression) m.invoke(null, listPartitionItem, new SlotReference("s", IntegerType.INSTANCE));
+ Assertions.assertTrue(expr instanceof IsNull);
+
+ PartitionKey v1 = PartitionKey.createListPartitionKeyWithTypes(ImmutableList.of(new PartitionValue("NULL", true)), ImmutableList.of(column.getType()), false);
+ PartitionKey v2 = PartitionKey.createListPartitionKeyWithTypes(ImmutableList.of(new PartitionValue("1", false)), ImmutableList.of(column.getType()), false);
+ listPartitionItem = new ListPartitionItem(ImmutableList.of(v1, v2));
+ expr = (Expression) m.invoke(null, listPartitionItem, new SlotReference("s", IntegerType.INSTANCE));
+ Assertions.assertEquals("(s IS NULL OR s IN (1))", expr.toSql());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org