This is an automated email from the ASF dual-hosted git repository. morrysnow 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 80d54368e0 [minor](Nereids) replace some nullable field to Optional (#20967) 80d54368e0 is described below commit 80d54368e04f4980cf1c2daa9094304150989bd6 Author: mch_ucchi <41606806+sohardforan...@users.noreply.github.com> AuthorDate: Sun Jun 25 12:02:25 2023 +0800 [minor](Nereids) replace some nullable field to Optional (#20967) --- .../nereids/analyzer/UnboundOlapTableSink.java | 9 +++--- .../glue/translator/PhysicalPlanTranslator.java | 2 +- .../doris/nereids/parser/LogicalPlanBuilder.java | 19 ++++++++----- .../rules/analysis/BindInsertTargetTable.java | 6 ++-- .../trees/plans/commands/DeleteCommand.java | 15 +++++----- .../plans/commands/InsertIntoTableCommand.java | 10 ++----- .../trees/plans/commands/UpdateCommand.java | 13 +++++---- .../trees/plans/logical/LogicalOlapTableSink.java | 9 +++--- .../plans/physical/PhysicalOlapTableSink.java | 32 ++++++++++++---------- .../java/org/apache/doris/nereids/util/Utils.java | 5 ++-- 10 files changed, 63 insertions(+), 57 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundOlapTableSink.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundOlapTableSink.java index cfebd0e5d3..3e843010c2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundOlapTableSink.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundOlapTableSink.java @@ -29,7 +29,6 @@ import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; import org.apache.doris.nereids.util.Utils; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; import java.util.List; import java.util.Objects; @@ -53,10 +52,10 @@ public class UnboundOlapTableSink<CHILD_TYPE extends Plan> extends LogicalUnary< List<String> partitions, Optional<GroupExpression> groupExpression, Optional<LogicalProperties> logicalProperties, CHILD_TYPE child) { super(PlanType.LOGICAL_UNBOUND_OLAP_TABLE_SINK, groupExpression, logicalProperties, child); - this.nameParts = ImmutableList.copyOf(Objects.requireNonNull(nameParts, "nameParts cannot be null")); - this.colNames = Utils.copyIfNotNull(colNames); - this.hints = Utils.copyIfNotNull(hints); - this.partitions = Utils.copyIfNotNull(partitions); + this.nameParts = Utils.copyRequiredList(nameParts); + this.colNames = Utils.copyRequiredList(colNames); + this.hints = Utils.copyRequiredList(hints); + this.partitions = Utils.copyRequiredList(partitions); } public List<String> getColNames() { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java index 10cb05acba..a505582f0b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java @@ -326,7 +326,7 @@ public class PhysicalPlanTranslator extends DefaultPlanVisitor<PlanFragment, Pla OlapTableSink sink = new OlapTableSink( olapTableSink.getTargetTable(), olapTuple, - olapTableSink.getPartitionIds(), + olapTableSink.getPartitionIds().isEmpty() ? null : olapTableSink.getPartitionIds(), olapTableSink.isSingleReplicaLoad() ); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java index dc186625be..b507b41e79 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java @@ -315,14 +315,18 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> { public LogicalPlan visitInsertIntoQuery(InsertIntoQueryContext ctx) { List<String> tableName = visitMultipartIdentifier(ctx.tableName); String labelName = ctx.labelName == null ? null : ctx.labelName.getText(); - List<String> colNames = ctx.cols == null ? null : visitIdentifierList(ctx.cols); - List<String> partitions = ctx.partition == null ? null : visitIdentifierList(ctx.partition); - UnboundOlapTableSink<?> sink = new UnboundOlapTableSink<>(tableName, colNames, ImmutableList.of(), - partitions, visitQuery(ctx.query())); + List<String> colNames = ctx.cols == null ? ImmutableList.of() : visitIdentifierList(ctx.cols); + List<String> partitions = ctx.partition == null ? ImmutableList.of() : visitIdentifierList(ctx.partition); + UnboundOlapTableSink<?> sink = new UnboundOlapTableSink<>( + tableName, + colNames, + ImmutableList.of(), + partitions, + visitQuery(ctx.query())); if (ctx.explain() != null) { return withExplain(sink, ctx.explain()); } - return new InsertIntoTableCommand(sink, labelName); + return new InsertIntoTableCommand(sink, Optional.ofNullable(labelName)); } @Override @@ -345,7 +349,7 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> { @Override public LogicalPlan visitDelete(DeleteContext ctx) { List<String> tableName = visitMultipartIdentifier(ctx.tableName); - List<String> partitions = ctx.partition == null ? null : visitIdentifierList(ctx.partition); + List<String> partitions = ctx.partition == null ? ImmutableList.of() : visitIdentifierList(ctx.partition); LogicalPlan query = withTableAlias(withCheckPolicy( new UnboundRelation(RelationUtil.newRelationId(), tableName)), ctx.tableAlias()); if (ctx.USING() != null) { @@ -356,7 +360,8 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> { if (ctx.tableAlias().strictIdentifier() != null) { tableAlias = ctx.tableAlias().getText(); } - return withExplain(new DeleteCommand(tableName, tableAlias, partitions, query), ctx.explain()); + return withExplain(new DeleteCommand(tableName, tableAlias, partitions, query), + ctx.explain()); } /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindInsertTargetTable.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindInsertTargetTable.java index d0ff477696..fc1ae2e21d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindInsertTargetTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindInsertTargetTable.java @@ -166,8 +166,8 @@ public class BindInsertTargetTable extends OneAnalysisRuleFactory { } private List<Long> bindPartitionIds(OlapTable table, List<String> partitions) { - return partitions == null - ? null + return partitions.isEmpty() + ? ImmutableList.of() : partitions.stream().map(pn -> { Partition partition = table.getPartition(pn); if (partition == null) { @@ -179,7 +179,7 @@ public class BindInsertTargetTable extends OneAnalysisRuleFactory { } private List<Column> bindTargetColumns(OlapTable table, List<String> colsName) { - return colsName == null + return colsName.isEmpty() ? table.getFullSchema().stream().filter(column -> column.isVisible() && !column.isMaterializedViewColumn()) .collect(Collectors.toList()) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteCommand.java index 48408db1a8..d7216d257b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteCommand.java @@ -42,7 +42,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import java.util.List; -import java.util.Objects; +import java.util.Optional; /** * delete from unique key table. @@ -57,18 +57,18 @@ public class DeleteCommand extends Command implements ForwardWithSync, Explainab /** * constructor */ - public DeleteCommand(List<String> nameParts, String tableAlias, List<String> partitions, LogicalPlan logicalQuery) { + public DeleteCommand(List<String> nameParts, String tableAlias, List<String> partitions, + LogicalPlan logicalQuery) { super(PlanType.DELETE_COMMAND); - this.nameParts = ImmutableList.copyOf(Objects.requireNonNull(nameParts, - "nameParts in DeleteCommand cannot be null")); + this.nameParts = Utils.copyRequiredList(nameParts); this.tableAlias = tableAlias; - this.partitions = Utils.copyIfNotNull(partitions); + this.partitions = Utils.copyRequiredList(partitions); this.logicalQuery = logicalQuery; } @Override public void run(ConnectContext ctx, StmtExecutor executor) throws Exception { - new InsertIntoTableCommand(completeQueryPlan(ctx, logicalQuery), null).run(ctx, executor); + new InsertIntoTableCommand(completeQueryPlan(ctx, logicalQuery), Optional.empty()).run(ctx, executor); } private void checkTable(ConnectContext ctx) { @@ -112,7 +112,8 @@ public class DeleteCommand extends Command implements ForwardWithSync, Explainab logicalQuery = new LogicalProject<>(selectLists, logicalQuery); // make UnboundTableSink - return new UnboundOlapTableSink<>(nameParts, cols, null, partitions, logicalQuery); + return new UnboundOlapTableSink<>(nameParts, cols, ImmutableList.of(), + partitions, logicalQuery); } public LogicalPlan getLogicalQuery() { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/InsertIntoTableCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/InsertIntoTableCommand.java index 8e7c688597..94e39de297 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/InsertIntoTableCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/InsertIntoTableCommand.java @@ -45,7 +45,6 @@ import org.apache.logging.log4j.Logger; import java.util.Objects; import java.util.Optional; import java.util.Set; -import javax.annotation.Nullable; /** * insert into select command implementation @@ -60,14 +59,14 @@ public class InsertIntoTableCommand extends Command implements ForwardWithSync, public static final Logger LOG = LogManager.getLogger(InsertIntoTableCommand.class); private final LogicalPlan logicalQuery; - private final @Nullable String labelName; + private final Optional<String> labelName; private NereidsPlanner planner; private boolean isTxnBegin = false; /** * constructor */ - public InsertIntoTableCommand(LogicalPlan logicalQuery, @Nullable String labelName) { + public InsertIntoTableCommand(LogicalPlan logicalQuery, Optional<String> labelName) { super(PlanType.INSERT_INTO_TABLE_COMMAND); this.logicalQuery = Objects.requireNonNull(logicalQuery, "logicalQuery cannot be null in InsertIntoTableCommand"); @@ -104,10 +103,7 @@ public class InsertIntoTableCommand extends Command implements ForwardWithSync, if (ctx.getMysqlChannel() != null) { ctx.getMysqlChannel().reset(); } - String label = this.labelName; - if (label == null) { - label = String.format("label_%x_%x", ctx.queryId().hi, ctx.queryId().lo); - } + String label = this.labelName.orElse(String.format("label_%x_%x", ctx.queryId().hi, ctx.queryId().lo)); Optional<TreeNode> plan = ((Set<TreeNode>) planner.getPhysicalPlan() .collect(node -> node instanceof PhysicalOlapTableSink)).stream().findAny(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UpdateCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UpdateCommand.java index a582c22394..3b9a694c6a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UpdateCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UpdateCommand.java @@ -36,6 +36,7 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalPlan; import org.apache.doris.nereids.trees.plans.logical.LogicalProject; import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; import org.apache.doris.nereids.util.RelationUtil; +import org.apache.doris.nereids.util.Utils; import org.apache.doris.qe.ConnectContext; import org.apache.doris.qe.SessionVariable; import org.apache.doris.qe.StmtExecutor; @@ -47,6 +48,7 @@ import com.google.common.collect.Maps; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import javax.annotation.Nullable; /** @@ -76,17 +78,15 @@ public class UpdateCommand extends Command implements ForwardWithSync, Explainab public UpdateCommand(List<String> nameParts, @Nullable String tableAlias, List<EqualTo> assignments, LogicalPlan logicalQuery) { super(PlanType.UPDATE_COMMAND); - this.nameParts = ImmutableList.copyOf(Objects.requireNonNull(nameParts, - "tableName is required in update command")); - this.assignments = ImmutableList.copyOf(Objects.requireNonNull(assignments, - "assignment is required in update command")); + this.nameParts = Utils.copyRequiredList(nameParts); + this.assignments = Utils.copyRequiredList(assignments); this.tableAlias = tableAlias; this.logicalQuery = Objects.requireNonNull(logicalQuery, "logicalQuery is required in update command"); } @Override public void run(ConnectContext ctx, StmtExecutor executor) throws Exception { - new InsertIntoTableCommand(completeQueryPlan(ctx, logicalQuery), null).run(ctx, executor); + new InsertIntoTableCommand(completeQueryPlan(ctx, logicalQuery), Optional.empty()).run(ctx, executor); } /** @@ -119,7 +119,8 @@ public class UpdateCommand extends Command implements ForwardWithSync, Explainab logicalQuery = new LogicalProject<>(selectItems, logicalQuery); // make UnboundTableSink - return new UnboundOlapTableSink<>(nameParts, null, null, null, logicalQuery); + return new UnboundOlapTableSink<>(nameParts, ImmutableList.of(), ImmutableList.of(), + ImmutableList.of(), logicalQuery); } private void checkTable(ConnectContext ctx) throws AnalysisException { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapTableSink.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapTableSink.java index 254d503a80..26f0393e3f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapTableSink.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapTableSink.java @@ -51,14 +51,15 @@ public class LogicalOlapTableSink<CHILD_TYPE extends Plan> extends LogicalUnary< this(database, targetTable, cols, partitionIds, Optional.empty(), Optional.empty(), child); } - public LogicalOlapTableSink(Database database, OlapTable targetTable, List<Column> cols, List<Long> partitionIds, - Optional<GroupExpression> groupExpression, Optional<LogicalProperties> logicalProperties, + public LogicalOlapTableSink(Database database, OlapTable targetTable, List<Column> cols, + List<Long> partitionIds, Optional<GroupExpression> groupExpression, + Optional<LogicalProperties> logicalProperties, CHILD_TYPE child) { super(PlanType.LOGICAL_OLAP_TABLE_SINK, groupExpression, logicalProperties, child); this.database = Objects.requireNonNull(database, "database != null in LogicalOlapTableSink"); this.targetTable = Objects.requireNonNull(targetTable, "targetTable != null in LogicalOlapTableSink"); - this.cols = Utils.copyIfNotNull(cols); - this.partitionIds = Utils.copyIfNotNull(partitionIds); + this.cols = Utils.copyRequiredList(cols); + this.partitionIds = Utils.copyRequiredList(partitionIds); } @Override diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalOlapTableSink.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalOlapTableSink.java index 6b9c39fff1..21d36dda2a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalOlapTableSink.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalOlapTableSink.java @@ -33,7 +33,7 @@ import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; import org.apache.doris.nereids.util.Utils; import org.apache.doris.statistics.Statistics; -import com.google.common.base.Preconditions; +import avro.shaded.com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; @@ -54,37 +54,39 @@ public class PhysicalOlapTableSink<CHILD_TYPE extends Plan> extends PhysicalUnar private final List<Long> partitionIds; private final boolean singleReplicaLoad; - public PhysicalOlapTableSink(Database database, OlapTable targetTable, List<Long> partitionIds, List<Column> cols, - boolean singleReplicaLoad, LogicalProperties logicalProperties, CHILD_TYPE child) { + public PhysicalOlapTableSink(Database database, OlapTable targetTable, List<Long> partitionIds, + List<Column> cols, boolean singleReplicaLoad, LogicalProperties logicalProperties, + CHILD_TYPE child) { this(database, targetTable, partitionIds, cols, singleReplicaLoad, Optional.empty(), logicalProperties, child); } /** * Constructor */ - public PhysicalOlapTableSink(Database database, OlapTable targetTable, List<Long> partitionIds, List<Column> cols, - boolean singleReplicaLoad, Optional<GroupExpression> groupExpression, LogicalProperties logicalProperties, - CHILD_TYPE child) { + public PhysicalOlapTableSink(Database database, OlapTable targetTable, List<Long> partitionIds, + List<Column> cols, boolean singleReplicaLoad, Optional<GroupExpression> groupExpression, + LogicalProperties logicalProperties, CHILD_TYPE child) { super(PlanType.PHYSICAL_OLAP_TABLE_SINK, groupExpression, logicalProperties, child); - this.database = Preconditions.checkNotNull(database, "database != null in PhysicalOlapTableSink"); - this.targetTable = Preconditions.checkNotNull(targetTable, "targetTable != null in PhysicalOlapTableSink"); - this.cols = cols; - this.partitionIds = partitionIds; + this.database = Objects.requireNonNull(database, "database != null in PhysicalOlapTableSink"); + this.targetTable = Objects.requireNonNull(targetTable, "targetTable != null in PhysicalOlapTableSink"); + this.cols = Utils.copyRequiredList(cols); + this.partitionIds = Utils.copyRequiredList(partitionIds); this.singleReplicaLoad = singleReplicaLoad; } /** * Constructor */ - public PhysicalOlapTableSink(Database database, OlapTable targetTable, List<Long> partitionIds, List<Column> cols, - boolean singleReplicaLoad, Optional<GroupExpression> groupExpression, LogicalProperties logicalProperties, - PhysicalProperties physicalProperties, Statistics statistics, CHILD_TYPE child) { + public PhysicalOlapTableSink(Database database, OlapTable targetTable, List<Long> partitionIds, + List<Column> cols, boolean singleReplicaLoad, Optional<GroupExpression> groupExpression, + LogicalProperties logicalProperties, PhysicalProperties physicalProperties, Statistics statistics, + CHILD_TYPE child) { super(PlanType.PHYSICAL_OLAP_TABLE_SINK, groupExpression, logicalProperties, physicalProperties, statistics, child); this.database = Objects.requireNonNull(database, "database != null in PhysicalOlapTableSink"); this.targetTable = Objects.requireNonNull(targetTable, "targetTable != null in PhysicalOlapTableSink"); - this.cols = Utils.copyIfNotNull(cols); - this.partitionIds = Utils.copyIfNotNull(partitionIds); + this.cols = Utils.copyRequiredList(cols); + this.partitionIds = Utils.copyRequiredList(partitionIds); this.singleReplicaLoad = singleReplicaLoad; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java index 83288e2456..f995ab138c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java @@ -32,6 +32,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -252,7 +253,7 @@ public class Utils { ).collect(ImmutableList.toImmutableList()); } - public static <T> List<T> copyIfNotNull(List<T> list) { - return list == null ? null : ImmutableList.copyOf(list); + public static <T> List<T> copyRequiredList(List<T> list) { + return ImmutableList.copyOf(Objects.requireNonNull(list, "non-null list is required")); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org