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

[vectorized](bug) fix window function can't handle first row of beyond #17084

Merged
merged 1 commit into from
Feb 28, 2023
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
4 changes: 2 additions & 2 deletions be/src/vec/aggregate_functions/aggregate_function_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ struct WindowFunctionFirstImpl : Data {
if (this->has_set_value()) {
return;
}
if (frame_start < frame_end &&
if (frame_start <= frame_end &&
frame_end <= partition_start) { //rewrite last_value when under partition
this->set_is_null(); //so no need more judge
return;
Expand All @@ -352,7 +352,7 @@ template <typename Data>
struct WindowFunctionLastImpl : Data {
void add_range_single_place(int64_t partition_start, int64_t partition_end, int64_t frame_start,
int64_t frame_end, const IColumn** columns) {
if ((frame_start < frame_end) &&
if ((frame_start <= frame_end) &&
((frame_end <= partition_start) ||
(frame_start >= partition_end))) { //beyond or under partition, set null
this->set_is_null();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,3 +625,13 @@ sales 4 4800 14600
10 30
11 21

-- !sql_window_last_value --
1 gz 30000 \N
2 gz 25000 30000
3 gz 17000 25000
4 gz 32000 17000
5 sz 40000 \N
6 sz 27000 40000
7 sz 27000 27000
8 sz 33000 27000

Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,43 @@ suite("test_window_fn") {

sql "DROP TABLE IF EXISTS ${tbName1};"
sql "DROP TABLE IF EXISTS ${tbName2};"

sql """ DROP TABLE IF EXISTS example_window_tb """
sql """
CREATE TABLE IF NOT EXISTS example_window_tb (
u_id int NULL COMMENT "",
u_city varchar(20) NULL COMMENT "",
u_salary int NULL COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(`u_id`, `u_city`, `u_salary`)
COMMENT ""
DISTRIBUTED BY HASH(`u_id`, `u_city`, `u_salary`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2"
);
"""

sql """
INSERT INTO example_window_tb(u_id, u_city, u_salary) VALUES
('1', 'gz', 30000),
('2', 'gz', 25000),
('3', 'gz', 17000),
('4', 'gz', 32000),
('5', 'sz', 40000),
('6', 'sz', 27000),
('7', 'sz', 27000),
('8', 'sz', 33000);
"""

qt_sql_window_last_value """
select u_id, u_city, u_salary,
last_value(u_salary) over (partition by u_city order by u_id rows between unbounded preceding and 1 preceding) last_value_test
from example_window_tb;
"""

sql "DROP TABLE IF EXISTS example_window_tb;"
}