This is an automated email from the ASF dual-hosted git repository. morrysnow pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push: new db4d061a686 [fix](Nereids) null type result with alias name should keep alias name (#37457) (#37524) db4d061a686 is described below commit db4d061a686531731b830747f6a3f903313bb07b Author: morrySnow <101034200+morrys...@users.noreply.github.com> AuthorDate: Tue Jul 9 20:46:51 2024 +0800 [fix](Nereids) null type result with alias name should keep alias name (#37457) (#37524) pick from master #37457 --- .../nereids/rules/analysis/BindExpression.java | 34 +++++----------------- .../trees/plans/commands/info/CreateMTMVInfo.java | 6 +++- .../data/mtmv_p0/test_create_with_null_type.out | 8 ++++- .../mtmv_p0/test_create_with_null_type.groovy | 26 ++++++++++++++++- 4 files changed, 44 insertions(+), 30 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java index ad8dec4ac7c..c1080adf3b7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java @@ -42,7 +42,6 @@ import org.apache.doris.nereids.rules.RuleType; import org.apache.doris.nereids.rules.expression.ExpressionRewriteContext; import org.apache.doris.nereids.trees.expressions.Alias; import org.apache.doris.nereids.trees.expressions.BoundStar; -import org.apache.doris.nereids.trees.expressions.Cast; import org.apache.doris.nereids.trees.expressions.DefaultValueSlot; import org.apache.doris.nereids.trees.expressions.EqualTo; import org.apache.doris.nereids.trees.expressions.ExprId; @@ -90,11 +89,8 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalTVFRelation; import org.apache.doris.nereids.trees.plans.logical.UsingJoin; import org.apache.doris.nereids.trees.plans.visitor.InferPlanOutputAlias; import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.types.NullType; import org.apache.doris.nereids.types.StructField; import org.apache.doris.nereids.types.StructType; -import org.apache.doris.nereids.types.TinyIntType; import org.apache.doris.nereids.util.ExpressionUtils; import org.apache.doris.nereids.util.PlanUtils; import org.apache.doris.nereids.util.TypeCoercionUtils; @@ -212,38 +208,22 @@ public class BindExpression implements AnalysisRuleFactory { private LogicalResultSink<Plan> bindResultSink(MatchingContext<UnboundResultSink<Plan>> ctx) { LogicalSink<Plan> sink = ctx.root; - Plan child = sink.child(); - List<Slot> output = child.getOutput(); - List<NamedExpression> castNullToTinyInt = Lists.newArrayListWithCapacity(output.size()); - boolean needProject = false; - for (Slot slot : output) { - DataType newType = TypeCoercionUtils.replaceSpecifiedType( - slot.getDataType(), NullType.class, TinyIntType.INSTANCE); - if (!newType.equals(slot.getDataType())) { - needProject = true; - castNullToTinyInt.add(new Alias(new Cast(slot, newType))); - } else { - castNullToTinyInt.add(slot); - } - } - if (needProject) { - child = new LogicalProject<>(castNullToTinyInt, child); - } if (ctx.connectContext.getState().isQuery()) { - List<NamedExpression> outputExprs = child.getOutput().stream() + List<NamedExpression> outputExprs = sink.child().getOutput().stream() .map(NamedExpression.class::cast) .collect(ImmutableList.toImmutableList()); - return new LogicalResultSink<>(outputExprs, child); + return new LogicalResultSink<>(outputExprs, sink.child()); } // Should infer column name for expression when query command - final ImmutableListMultimap.Builder<ExprId, Integer> exprIdToIndexMapBuilder = ImmutableListMultimap.builder(); - List<Slot> childOutput = child.getOutput(); + final ImmutableListMultimap.Builder<ExprId, Integer> exprIdToIndexMapBuilder = + ImmutableListMultimap.builder(); + List<Slot> childOutput = sink.child().getOutput(); for (int index = 0; index < childOutput.size(); index++) { exprIdToIndexMapBuilder.put(childOutput.get(index).getExprId(), index); } InferPlanOutputAlias aliasInfer = new InferPlanOutputAlias(childOutput); - List<NamedExpression> sinkExpr = aliasInfer.infer(child, exprIdToIndexMapBuilder.build()); - return new LogicalResultSink<>(sinkExpr, child); + List<NamedExpression> output = aliasInfer.infer(sink.child(), exprIdToIndexMapBuilder.build()); + return new LogicalResultSink<>(output, sink.child()); } private LogicalSubQueryAlias<Plan> bindSubqueryAlias(MatchingContext<LogicalSubQueryAlias<Plan>> ctx) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java index bad9acd7468..dac8674e08c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java @@ -66,6 +66,9 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalSubQueryAlias; import org.apache.doris.nereids.trees.plans.visitor.NondeterministicFunctionCollector; import org.apache.doris.nereids.types.AggStateType; import org.apache.doris.nereids.types.DataType; +import org.apache.doris.nereids.types.NullType; +import org.apache.doris.nereids.types.TinyIntType; +import org.apache.doris.nereids.util.TypeCoercionUtils; import org.apache.doris.nereids.util.Utils; import org.apache.doris.qe.ConnectContext; import org.apache.doris.qe.SessionVariable; @@ -372,7 +375,8 @@ public class CreateMTMVInfo { // If datatype is AggStateType, AggregateType should be generic, or column definition check will fail columns.add(new ColumnDefinition( colName, - slots.get(i).getDataType(), + TypeCoercionUtils.replaceSpecifiedType(slots.get(i).getDataType(), + NullType.class, TinyIntType.INSTANCE), false, slots.get(i).getDataType() instanceof AggStateType ? AggregateType.GENERIC : null, slots.get(i).nullable(), diff --git a/regression-test/data/mtmv_p0/test_create_with_null_type.out b/regression-test/data/mtmv_p0/test_create_with_null_type.out index de8fa5e4403..ec90732f163 100644 --- a/regression-test/data/mtmv_p0/test_create_with_null_type.out +++ b/regression-test/data/mtmv_p0/test_create_with_null_type.out @@ -3,5 +3,11 @@ \N -- !desc -- -test_create_with_null_type DUP_KEYS __cast_0 TINYINT TINYINT Yes true \N true +test_create_with_null_type DUP_KEYS __literal_0 TINYINT TINYINT Yes true \N true + +-- !select -- +\N + +-- !desc -- +test_create_with_null_type DUP_KEYS id TINYINT TINYINT Yes true \N true diff --git a/regression-test/suites/mtmv_p0/test_create_with_null_type.groovy b/regression-test/suites/mtmv_p0/test_create_with_null_type.groovy index b749c95c8e1..2236b4e8d64 100644 --- a/regression-test/suites/mtmv_p0/test_create_with_null_type.groovy +++ b/regression-test/suites/mtmv_p0/test_create_with_null_type.groovy @@ -59,6 +59,30 @@ suite("test_create_with_null_type") { qt_desc "desc ${mvName} all" - sql """drop table if exists `${tableName}`""" sql """drop materialized view if exists ${mvName};""" + + sql """ + CREATE MATERIALIZED VIEW ${mvName} + BUILD DEFERRED REFRESH AUTO ON MANUAL + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ('replication_num' = '1') + AS + SELECT null as id FROM ${tableName}; + """ + + sql """ + REFRESH MATERIALIZED VIEW ${mvName} AUTO; + """ + + jobName = getJobName(dbName, mvName); + log.info(jobName) + waitingMTMVTaskFinished(jobName) + + order_qt_select "SELECT * FROM ${mvName}" + + qt_desc "desc ${mvName} all" + + sql """drop materialized view if exists ${mvName};""" + + sql """drop table if exists `${tableName}`""" } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org