This is an automated email from the ASF dual-hosted git repository. kxiao pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push: new c62acf5c318 [Bug](repeat) fix core dump coz output slot'order on repeat node not match with pre repeat exprs (#32662) (#34803) c62acf5c318 is described below commit c62acf5c3184d05fdc48d6ee6d331e6d6ba3cd1d Author: Pxl <pxl...@qq.com> AuthorDate: Mon May 20 11:25:43 2024 +0800 [Bug](repeat) fix core dump coz output slot'order on repeat node not match with pre repeat exprs (#32662) (#34803) fix core dump coz output slot'order on repeat node not match with pre repeat exprs --- .../glue/translator/PhysicalPlanTranslator.java | 22 +++++----- .../test_dup_mv_repeat/test_dup_mv_repeat.out | 5 +++ .../test_dup_mv_repeat/test_dup_mv_repeat.groovy | 47 ++++++++++++++++++++++ 3 files changed, 61 insertions(+), 13 deletions(-) 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 1842e193152..31b01b4af22 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 @@ -1932,19 +1932,15 @@ public class PhysicalPlanTranslator extends DefaultPlanVisitor<PlanFragment, Pla .map(NamedExpression::toSlot) .collect(ImmutableList.toImmutableList()); - Set<Expression> usedSlotInRepeat = ImmutableSet.<Expression>builder() - .addAll(flattenGroupingSetExprs) - .addAll(aggregateFunctionUsedSlots) - .build(); - - List<Expr> preRepeatExprs = usedSlotInRepeat.stream() - .map(expr -> ExpressionTranslator.translate(expr, context)) - .collect(ImmutableList.toImmutableList()); - - List<Slot> outputSlots = repeat.getOutputExpressions() - .stream() - .map(NamedExpression::toSlot) - .collect(ImmutableList.toImmutableList()); + // keep flattenGroupingSetExprs comes first + List<Expr> preRepeatExprs = Stream.concat(flattenGroupingSetExprs.stream(), aggregateFunctionUsedSlots.stream()) + .map(expr -> ExpressionTranslator.translate(expr, context)).collect(ImmutableList.toImmutableList()); + + // outputSlots's order need same with preRepeatExprs + List<Slot> outputSlots = Stream.concat( + repeat.getOutputExpressions().stream().filter(output -> flattenGroupingSetExprs.contains(output)), + repeat.getOutputExpressions().stream().filter(output -> !flattenGroupingSetExprs.contains(output))) + .map(NamedExpression::toSlot).collect(ImmutableList.toImmutableList()); // NOTE: we should first translate preRepeatExprs, then generate output tuple, // or else the preRepeatExprs can not find the bottom slotRef and throw diff --git a/regression-test/data/mv_p0/test_dup_mv_repeat/test_dup_mv_repeat.out b/regression-test/data/mv_p0/test_dup_mv_repeat/test_dup_mv_repeat.out new file mode 100644 index 00000000000..a958cf0b819 --- /dev/null +++ b/regression-test/data/mv_p0/test_dup_mv_repeat/test_dup_mv_repeat.out @@ -0,0 +1,5 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select_mv -- +abc 123.0 +def 456.0 + diff --git a/regression-test/suites/mv_p0/test_dup_mv_repeat/test_dup_mv_repeat.groovy b/regression-test/suites/mv_p0/test_dup_mv_repeat/test_dup_mv_repeat.groovy new file mode 100644 index 00000000000..0a40c3cb050 --- /dev/null +++ b/regression-test/suites/mv_p0/test_dup_mv_repeat/test_dup_mv_repeat.groovy @@ -0,0 +1,47 @@ +// 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. + +import org.codehaus.groovy.runtime.IOGroovyMethods + +suite ("test_dup_mv_repeat") { + + sql """ DROP TABLE IF EXISTS d_table; """ + + sql """ + CREATE TABLE `db1` ( + `dt` date NULL, + `s` varchar(128) NULL, + `n` bigint NULL + ) ENGINE=OLAP + DUPLICATE KEY(`dt`) + DISTRIBUTED BY HASH(`dt`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "storage_format" = "V2" + ); + """ + + sql "insert into db1 values('2020-01-01','abc',123),('2020-01-02','def',456);" + + createMV ("create materialized view dbviwe as select dt,s,sum(n) as n from db1 group by dt,s;") + + explain { + sql("SELECT s AS s, sum(n) / count(DISTINCT dt) AS n FROM db1 GROUP BY GROUPING SETS((s)) order by 1;") + contains "(dbviwe)" + } + qt_select_mv "SELECT s AS s, sum(n) / count(DISTINCT dt) AS n FROM db1 GROUP BY GROUPING SETS((s)) order by 1;" +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org