Skip to content

Commit

Permalink
[fix](window function) Fix illegal frame range
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel39 committed Sep 23, 2024
1 parent f57dc92 commit a518503
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 4 deletions.
4 changes: 3 additions & 1 deletion be/src/pipeline/exec/analytic_source_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,16 @@ Status AnalyticLocalState::_get_next_for_rows(size_t current_block_rows) {
1; //going on calculate,add up data, no need to reset state
} else {
_reset_agg_status();
range_end = _shared_state->current_row_position + _rows_end_offset + 1;
if (!_parent->cast<AnalyticSourceOperatorX>()
._window.__isset
.window_start) { //[preceding, offset] --unbound: [preceding, following]
range_start = _partition_by_start.pos;
} else {
range_start = _shared_state->current_row_position + _rows_start_offset;
}
range_end = _shared_state->current_row_position + _rows_end_offset + 1;
// Make sure range_start <= range_end
range_start = std::min(range_start, range_end);
}
_executor.execute(_partition_by_start.pos, _shared_state->partition_by_end.pos, range_start,
range_end);
Expand Down
6 changes: 3 additions & 3 deletions be/src/vec/aggregate_functions/aggregate_function_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,9 @@ template <typename Data, bool arg_ignore_null = false>
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) &&
((frame_end <= partition_start) ||
(frame_start >= partition_end))) { //beyond or under partition, set null
DCHECK_LE(frame_start, frame_end);
if ((frame_end <= partition_start) ||
(frame_start >= partition_end)) { //beyond or under partition, set null
this->set_is_null();
return;
}
Expand Down
202 changes: 202 additions & 0 deletions regression-test/data/nereids_syntax_p0/window_function.out
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,205 @@
1.0
1.5

-- !sql --
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N

39 changes: 39 additions & 0 deletions regression-test/suites/nereids_syntax_p0/window_function.groovy

Large diffs are not rendered by default.

0 comments on commit a518503

Please sign in to comment.