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

refactor(over window): generalize WindowBuffer and window function AggregateState #14647

Merged
merged 6 commits into from
Feb 1, 2024

Conversation

stdrc
Copy link
Member

@stdrc stdrc commented Jan 18, 2024

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

This PR generalizes WindowBuffer and AggregateState so that window aggregation for calls with RANGE frames can be easily supported by just adding a new WindowImpl implementation.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

Comment on lines +252 to +276
buffer_ref.curr_idx < buffer_ref.buffer.len() && {
let start_off = self.frame_bounds.start.to_offset();
if let Some(start_off) = start_off {
if start_off >= 0 {
true // pure following frame, always preceding-saturated
} else {
// FIXME(rc): Clippy rule `clippy::nonminimal_bool` is misreporting that
// the following can be simplified.
#[allow(clippy::nonminimal_bool)]
{
assert!(buffer_ref.curr_idx >= buffer_ref.left_idx);
}
buffer_ref.curr_idx - buffer_ref.left_idx >= start_off.unsigned_abs()
}
} else {
false // unbounded frame start, never preceding-saturated
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Algorithm not changed, only moved

Comment on lines +273 to +298
buffer_ref.curr_idx < buffer_ref.buffer.len() && {
let end_off = self.frame_bounds.end.to_offset();
if let Some(end_off) = end_off {
if end_off <= 0 {
true // pure preceding frame, always following-saturated
} else {
// FIXME(rc): Ditto.
#[allow(clippy::nonminimal_bool)]
{
assert!(buffer_ref.right_excl_idx > 0);
assert!(buffer_ref.right_excl_idx > buffer_ref.curr_idx);
assert!(buffer_ref.right_excl_idx <= buffer_ref.buffer.len());
}
buffer_ref.right_excl_idx - 1 - buffer_ref.curr_idx >= end_off as usize
}
} else {
false // unbounded frame end, never following-saturated
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Algorithm not changed, only moved

Comment on lines +295 to +332
if buffer_ref.buffer.is_empty() {
*buffer_ref.left_idx = 0;
*buffer_ref.right_excl_idx = 0;
}

let start_off = self.frame_bounds.start.to_offset();
let end_off = self.frame_bounds.end.to_offset();
if let Some(start_off) = start_off {
let logical_left_idx = *buffer_ref.curr_idx as isize + start_off;
if logical_left_idx >= 0 {
*buffer_ref.left_idx =
std::cmp::min(logical_left_idx as usize, buffer_ref.buffer.len());
} else {
*buffer_ref.left_idx = 0;
}
} else {
// unbounded start
*buffer_ref.left_idx = 0;
}
if let Some(end_off) = end_off {
let logical_right_excl_idx = *buffer_ref.curr_idx as isize + end_off + 1;
if logical_right_excl_idx >= 0 {
*buffer_ref.right_excl_idx =
std::cmp::min(logical_right_excl_idx as usize, buffer_ref.buffer.len());
} else {
*buffer_ref.right_excl_idx = 0;
}
} else {
// unbounded end
*buffer_ref.right_excl_idx = buffer_ref.buffer.len();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Algorithm not changed, only moved

@stdrc stdrc force-pushed the rc/refactor-find-affected-ranges branch from 3181b68 to e2e4eb1 Compare January 18, 2024 09:55
@stdrc stdrc force-pushed the rc/generalize-window-buffer branch from 27c8004 to 980d29d Compare January 18, 2024 09:55
@stdrc stdrc force-pushed the rc/refactor-find-affected-ranges branch from e2e4eb1 to 5bd2c0e Compare January 19, 2024 05:23
@stdrc stdrc force-pushed the rc/generalize-window-buffer branch from 980d29d to dfe1a5b Compare January 19, 2024 05:24
@stdrc stdrc force-pushed the rc/refactor-find-affected-ranges branch from 5bd2c0e to 56ad72f Compare January 22, 2024 05:08
@stdrc stdrc force-pushed the rc/generalize-window-buffer branch from c25c28f to 8f5ed91 Compare January 22, 2024 05:08
@stdrc stdrc force-pushed the rc/refactor-find-affected-ranges branch from 56ad72f to 4b99ab1 Compare January 23, 2024 07:27
@stdrc stdrc force-pushed the rc/generalize-window-buffer branch from 8f5ed91 to d3eba36 Compare January 23, 2024 07:27
@stdrc stdrc force-pushed the rc/refactor-find-affected-ranges branch from 4b99ab1 to 6a55390 Compare January 24, 2024 08:09
@stdrc stdrc force-pushed the rc/generalize-window-buffer branch from d3eba36 to 9933c72 Compare January 24, 2024 08:09
@stdrc stdrc force-pushed the rc/refactor-find-affected-ranges branch from 6a55390 to d7cf817 Compare January 24, 2024 08:57
@stdrc stdrc force-pushed the rc/generalize-window-buffer branch 2 times, most recently from d23eeca to bd2ed75 Compare January 24, 2024 10:06
@stdrc stdrc force-pushed the rc/refactor-find-affected-ranges branch from 15fd42d to 9cd74ef Compare January 25, 2024 04:06
@stdrc stdrc force-pushed the rc/generalize-window-buffer branch from bd2ed75 to 16f5d06 Compare January 25, 2024 04:07
@stdrc stdrc force-pushed the rc/refactor-find-affected-ranges branch from 9cd74ef to 58054c8 Compare January 25, 2024 04:35
@stdrc stdrc force-pushed the rc/generalize-window-buffer branch from 16f5d06 to 58d9f5d Compare January 25, 2024 04:35
@stdrc stdrc force-pushed the rc/refactor-find-affected-ranges branch from 82b2728 to b5f5a39 Compare January 25, 2024 05:38
@stdrc stdrc force-pushed the rc/generalize-window-buffer branch from 58d9f5d to 8d89879 Compare January 25, 2024 05:38
@stdrc stdrc force-pushed the rc/refactor-find-affected-ranges branch from b5f5a39 to 9ae199f Compare January 29, 2024 07:19
@stdrc stdrc force-pushed the rc/generalize-window-buffer branch from 8d89879 to 21e2a86 Compare January 29, 2024 07:19
@stdrc stdrc force-pushed the rc/refactor-find-affected-ranges branch from a148e1c to b2653b5 Compare January 30, 2024 06:30
@stdrc stdrc force-pushed the rc/generalize-window-buffer branch from 21e2a86 to 12760a7 Compare January 30, 2024 06:30
@stdrc stdrc force-pushed the rc/refactor-find-affected-ranges branch 2 times, most recently from c002f15 to 9e8731e Compare January 31, 2024 05:52
@stdrc stdrc force-pushed the rc/generalize-window-buffer branch from 12760a7 to c44e1fe Compare January 31, 2024 05:53
Base automatically changed from rc/refactor-find-affected-ranges to main February 1, 2024 06:56
@stdrc stdrc force-pushed the rc/generalize-window-buffer branch from c44e1fe to 622719f Compare February 1, 2024 06:57
Copy link
Member

@fuyufjh fuyufjh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest LGTM. Most changes are restructuring.

stdrc added 6 commits February 1, 2024 16:03
Signed-off-by: Richard Chien <[email protected]>
Signed-off-by: Richard Chien <[email protected]>
Signed-off-by: Richard Chien <[email protected]>
Signed-off-by: Richard Chien <[email protected]>
@stdrc stdrc force-pushed the rc/generalize-window-buffer branch from 622719f to 86795a0 Compare February 1, 2024 08:15
@stdrc stdrc added this pull request to the merge queue Feb 1, 2024
Merged via the queue into main with commit 8481ea7 Feb 1, 2024
28 of 29 checks passed
@stdrc stdrc deleted the rc/generalize-window-buffer branch February 1, 2024 12:08
type Value: Clone;

/// Whether the preceding half of the current window is saturated.
/// By "saturated" we mean that every row that is possible to be in the preceding half of the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel confused from my understanding of the English word "saturated" 😕

How about "buffered", "loaded" or "cached"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can change the word later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants