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

feat(stream,over-window): implement AggregateState to allow aggregate function over window #9248

Merged
merged 16 commits into from Apr 21, 2023

Conversation

stdrc
Copy link
Contributor

@stdrc stdrc commented Apr 18, 2023

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

What's changed and what's your intention?

This PR

  • Adds a common WindowBuffer structure to maintain buffered entries for a window frame.
  • Implements AggregateState which is a WindowState to support aggregate function over window.

Checklist For Contributors

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • [ ] I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • I have demonstrated that backward compatibility is not broken by breaking changes and created issues to track deprecated features to be removed in the future. (Please refer to the issue)
  • All checks passed in ./risedev check (or alias, ./risedev c)

Checklist For Reviewers

  • I have requested macro/micro-benchmarks as this PR can affect performance substantially, and the results are shown.

Documentation

  • My PR DOES NOT contain user-facing changes.
Click here for Documentation

Types of user-facing changes

Please keep the types that apply to your changes, and remove the others.

  • Installation and deployment
  • Connector (sources & sinks)
  • SQL commands, functions, and operators
  • RisingWave cluster configuration changes
  • Other (please specify in the release note below)

Release note

@mergify

This comment was marked as outdated.

@stdrc stdrc closed this Apr 18, 2023
@stdrc stdrc force-pushed the rc/aggregate-window-state branch from 7dad266 to be50b16 Compare April 18, 2023 08:09
@stdrc stdrc reopened this Apr 18, 2023
Base automatically changed from rc/unify-batch-stream-agg-call to main April 18, 2023 08:22
@stdrc stdrc force-pushed the rc/aggregate-window-state branch from 54e388d to 203f729 Compare April 18, 2023 08:22
@stdrc stdrc changed the title feat(stream,over-window): implement AggregateState to allow aggregate over window feat(stream,over-window): implement AggregateState to allow aggregate function over window Apr 18, 2023
Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
@stdrc stdrc force-pushed the rc/aggregate-window-state branch from 773aa63 to 9818593 Compare April 19, 2023 05:25
Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
@stdrc stdrc marked this pull request as ready for review April 19, 2023 05:55
Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
@codecov
Copy link

codecov bot commented Apr 19, 2023

Codecov Report

Merging #9248 (155fd98) into main (3fe8bd4) will increase coverage by 0.05%.
The diff coverage is 96.38%.

@@            Coverage Diff             @@
##             main    #9248      +/-   ##
==========================================
+ Coverage   70.79%   70.85%   +0.05%     
==========================================
  Files        1216     1218       +2     
  Lines      202120   202616     +496     
==========================================
+ Hits       143089   143560     +471     
- Misses      59031    59056      +25     
Flag Coverage Δ
rust 70.85% <96.38%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/expr/src/function/window/kind.rs 100.00% <ø> (ø)
src/expr/src/function/window/call.rs 70.00% <69.23%> (-30.00%) ⬇️
...stream/src/executor/over_window/state/aggregate.rs 96.51% <96.51%> (ø)
...rc/stream/src/executor/over_window/state/buffer.rs 98.83% <98.83%> (ø)
src/stream/src/executor/over_window/mod.rs 95.91% <100.00%> (+0.55%) ⬆️
src/stream/src/executor/over_window/partition.rs 95.45% <100.00%> (ø)
src/stream/src/executor/over_window/state/lag.rs 100.00% <100.00%> (ø)
src/stream/src/executor/over_window/state/lead.rs 100.00% <100.00%> (ø)
src/stream/src/executor/over_window/state/mod.rs 74.35% <100.00%> (+2.13%) ⬆️

... and 6 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

assert!(start_off <= end_off);
}
if end_off <= 0 {
0
Copy link
Contributor

Choose a reason for hiding this comment

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

should it be LEFT_IDX here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems to have bug here, let me add some unit tests later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed a bug related to index maintaining, PTAL

@@ -363,7 +362,9 @@ impl<S: StateStore> OverWindowExecutor<S> {
let (ret_values, evict_hints): (Vec<_>, Vec<_>) = partition
.states
.iter_mut()
.map(|state| state.slide())
.map(|state| state.output())
.try_collect::<Vec<_>>()?
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the point of returning an error early here when .map(|o| (o.return_value, o.evict_hint)) has no side effects?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because batch aggregator will possibly throw an error

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree, but the collect is unnecessary if we have rust-itertools/itertools#402

We can resolve it later :)

buffer: VecDeque<BufferEntry>,
curr_idx: usize,
}

impl LagState {
pub fn new(frame: &Frame) -> Self {
let offset = must_match!(frame, Frame::Offset(offset) if *offset < 0 => -offset as usize);
let offset = must_match!(frame, Frame::Rows(FrameBound::Preceding(offset), FrameBound::CurrentRow) => *offset);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the difference between our must_match and assert_matches?

Copy link
Contributor Author

@stdrc stdrc Apr 20, 2023

Choose a reason for hiding this comment

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

Looks the same😄, will change to assert_matches.

Copy link
Collaborator

@TennyZhuang TennyZhuang left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@soundOfDestiny soundOfDestiny left a comment

Choose a reason for hiding this comment

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

👍

Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
@stdrc stdrc enabled auto-merge April 21, 2023 09:32
@stdrc stdrc added this pull request to the merge queue Apr 21, 2023
Merged via the queue into main with commit 64aa26d Apr 21, 2023
30 checks passed
@stdrc stdrc deleted the rc/aggregate-window-state branch April 21, 2023 10:16
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.

None yet

4 participants