Skip to content

Commit

Permalink
fix test fail
Browse files Browse the repository at this point in the history
  • Loading branch information
seawinde committed Nov 27, 2024
1 parent 767509e commit dde9346
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -487,27 +487,37 @@ private static boolean isGroupByEqualsByFunctionDependency(
if (!viewShuttledExprQueryBasedSet.containsAll(queryGroupShuttledExpression)) {
return false;
}
Set<Expression> viewShouldUniformExpressionSet = new HashSet<>();
Set<Expression> viewShouldRemovedExpressionSet = new HashSet<>();
Set<Expression> viewScanShouldReservedExpressionSet = new HashSet<>();
// calc the group by expr which is needed to roll up and should be uniform
for (Map.Entry<Expression, Expression> expressionEntry :
for (Map.Entry<Expression, Expression> expressionMappingEntry :
viewShuttledExprQueryBasedToViewGroupByExprMap.entrySet()) {
if (queryGroupShuttledExpression.contains(expressionEntry.getKey())) {
// the group expr which query has, do not require uniform
continue;
if (queryGroupShuttledExpression.contains(expressionMappingEntry.getKey())) {
// the group expr which query has, do not require eliminate
viewScanShouldReservedExpressionSet.add(
viewShuttledExprToScanExprMapping.get(expressionMappingEntry.getValue()));
} else {
// the view expression which is more than query's expression, should try to eliminate
viewShouldRemovedExpressionSet.add(expressionMappingEntry.getValue());
}
viewShouldUniformExpressionSet.add(expressionEntry.getValue());
}

DataTrait dataTrait = tempRewrittenPlan.computeDataTrait();
for (Expression shouldUniformExpr : viewShouldUniformExpressionSet) {
Expression viewScanExpression = viewShuttledExprToScanExprMapping.get(shouldUniformExpr);
for (Expression viewShouldRemovedExpr : viewShouldRemovedExpressionSet) {
Expression viewScanExpression = viewShuttledExprToScanExprMapping.get(viewShouldRemovedExpr);
if (viewScanExpression == null) {
return false;
}
if (!(viewScanExpression instanceof Slot)) {
return false;
}
if (!dataTrait.isUniform((Slot) viewScanExpression)) {
if (!dataTrait.isUniform((Slot) viewScanExpression)
&& Sets.intersection(dataTrait.calEqualSet((Slot) viewScanExpression),
viewScanShouldReservedExpressionSet).isEmpty()) {
// Such as query is l_orderkey#0, l_linenumber#1, o_custkey#17, l_partkey#2
// view is ps_partkey#25, o_orderkey#16, l_orderkey#0, l_linenumber#1, o_custkey#17, l_partkey#2
// If want to check the group by equality, ps_partkey#25, o_orderkey#16 should be uniform
// or should be equal any of [ l_orderkey#0, l_linenumber#1, o_custkey#17, l_partkey#2]
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1979,9 +1979,8 @@ class Suite implements GroovyInterceptable {
check { result ->
boolean success = true;
for (String mv_name : mv_names) {
success = success && result.contains("${mv_name} chose")
Assert.assertEquals(true, result.contains("${mv_name} chose"))
}
Assert.assertEquals(true, success)
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions regression-test/suites/mv_p0/ssb/q_1_1/q_1_1.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@ suite ("mv_ssb_q_1_1") {
AND LO_ORDERDATE <= 19931231
AND LO_DISCOUNT >= 1 AND LO_DISCOUNT <= 3
AND LO_QUANTITY < 25
GROUP BY
LO_ORDERKEY;""")
GROUP BY LO_ORDERKEY;""")

sql """INSERT INTO lineorder_flat (LO_ORDERDATE, LO_ORDERKEY, LO_LINENUMBER, LO_CUSTKEY, LO_PARTKEY, LO_SUPPKEY, LO_ORDERPRIORITY, LO_SHIPPRIORITY, LO_QUANTITY, LO_EXTENDEDPRICE, LO_ORDTOTALPRICE, LO_DISCOUNT, LO_REVENUE, LO_SUPPLYCOST, LO_TAX, LO_COMMITDATE, LO_SHIPMODE,C_NAME,C_ADDRESS,C_CITY,C_NATION,C_REGION,C_PHONE,C_MKTSEGMENT,S_NAME,S_ADDRESS,S_CITY,S_NATION,S_REGION,S_PHONE,P_NAME,P_MFGR,P_CATEGORY,P_BRAND,P_COLOR,P_TYPE,P_SIZE,P_CONTAINER)
VALUES (19930101 , 2 , 2 , 2 , 2 , 2 ,'2',2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,'2023-06-09','shipmode','name','address','city','nation','region','phone','mktsegment','name','address','city','nation','region','phone','name','mfgr','category','brand','color','type',4,'container');"""
VALUES (19930101 , 2 , 2 , 2 , 2 , 2 ,'2',2 ,2 ,2 ,2 ,2 ,2 ,2 ,'2023-06-09','shipmode','name','address','city','nation','region','phone','mktsegment','name','address','city','nation','region','phone','name','mfgr','category','brand','color','type',4,'container');"""

qt_select_star "select * from lineorder_flat order by 1,2, P_MFGR;"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,34 +96,49 @@ suite("nested_mtmv") {
insert into orders_1 values
(null, 1, 'k', 99.5, 'a', 'b', 1, 'yy', '2023-10-17'),
(1, null, 'o', 109.2, 'c','d',2, 'mm', '2023-10-17'),
(1, null, 'o', 109.2, 'c','d',2, 'mm', '2023-10-17'),
(3, 3, null, 99.5, 'a', 'b', 1, 'yy', '2023-10-19'),
(3, 3, null, 99.5, 'a', 'b', 1, 'yy', '2023-10-19'),
(1, 2, 'o', null, 'a', 'b', 1, 'yy', '2023-10-20'),
(1, 2, 'o', null, 'a', 'b', 1, 'yy', '2023-10-20'),
(2, 3, 'k', 109.2, null,'d',2, 'mm', '2023-10-21'),
(2, 3, 'k', 109.2, null,'d',2, 'mm', '2023-10-21'),
(3, 1, 'k', 99.5, 'a', null, 1, 'yy', '2023-10-22'),
(3, 1, 'k', 99.5, 'a', null, 1, 'yy', '2023-10-22'),
(1, 3, 'o', 99.5, 'a', 'b', null, 'yy', '2023-10-19'),
(1, 3, 'o', 99.5, 'a', 'b', null, 'yy', '2023-10-19'),
(2, 1, 'o', 109.2, 'c','d',2, null, '2023-10-18'),
(2, 1, 'o', 109.2, 'c','d',2, null, '2023-10-18'),
(3, 2, 'k', 99.5, 'a', 'b', 1, 'yy', '2023-10-17'),
(3, 2, 'k', 99.5, 'a', 'b', 1, 'yy', '2023-10-17'),
(4, 5, 'k', 99.5, 'a', 'b', 1, 'yy', '2023-10-19');
"""

sql """
insert into lineitem_1 values
(null, 1, 2, 3, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-10-17', '2023-10-17', 'a', 'b', 'yyyyyyyyy', '2023-10-17'),
(null, 1, 2, 3, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-10-17', '2023-10-17', 'a', 'b', 'yyyyyyyyy', '2023-10-17'),
(1, 1, 3, 1, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-10-18', '2023-10-18', 'a', 'b', 'yyyyyyyyy', '2023-10-17'),
(3, 3, 3, 2, 7.5, 8.5, 9.5, 10.5, 'k', 'o', '2023-10-19', '2023-10-19', 'c', 'd', 'xxxxxxxxx', '2023-10-19'),
(3, 3, 3, 2, 7.5, 8.5, 9.5, 10.5, 'k', 'o', '2023-10-19', '2023-10-19', 'c', 'd', 'xxxxxxxxx', '2023-10-19'),
(1, 2, 3, 2, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-10-17', '2023-10-17', 'a', 'b', 'yyyyyyyyy', '2023-10-17'),
(2, 1, 2, 1, 5.5, 6.5, 7.5, 8.5, 'o', 'k', null, '2023-10-18', 'a', 'b', 'yyyyyyyyy', '2023-10-18'),
(2, 1, 2, 1, 5.5, 6.5, 7.5, 8.5, 'o', 'k', null, '2023-10-18', 'a', 'b', 'yyyyyyyyy', '2023-10-18'),
(3, 1, 3, 1, 7.5, 8.5, 9.5, 10.5, 'k', 'o', '2023-10-19', null, 'c', 'd', 'xxxxxxxxx', '2023-10-19'),
(1, 2, 1, 2, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-10-17', '2023-10-17', 'a', 'b', 'yyyyyyyyy', '2023-10-17'),
(2, 2, 2, 2, 5.5, 6.5, 7.5, 8.5, 'o', 'k', null, '2023-10-18', 'a', 'b', 'yyyyyyyyy', '2023-10-18'),
(3, 3, 3, 3, 7.5, 8.5, 9.5, 10.5, 'k', 'o', '2023-10-19', null, 'c', 'd', 'xxxxxxxxx', '2023-10-19'),
(3, 3, 3, 3, 7.5, 8.5, 9.5, 10.5, 'k', 'o', '2023-10-19', null, 'c', 'd', 'xxxxxxxxx', '2023-10-19'),
(1, 1, 1, 1, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-10-17', '2023-10-17', 'a', 'b', 'yyyyyyyyy', '2023-10-17');
"""

sql"""
insert into partsupp_1 values
(1, 1, 1, 99.5, 'yy'),
(1, 1, 1, 99.5, 'yy'),
(2, 2, 2, 109.2, 'mm'),
(2, 2, 2, 109.2, 'mm'),
(3, 3, 1, 99.5, 'yy'),
(3, 3, 1, 99.5, 'yy'),
(3, null, 1, 99.5, 'yy');
"""
Expand All @@ -132,9 +147,9 @@ suite("nested_mtmv") {
sql """analyze table lineitem_1 with sync;"""
sql """analyze table partsupp_1 with sync;"""

sql """alter table orders_1 modify column o_orderdate set stats ('row_count'='10');"""
sql """alter table lineitem_1 modify column l_shipdate set stats ('row_count'='10');"""
sql """alter table partsupp_1 modify column ps_comment set stats ('row_count'='4');"""
sql """alter table orders_1 modify column o_orderdate set stats ('row_count'='17');"""
sql """alter table lineitem_1 modify column l_shipdate set stats ('row_count'='14');"""
sql """alter table partsupp_1 modify column ps_comment set stats ('row_count'='7');"""

def compare_res = { def stmt ->
sql "SET enable_materialized_view_rewrite=false"
Expand Down Expand Up @@ -724,28 +739,16 @@ suite("nested_mtmv") {
group by t1.l_orderkey, t2.l_partkey, t1.l_suppkey, t2.o_orderkey, t1.o_custkey, t2.ps_partkey, t1.ps_suppkey, t2.agg1, t1.agg2, t2.agg3, t1.agg4, t2.agg5, t1.agg6
"""

explain {
sql("${sql_2}")
contains "${mv_2}(${mv_2})"
}
mv_rewrite_any_success(sql_2, [mv_1, mv_2])
compare_res(sql_2 + " order by 1,2,3,4,5,6,7,8,9,10,11,12,13")

explain {
sql("${sql_3}")
contains "${mv_3}(${mv_3})"
}
mv_rewrite_any_success(sql_3, [mv_3, mv_4])
compare_res(sql_3 + " order by 1,2,3,4,5,6,7,8,9,10,11,12,13")

explain {
sql("${sql_4}")
contains "${mv_4}(${mv_4})"
}
mv_rewrite_any_success(sql_4, [mv_3, mv_4])
compare_res(sql_4 + " order by 1,2,3,4,5,6,7,8,9,10,11,12,13")

explain {
sql("${sql_5}")
contains "${mv_5}(${mv_5})"
}
mv_rewrite_any_success(sql_5, [mv_3, mv_4, mv_5])
compare_res(sql_5 + " order by 1,2,3,4,5,6,7,8,9,10,11,12,13")

}

0 comments on commit dde9346

Please sign in to comment.