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

Minor: add partial assertion for skip aggregation probe #12640

Merged
merged 6 commits into from
Sep 30, 2024

Conversation

Rachelint
Copy link
Contributor

Which issue does this PR close?

Closes #.

Rationale for this change

I found an partial assertion check may be needed in skip aggregation probe, this pr added it.
#12332 (comment)

What changes are included in this PR?

Add an assertion to ensure and emphasize that skip aggregation probe will only be called in partial aggregation.

Are these changes tested?

Test by exist tests.

Are there any user-facing changes?

No.

@github-actions github-actions bot added the physical-expr Physical Expressions label Sep 27, 2024
// Although currently spilling is actually not supported in Partial aggregation,
// it is possible to be supported in future, so we also add an assertion for it.
assert!(
self.mode == AggregateMode::Partial && self.spill_state.spills.is_empty()
Copy link
Contributor

@jayzhan211 jayzhan211 Sep 27, 2024

Choose a reason for hiding this comment

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

In partial mode, skip_aggregation_probe should be None, so mode check is not required

Copy link
Contributor Author

@Rachelint Rachelint Sep 27, 2024

Choose a reason for hiding this comment

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

Yes, these are two defensive assertions.

Copy link
Contributor Author

@Rachelint Rachelint Sep 27, 2024

Choose a reason for hiding this comment

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

I want to make that update_skip_aggregation_probe will be only called in partial more clear by someway.

Maybe we can just let the update_skip_aggregation_probe will only be called in partial?

if self.mode == AggregateMode::Partial {
    self.update_skip_aggregation_probe(input_rows);
}

And we make self.skip_aggregation_probe.as_mut().unwarp in update_skip_aggregation_probe?

Copy link
Contributor

@jayzhan211 jayzhan211 Sep 27, 2024

Choose a reason for hiding this comment

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

It looks good to me, and also we could do the same for other partial mode only like switch_to_skip_aggregation, should_skip_aggregation and emit_early_if_necessary

Copy link
Contributor

@jayzhan211 jayzhan211 Sep 27, 2024

Choose a reason for hiding this comment

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

We could even use pattern matching on mode, trade duplicated function call with a clearer code path for partial and non-partial mode

match self.mode {
    AggregateMode::Partial => {}
     _ => {} 
}

Copy link
Contributor Author

@Rachelint Rachelint Sep 28, 2024

Choose a reason for hiding this comment

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

It looks good to me, and also we could do the same for other partial mode only like switch_to_skip_aggregation, should_skip_aggregation and emit_early_if_necessary

It is really a good suggestion for readability.
I have tried to refactor the codes following the suggestion, I think it indeed clearer for me.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Looks like an improvement to me -- thank you @Rachelint

Let's see what @jayzhan211 thinks too

Some(Ok(batch)) => {
match (ready!(self.input.poll_next_unpin(cx)), self.mode) {
// New batch to aggregate in partial aggregation operator
(Some(Ok(batch)), AggregateMode::Partial) => {
Copy link
Contributor

@alamb alamb Sep 29, 2024

Choose a reason for hiding this comment

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

BTW another way to express this rather than matching on (.., self.mode) would be to use a match clause

like

Suggested change
(Some(Ok(batch)), AggregateMode::Partial) => {
Some(Ok(batch)) if self.mode == AggregateMode::Partial => {

That way you could avoid the other places which all match with (..., _)

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 nice, fixed.

Copy link
Contributor

@jayzhan211 jayzhan211 left a comment

Choose a reason for hiding this comment

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

👍

@jayzhan211 jayzhan211 merged commit f1aa27f into apache:main Sep 30, 2024
24 checks passed
@jayzhan211
Copy link
Contributor

Thanks @Rachelint @alamb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physical-expr Physical Expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants