Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

branch-2.1: [fix](nereids) fix ptopN push down under multi winexprs with partial forbidden type #44617 #44650

Closed
wants to merge 1 commit into from
Closed
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 @@ -218,20 +218,20 @@ && child(0).child(0) instanceof LogicalPartitionTopN)) {
for (NamedExpression windowExpr : windowExpressions) {
if (windowExpr == null || windowExpr.children().size() != 1
|| !(windowExpr.child(0) instanceof WindowExpression)) {
continue;
return null;
}
WindowExpression windowFunc = (WindowExpression) windowExpr.child(0);

// Check the window function name.
if (!(windowFunc.getFunction() instanceof RowNumber
|| windowFunc.getFunction() instanceof Rank
|| windowFunc.getFunction() instanceof DenseRank)) {
continue;
return null;
}

// Check the partition key and order key.
if (windowFunc.getPartitionKeys().isEmpty() && windowFunc.getOrderKeys().isEmpty()) {
continue;
return null;
}

// Check the window type and window frame.
Expand All @@ -240,10 +240,10 @@ && child(0).child(0) instanceof LogicalPartitionTopN)) {
WindowFrame frame = windowFrame.get();
if (!(frame.getLeftBoundary().getFrameBoundType() == WindowFrame.FrameBoundType.UNBOUNDED_PRECEDING
&& frame.getRightBoundary().getFrameBoundType() == WindowFrame.FrameBoundType.CURRENT_ROW)) {
continue;
return null;
}
} else {
continue;
return null;
}

// Check filter conditions.
Expand Down
6 changes: 6 additions & 0 deletions regression-test/data/nereids_syntax_p0/window_function.out
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,9 @@
\N
\N

-- !multi_winf1 --
1 c

-- !multi_winf2 --
1 35

Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,24 @@ suite("push_down_multi_filter_through_window") {
sql ("select * from (select row_number() over(partition by c1, c2 order by c3) as rn, rank() over(partition by c1 order by c3) as rk from push_down_multi_predicate_through_window_t) t where rn <= 1 or rk <= 1;")
notContains "VPartitionTopN"
}

explain {
sql ("select * from (select row_number() over(partition by c1, c2 order by c3) as rn, sum(c2) over(order by c2 range between unbounded preceding and unbounded following) as sw from push_down_multi_predicate_through_window_t) t where rn <= 1 and sw <= 1;")
notContains "VPartitionTopN"
}

explain {
sql ("select * from (select sum(c2) over(order by c2 range between unbounded preceding and unbounded following) as sw, row_number() over(partition by c1, c2 order by c3) as rn from push_down_multi_predicate_through_window_t) t where rn <= 1 and sw <= 1;")
notContains "VPartitionTopN"
}

explain {
sql ("select * from (select row_number() over(partition by c1, c2 order by c3 rows between unbounded preceding and current row) as rn, sum(c2) over(order by c2) as sw from push_down_multi_predicate_through_window_t) t where rn <= 1 and sw <= 1;")
notContains "VPartitionTopN"
}

explain {
sql ("select * from (select sum(c2) over(order by c2) as sw, row_number() over(partition by c1, c2 order by c3 rows between unbounded preceding and current row) as rn from push_down_multi_predicate_through_window_t) t where rn <= 1 and sw <= 1;")
notContains "VPartitionTopN"
}
}
39 changes: 39 additions & 0 deletions regression-test/suites/nereids_syntax_p0/window_function.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,43 @@ suite("window_function") {
"""

qt_sql """ select LAST_VALUE(col_tinyint_undef_signed_not_null) over (partition by col_double_undef_signed_not_null, col_int_undef_signed, (col_float_undef_signed_not_null - col_int_undef_signed), round_bankers(col_int_undef_signed) order by pk rows between unbounded preceding and 4 preceding) AS col_alias56089 from table_200_undef_partitions2_keys3_properties4_distributed_by53 order by col_alias56089; """

order_qt_multi_winf1 """
select *
from (
select
row_number() over(partition by c1 order by c2) rn,
lead(c2, 2, '') over(partition by c1 order by c2)
from (
select 1 as c1, 'a' as c2
union all
select 1 as c1, 'b' as c2
union all
select 1 as c1, 'c' as c2
union all
select 1 as c1, 'd' as c2
union all
select 1 as c1, 'e' as c2
)t
)a where rn=1
"""
order_qt_multi_winf2 """
select *
from (
select
row_number() over(partition by c1 order by c2) rn,
sum(c2) over(order by c2 range between unbounded preceding and unbounded following)
from (
select 1 as c1, 5 as c2
union all
select 1 as c1, 6 as c2
union all
select 1 as c1, 7 as c2
union all
select 1 as c1, 8 as c2
union all
select 1 as c1, 9 as c2
)t
)a where rn=1
"""
}
Loading