Skip to content

Commit

Permalink
fix regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
seawinde committed Jul 26, 2024
1 parent e7daa9b commit c0d00e1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,8 @@ private boolean isGroupByEquals(Pair<Plan, LogicalAggregate<Plan>> queryTopPlanA
LogicalAggregate<Plan> queryAggregate = queryTopPlanAndAggPair.value();
LogicalAggregate<Plan> viewAggregate = viewTopPlanAndAggPair.value();

Set<Expression> queryGroupShuttledExpression = new HashSet<>();
for (Expression queryExpression : ExpressionUtils.shuttleExpressionWithLineage(
queryAggregate.getGroupByExpressions(), queryTopPlan, queryStructInfo.getTableBitSet())) {
queryGroupShuttledExpression.add(queryExpression);
}
Set<Expression> queryGroupShuttledExpression = new HashSet<>(ExpressionUtils.shuttleExpressionWithLineage(
queryAggregate.getGroupByExpressions(), queryTopPlan, queryStructInfo.getTableBitSet()));

// try to eliminate group by dimension by function dependency if group by expression is not in query
Map<Expression, Expression> viewShuttledExpressionQueryBasedToGroupByExpressionMap = new HashMap<>();
Expand All @@ -363,7 +360,7 @@ private boolean isGroupByEquals(Pair<Plan, LogicalAggregate<Plan>> queryTopPlanA
viewGroupExpressionQueryBased
);
}
if (queryGroupShuttledExpression.equals(viewShuttledExpressionQueryBasedToGroupByExpressionMap.values())) {
if (queryGroupShuttledExpression.equals(viewShuttledExpressionQueryBasedToGroupByExpressionMap.keySet())) {
// return true, if equals directly
return true;
}
Expand All @@ -378,7 +375,7 @@ private boolean isGroupByEquals(Pair<Plan, LogicalAggregate<Plan>> queryTopPlanA
// check is equals by equal filter eliminate
Optional<LogicalFilter<Plan>> filterOptional = tempRewrittenPlan.collectFirst(LogicalFilter.class::isInstance);
if (!filterOptional.isPresent()) {
return false;
return isGroupByEquals;
}
isGroupByEquals |= isGroupByEqualsAfterEqualFilterEliminate(
(LogicalPlan) tempRewrittenPlan,
Expand Down Expand Up @@ -409,6 +406,7 @@ private static boolean isGroupByEqualsAfterEqualFilterEliminate(
return false;
}
Set<Expression> viewShouldUniformExpressionSet = new HashSet<>();
// calc the group by expr which is needed to roll up and should be uniform
for (Map.Entry<Expression, Expression> expressionEntry :
viewShuttledExprQueryBasedToViewGroupByExprMap.entrySet()) {
if (queryGroupShuttledExpression.contains(expressionEntry.getKey())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ PhysicalResultSink
yy 11.50 11.50 11.50 1

-- !query3_1_before --
mi 56.20 56.20 56.20 1

-- !shape3_1_after --
PhysicalResultSink
--hashAgg[GLOBAL]
----hashAgg[LOCAL]
------filter((cast(o_shippriority as DOUBLE) = cast('a' as DOUBLE)) and (orders.o_orderdate = '2023-12-09') and (orders.o_totalprice = 11.50))
------filter((orders.o_orderdate = '2023-12-12') and (orders.o_shippriority = 2) and (orders.o_totalprice = 56.20))
--------PhysicalOlapScan[orders]

-- !query3_1_after --
mi 56.20 56.20 56.20 1

-- !query4_0_before --
yy 11.50 11.50 11.50 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ suite("agg_optimize_when_uniform") {
min(o_totalprice),
count(*)
from orders
where o_orderdate = '2023-12-09' and o_shippriority = 'a' and o_totalprice = 11.5
where o_orderdate = '2023-12-12' and o_shippriority = 2 and o_totalprice = 56.2
group by
o_comment;
"""
Expand Down Expand Up @@ -290,7 +290,7 @@ suite("agg_optimize_when_uniform") {
"""
order_qt_query4_0_before "${query4_0}"
// query success but add agg
check_mv_rewrite_successs_without_check_chosen(db, mv4_0, query4_0, "mv4_0")
check_mv_rewrite_success_without_check_chosen(db, mv4_0, query4_0, "mv4_0")
qt_shape4_0_after """explain shape plan ${query4_0}"""
order_qt_query4_0_after "${query4_0}"
sql """ DROP MATERIALIZED VIEW IF EXISTS mv4_0"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ suite("aggregate_without_roll_up") {
min(o_totalprice),
count(*)
from orders
where o_shippriority in (1, 2
where o_shippriority in (1, 2)
group by
o_shippriority,
o_comment;
Expand Down Expand Up @@ -247,27 +247,29 @@ suite("aggregate_without_roll_up") {
"group by " +
"O_SHIPPRIORITY, " +
"O_COMMENT "
def query1_2 = "select O_SHIPPRIORITY, O_COMMENT, " +
"count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (1, 3) then O_ORDERSTATUS else null end) as filter_cnt_1, " +
"count(distinct case when O_SHIPPRIORITY > 2 and O_ORDERKEY IN (2) then O_ORDERSTATUS else null end) as filter_cnt_2, " +
"count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (3, 4) then O_ORDERSTATUS else null end) as filter_cnt_3, " +
"count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (2, 3) then O_ORDERSTATUS else null end) as filter_cnt_5, " +
"count(distinct case when O_SHIPPRIORITY > 2 and O_ORDERKEY IN (7, 9) then O_ORDERSTATUS else null end) as filter_cnt_6, " +
"count(distinct case when O_SHIPPRIORITY > 4 and O_ORDERKEY IN (11, 13) then O_ORDERSTATUS else null end) as filter_cnt_8, " +
"count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (12, 11) then O_ORDERSTATUS else null end) as filter_cnt_9, " +
"count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (11, 12) then O_ORDERSTATUS else null end) as filter_cnt_11, " +
"count(distinct case when O_SHIPPRIORITY > 4 and O_ORDERKEY IN (3, 6) then O_ORDERSTATUS else null end) as filter_cnt_12, " +
"count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (16, 19) then O_ORDERSTATUS else null end) as filter_cnt_13, " +
"count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (15, 19) then O_ORDERSTATUS else null end) as filter_cnt_15, " +
"count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (13, 21) then O_ORDERSTATUS else null end) as filter_cnt_16, " +
"count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (16, 25) then O_ORDERSTATUS else null end) as filter_cnt_18, " +
"count(distinct case when O_SHIPPRIORITY > 4 and O_ORDERKEY IN (19, 3) then O_ORDERSTATUS else null end) as filter_cnt_19, " +
"count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (1, 20) then O_ORDERSTATUS else null end) as filter_cnt_20 " +
"from orders " +
"where O_ORDERDATE < '2023-12-30' and O_ORDERDATE > '2023-12-01'" +
"group by " +
"O_SHIPPRIORITY, " +
"O_COMMENT "
def query1_2 = """
select O_SHIPPRIORITY, O_COMMENT,
count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (1, 3) then O_ORDERSTATUS else null end) as filter_cnt_1,
count(distinct case when O_SHIPPRIORITY > 2 and O_ORDERKEY IN (2) then O_ORDERSTATUS else null end) as filter_cnt_2,
count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (3, 4) then O_ORDERSTATUS else null end) as filter_cnt_3,
count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (2, 3) then O_ORDERSTATUS else null end) as filter_cnt_5,
count(distinct case when O_SHIPPRIORITY > 2 and O_ORDERKEY IN (7, 9) then O_ORDERSTATUS else null end) as filter_cnt_6,
count(distinct case when O_SHIPPRIORITY > 4 and O_ORDERKEY IN (11, 13) then O_ORDERSTATUS else null end) as filter_cnt_8,
count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (12, 11) then O_ORDERSTATUS else null end) as filter_cnt_9,
count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (11, 12) then O_ORDERSTATUS else null end) as filter_cnt_11,
count(distinct case when O_SHIPPRIORITY > 4 and O_ORDERKEY IN (3, 6) then O_ORDERSTATUS else null end) as filter_cnt_12,
count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (16, 19) then O_ORDERSTATUS else null end) as filter_cnt_13,
count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (15, 19) then O_ORDERSTATUS else null end) as filter_cnt_15,
count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (13, 21) then O_ORDERSTATUS else null end) as filter_cnt_16,
count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (16, 25) then O_ORDERSTATUS else null end) as filter_cnt_18,
count(distinct case when O_SHIPPRIORITY > 4 and O_ORDERKEY IN (19, 3) then O_ORDERSTATUS else null end) as filter_cnt_19,
count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (1, 20) then O_ORDERSTATUS else null end) as filter_cnt_20
from orders
where O_ORDERDATE < '2023-12-30' and O_ORDERDATE > '2023-12-01'
group by
O_SHIPPRIORITY,
O_COMMENT;
"""
order_qt_query1_2_before "${query1_2}"
check_mv_rewrite_success(db, mv1_2, query1_2, "mv1_2")
order_qt_query1_2_after "${query1_2}"
Expand Down

0 comments on commit c0d00e1

Please sign in to comment.