This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new 8c40184c156 branch-4.0: [refactor](load) remove castToSlot in load
planner #57489 (#57708)
8c40184c156 is described below
commit 8c40184c156493bd7b3346c655a20ef4cb85ffe4
Author: morrySnow <[email protected]>
AuthorDate: Thu Nov 6 09:34:29 2025 +0800
branch-4.0: [refactor](load) remove castToSlot in load planner #57489
(#57708)
picked from #57489
---
.../nereids/load/NereidsLoadPlanInfoCollector.java | 83 ++++++++++------------
1 file changed, 39 insertions(+), 44 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/load/NereidsLoadPlanInfoCollector.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/load/NereidsLoadPlanInfoCollector.java
index 30c0574a822..628f34882a2 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/load/NereidsLoadPlanInfoCollector.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/load/NereidsLoadPlanInfoCollector.java
@@ -19,11 +19,9 @@ package org.apache.doris.nereids.load;
import org.apache.doris.analysis.DescriptorTable;
import org.apache.doris.analysis.Expr;
-import org.apache.doris.analysis.NullLiteral;
import org.apache.doris.analysis.PartitionNames;
import org.apache.doris.analysis.SlotDescriptor;
import org.apache.doris.analysis.SlotId;
-import org.apache.doris.analysis.StringLiteral;
import org.apache.doris.analysis.TupleDescriptor;
import org.apache.doris.analysis.TupleId;
import org.apache.doris.catalog.AggregateFunction;
@@ -34,7 +32,6 @@ import org.apache.doris.catalog.Partition;
import org.apache.doris.catalog.PartitionInfo;
import org.apache.doris.catalog.PartitionItem;
import org.apache.doris.catalog.PartitionType;
-import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.common.Config;
import org.apache.doris.common.DdlException;
@@ -44,16 +41,24 @@ import org.apache.doris.common.UserException;
import org.apache.doris.common.util.FileFormatConstants;
import org.apache.doris.nereids.CascadesContext;
import org.apache.doris.nereids.StatementContext;
+import org.apache.doris.nereids.analyzer.Scope;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.glue.translator.ExpressionTranslator;
import org.apache.doris.nereids.glue.translator.PlanTranslatorContext;
+import org.apache.doris.nereids.parser.NereidsParser;
import org.apache.doris.nereids.properties.PhysicalProperties;
+import org.apache.doris.nereids.rules.analysis.ExpressionAnalyzer;
+import org.apache.doris.nereids.rules.expression.rules.ConvertAggStateCast;
import org.apache.doris.nereids.rules.expression.rules.PartitionPruner;
import org.apache.doris.nereids.rules.expression.rules.SortedPartitionRanges;
+import org.apache.doris.nereids.trees.expressions.Alias;
+import org.apache.doris.nereids.trees.expressions.Cast;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.NamedExpression;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.SlotReference;
+import org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.StringLiteral;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapTableSink;
@@ -62,6 +67,9 @@ import
org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
import org.apache.doris.nereids.trees.plans.logical.LogicalPreFilter;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanVisitor;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.VarcharType;
+import org.apache.doris.nereids.util.TypeCoercionUtils;
import org.apache.doris.planner.GroupCommitBlockSink;
import org.apache.doris.planner.OlapTableSink;
import org.apache.doris.thrift.TExpr;
@@ -75,6 +83,7 @@ import org.apache.doris.thrift.TUniqueId;
import org.apache.doris.thrift.TUniqueKeyUpdateMode;
import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@@ -339,9 +348,6 @@ public class NereidsLoadPlanInfoCollector extends
DefaultPlanVisitor<Void, PlanT
}
}
- List<Expr> projectList = outputs.stream().map(e ->
ExpressionTranslator.translate(e, context))
- .collect(Collectors.toList());
-
// For Broker load with multiple file groups, all file groups share
the same destTuple.
// Create slots for destTuple only when processing the first file
group (when slots are empty).
// Subsequent file groups will reuse the slots created by the first
file group.
@@ -374,23 +380,23 @@ public class NereidsLoadPlanInfoCollector extends
DefaultPlanVisitor<Void, PlanT
context.createSlotDesc(loadPlanInfo.destTuple, (SlotReference)
slot, destTable);
}
}
-
- loadPlanInfo.destSlotIdToExprMap = Maps.newHashMap();
List<SlotDescriptor> slotDescriptorList =
loadPlanInfo.destTuple.getSlots();
+ loadPlanInfo.destSlotIdToExprMap = Maps.newHashMap();
for (int i = 0; i < slotDescriptorList.size(); ++i) {
- SlotDescriptor slotDescriptor = slotDescriptorList.get(i);
- Expr expr = projectList.get(i);
- PrimitiveType dstType =
slotDescriptor.getType().getPrimitiveType();
- PrimitiveType srcType = expr.getType().getPrimitiveType();
- if (!(dstType == PrimitiveType.JSONB
- && (srcType == PrimitiveType.VARCHAR || srcType ==
PrimitiveType.STRING))) {
- try {
- expr = castToSlot(slotDescriptor, expr);
- } catch (org.apache.doris.common.AnalysisException e) {
- throw new AnalysisException(e.getMessage(), e.getCause());
+ DataType targetType =
DataType.fromCatalogType(slotDescriptorList.get(i).getType());
+ Expression output = outputs.get(i);
+ if (!(targetType.isJsonType() &&
output.getDataType().isStringLikeType())) {
+ if (output instanceof Alias) {
+ output = TypeCoercionUtils.castIfNotSameType(((Alias)
output).child(), targetType);
+ } else {
+ output = TypeCoercionUtils.castIfNotSameType(output,
targetType);
+ }
+ if (output instanceof Cast &&
output.getDataType().isAggStateType()) {
+ output = ConvertAggStateCast.convert((Cast) output);
}
}
- loadPlanInfo.destSlotIdToExprMap.put(slotDescriptor.getId(), expr);
+ Expr expr = ExpressionTranslator.translate(output, context);
+
loadPlanInfo.destSlotIdToExprMap.put(slotDescriptorList.get(i).getId(), expr);
}
return null;
}
@@ -470,33 +476,36 @@ public class NereidsLoadPlanInfoCollector extends
DefaultPlanVisitor<Void, PlanT
for (SlotDescriptor slotDescriptor : oneRowTuple.getSlots()) {
Column column =
destTable.getColumn(slotDescriptor.getColumn().getName());
if (column != null) {
- Expr expr;
+ Expression expression;
if (column.getDefaultValue() != null) {
if (column.getDefaultValueExprDef() != null) {
try {
- expr = column.getDefaultValueExpr();
+ expression = new NereidsParser().parseExpression(
+
column.getDefaultValueExpr().toSqlWithoutTbl());
+ ExpressionAnalyzer analyzer = new
ExpressionAnalyzer(
+ null, new Scope(ImmutableList.of()), null,
true, true);
+ expression = analyzer.analyze(expression);
} catch (org.apache.doris.common.AnalysisException e) {
throw new AnalysisException(e.getMessage(),
e.getCause());
}
} else {
- expr = new StringLiteral(column.getDefaultValue());
+ expression = new
StringLiteral(column.getDefaultValue());
}
} else {
if (column.isAllowNull()) {
- expr =
NullLiteral.create(org.apache.doris.catalog.Type.VARCHAR);
+ expression = new
NullLiteral(VarcharType.SYSTEM_DEFAULT);
} else {
- expr = null;
+ expression = null;
}
}
if (exprMap.containsKey(column.getName())) {
continue;
}
- if (expr != null) {
- try {
- expr = castToSlot(slotDescriptor, expr);
- } catch (org.apache.doris.common.AnalysisException e) {
- throw new AnalysisException(e.getMessage(),
e.getCause());
- }
+ Expr expr = null;
+ if (expression != null) {
+ expression =
TypeCoercionUtils.castIfNotSameType(expression,
+
DataType.fromCatalogType(slotDescriptor.getType()));
+ expr = ExpressionTranslator.translate(expression, context);
}
loadPlanInfo.srcSlotIdToDefaultValueMap.put(slotDescriptor.getId(), expr);
srcSlots.put(column.getName(), slotDescriptor);
@@ -514,20 +523,6 @@ public class NereidsLoadPlanInfoCollector extends
DefaultPlanVisitor<Void, PlanT
return tupleDescriptor;
}
- private Expr castToSlot(SlotDescriptor slotDesc, Expr expr) throws
org.apache.doris.common.AnalysisException {
- PrimitiveType dstType = slotDesc.getType().getPrimitiveType();
- PrimitiveType srcType = expr.getType().getPrimitiveType();
- if (PrimitiveType.typeWithPrecision.contains(dstType) &&
PrimitiveType.typeWithPrecision.contains(srcType)
- && !slotDesc.getType().equals(expr.getType())) {
- return expr.castTo(slotDesc.getType());
- } else if (dstType != srcType || slotDesc.getType().isAggStateType()
&& expr.getType().isAggStateType()
- && !slotDesc.getType().equals(expr.getType())) {
- return expr.castTo(slotDesc.getType());
- } else {
- return expr;
- }
- }
-
// get all specified partition ids.
// if no partition specified, return null
private List<Long> getAllPartitionIds() throws DdlException,
AnalysisException {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]