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 @@ -100,15 +100,15 @@ protected String toSqlImpl() {
List<String> list = new ArrayList<>(children.size());
children.forEach(v -> list.add(v.toSqlImpl()));

return "ARRAY(" + StringUtils.join(list, ", ") + ")";
return "[" + StringUtils.join(list, ", ") + "]";
}

@Override
public String toDigestImpl() {
List<String> list = new ArrayList<>(children.size());
children.forEach(v -> list.add(v.toDigestImpl()));

return "ARRAY(" + StringUtils.join(list, ", ") + ")";
return "[" + StringUtils.join(list, ", ") + "]";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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.VirtualSlotReference;
import org.apache.doris.nereids.trees.expressions.WhenClause;
import org.apache.doris.nereids.trees.expressions.functions.ExpressionTrait;
import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction;
Expand Down Expand Up @@ -160,7 +161,7 @@ protected static boolean containsAllColumn(Expression expression, Set<String> mv
return true;
}
if (expression.children().isEmpty()) {
return false;
return expression instanceof VirtualSlotReference;
}
for (Expression child : expression.children()) {
if (child instanceof Literal) {
Expand Down Expand Up @@ -415,9 +416,6 @@ protected SlotContext generateBaseScanExprToMvExpr(LogicalOlapScan mvPlan) {
for (Slot mvSlot : mvPlan.getOutputByIndex(mvPlan.getSelectedIndexId())) {
boolean isPushed = false;
for (Slot baseSlot : mvPlan.getOutput()) {
if (org.apache.doris.analysis.CreateMaterializedViewStmt.isMVColumn(mvSlot.getName())) {
continue;
}
if (baseSlot.toSql().equalsIgnoreCase(
org.apache.doris.analysis.CreateMaterializedViewStmt.mvColumnBreaker(
normalizeName(mvSlot.getName())))) {
Expand All @@ -427,11 +425,6 @@ protected SlotContext generateBaseScanExprToMvExpr(LogicalOlapScan mvPlan) {
}
}
if (!isPushed) {
if (org.apache.doris.analysis.CreateMaterializedViewStmt.isMVColumn(mvSlot.getName())) {
mvNameToMvSlot.put(normalizeName(
org.apache.doris.analysis.CreateMaterializedViewStmt.mvColumnBreaker(mvSlot.getName())),
mvSlot);
}
mvNameToMvSlot.put(normalizeName(mvSlot.getName()), mvSlot);
}
}
Expand Down

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions regression-test/data/mv_p0/test_mv_dp/test_mv_dp.out
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 --
1 4 4
2 2 1

13 changes: 13 additions & 0 deletions regression-test/data/mv_p0/test_upper_alias/test_upper_alias.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select_mv --
XXX
YYY

-- !select_mv --
XXX
YYY

-- !select_mv --
wfsdf
wfsdf

Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,14 @@
-- !select_mv --
7

-- !select_mv --
1 2
2 1
3 1

-- !select_mv --
1 2

-- !select_mv --
1 2 1

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ suite ("test_dup_mv_year") {
}

sql "insert into d_table select 4,'2033-12-31','2033-12-31 01:02:03';"
Thread.sleep(1000)

qt_select_star "select * from d_table order by k1;"

Expand Down
71 changes: 71 additions & 0 deletions regression-test/suites/mv_p0/test_mv_dp/test_mv_dp.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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_mv_dp") {

sql """ DROP TABLE IF EXISTS dp; """

sql """
CREATE TABLE dp (
`d` int NULL ,
`status` text NULL ,
`uid_list` array<text> NULL
) ENGINE=OLAP
DUPLICATE KEY(`d`)
DISTRIBUTED BY HASH(`d`) BUCKETS AUTO
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
"""

sql """INSERT INTO `dp` VALUES (1,'success',["1","2"]),(2,'fail',["1"]);"""

createMV("""CREATE MATERIALIZED VIEW view_2 as
select d,
bitmap_union(bitmap_from_array(cast(uid_list as array<bigint>))),
bitmap_union(bitmap_from_array(if(status='success', cast(uid_list as array<bigint>), array())))
from dp
group by d;""")

sql """INSERT INTO `dp` VALUES (1,'success',["3","4"]),(2,'success',["5"]);"""
/*
streamLoad {
table "test"

set 'columns', 'date'

file './test'
time 10000 // limit inflight 10s
}
*/
explain {
sql("""select d,
bitmap_union_count(bitmap_from_array(cast(uid_list as array<bigint>))),
bitmap_union_count(bitmap_from_array(if(status='success', cast(uid_list as array<bigint>), array())))
from dp
group by d;""")
contains "(view_2)"
}

qt_select_mv """select d,
bitmap_union_count(bitmap_from_array(cast(uid_list as array<bigint>))),
bitmap_union_count(bitmap_from_array(if(status='success', cast(uid_list as array<bigint>), array())))
from dp
group by d order by 1;"""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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_upper_alias") {
sql """set enable_nereids_planner=true"""
sql """SET enable_fallback_to_original_planner=false"""
sql """ drop table if exists test_0401;"""

sql """
CREATE TABLE test_0401 (
`d_b` varchar(128) NULL,
`d_a` varchar(128) NULL,
`amt_b0` double NULL
) ENGINE=OLAP
DUPLICATE KEY(`d_b`)
DISTRIBUTED BY HASH(`d_b`) BUCKETS 3
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
"""

sql """insert into test_0401 values('xxx', 'wfsdf', 9.30 );"""

createMV ("""
create materialized view test_0401_mv as
select d_b, sum(amt_b0) as amt_b0 from test_0401 group by d_b;
""")

createMV ("""
create materialized view test_0401_mv2 as
select d_a,d_b from test_0401;
""")

sql """insert into test_0401 values('yyy', 'wfsdf', 91.310 );"""

explain {
sql("SELECT upper(d_b) AS d_b FROM test_0401 GROUP BY upper(d_b) order by 1;")
contains "(test_0401_mv)"
}
qt_select_mv "SELECT upper(d_b) AS d_b FROM test_0401 GROUP BY upper(d_b) order by 1;"

explain {
sql("SELECT upper(d_b) AS d_bb FROM test_0401 GROUP BY upper(d_b) order by 1;")
contains "(test_0401_mv)"
}
qt_select_mv "SELECT upper(d_b) AS d_bb FROM test_0401 GROUP BY upper(d_b) order by 1;"

explain {
sql("SELECT d_a AS d_b FROM test_0401 order by 1;")
contains "(test_0401_mv2)"
}
qt_select_mv "SELECT d_a AS d_b FROM test_0401 order by 1;"
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ suite ("testAggQueryOnAggMV1") {
sql """insert into emps values("2020-01-03",3,"c",3,3,3);"""


createMV("create materialized view emps_mv as select deptno, sum(salary), max(commission) from emps group by deptno ;")
createMV("create materialized view emps_mv as select deptno, sum(salary), max(commission) from emps group by deptno;")
createMV("create materialized view emps_mv_count_key as select deptno, count(deptno) from emps group by deptno;")
createMV("create materialized view emps_mv_if as select deptno, sum(if(empid = 1, empid, salary)) from emps group by deptno;")

sql """insert into emps values("2020-01-01",1,"a",1,1,1);"""

Expand All @@ -59,4 +61,22 @@ suite ("testAggQueryOnAggMV1") {
contains "(emps_mv)"
}
qt_select_mv "select sum(salary) as salary from emps;"

explain {
sql("select deptno, count(deptno) from emps group by deptno order by deptno;")
contains "(emps_mv_count_key)"
}
qt_select_mv "select deptno, count(deptno) from emps group by deptno order by deptno;"

explain {
sql("select deptno, count(deptno) from emps where deptno=1 group by deptno order by deptno;")
contains "(emps_mv_count_key)"
}
qt_select_mv "select deptno, count(deptno) from emps where deptno=1 group by deptno order by deptno;"

explain {
sql("select deptno, sum(salary), max(commission) from emps where salary=1 group by deptno order by deptno;")
contains "(emps)"
}
qt_select_mv "select deptno, sum(salary), max(commission) from emps where salary=1 group by deptno order by deptno;"
}