Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1932,19 +1932,15 @@ public PlanFragment visitPhysicalRepeat(PhysicalRepeat<? extends Plan> repeat, P
.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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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;"
}