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(frontend): add stateless two-phase ApproxPercentile #17469

Merged
merged 33 commits into from
Jul 25, 2024

Conversation

kwannoel
Copy link
Contributor

@kwannoel kwannoel commented Jun 26, 2024

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

What's changed and what's your intention?

30% the changes in this PR are planner tests + binder tests

This is part of #17531.

We add stateless two-phase simple approx percentile, integrating it with gen_stateless_two_phase_streaming_agg_plan.

StreamLocalApproxPercentile is the local phase for approx_percentile.
StreamGlobalApproxPercentile is the global phase.

We do not implement a core for either of these, since the fields they use are different (global step does not require any parameters, local step requires the parameters). Further, there's also no logical plan node which corresponds to these stream nodes, so there's no need to add a core, it will just be overhead.

We also add KeyedMerge which will combine the results from approx percentile and normal aggs, as well as pair-wise approx percentiles.

  • Add stateless two-phase approx percentile.
  • Fix the keyed merge schema.
  • Handle multiple approx percentiles.
  • Fix distribution of global approx percentile.
  • Handle DESC approx percentile.
  • Planner tests

Subsequent PRs

  • Handle vnode based two-phase approx percentile.
  • Handle single phase approx percentile (embedded in expr framework).
  • Write local approx percentile agg.
  • Write global approx percentile agg.

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.

@kwannoel kwannoel force-pushed the kwannoel/approx-percentile-frontend branch 3 times, most recently from 6265b13 to c9270bf Compare July 19, 2024 08:19
@kwannoel kwannoel changed the title feat(frontend): add ApproxPercentile feat(frontend): add stateless two-phase ApproxPercentile Jul 22, 2024
@kwannoel kwannoel marked this pull request as ready for review July 22, 2024 14:30
@graphite-app graphite-app bot requested a review from a team July 22, 2024 14:55
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.

Generally LGTM

src/frontend/src/optimizer/plan_node/stream_keyed_merge.rs Outdated Show resolved Hide resolved
@kwannoel kwannoel force-pushed the kwannoel/approx-percentile-frontend branch from 2c0a899 to 2d76cae Compare July 24, 2024 03:03
@kwannoel kwannoel force-pushed the kwannoel/approx-percentile-frontend branch from 563269d to 1dd7c2b Compare July 24, 2024 06:08
@kwannoel
Copy link
Contributor Author

Any review from @stdrc @st1page ?

Copy link
Member

@stdrc stdrc left a comment

Choose a reason for hiding this comment

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

Rest LGTM

src/frontend/src/optimizer/plan_node/logical_agg.rs Outdated Show resolved Hide resolved
Comment on lines +322 to +334
fn build_approx_percentile_agg(
&self,
input: PlanRef,
approx_percentile_agg_call: &PlanAggCall,
) -> PlanRef {
let local_approx_percentile =
StreamLocalApproxPercentile::new(input, approx_percentile_agg_call);
let global_approx_percentile = StreamGlobalApproxPercentile::new(
local_approx_percentile.into(),
approx_percentile_agg_call,
);
global_approx_percentile.into()
}
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to unify ApproxPercentile executor with ApproxCountDistinct to have something like BucketBasedAgg? Just curious, not a suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I'm not sure about the internals of approx count distinct. Does it involve 2 phase agg?

Copy link
Member

Choose a reason for hiding this comment

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

No I mean is it possible to abstract a common executor like HashAgg that can do various kinds of aggregation that can fit into the framework. This seems not related to 2-phase agg, cuz HashAgg can be used in either local phase or global phase.

@kwannoel kwannoel added this pull request to the merge queue Jul 25, 2024
Merged via the queue into main with commit 6834de8 Jul 25, 2024
31 of 32 checks passed
@kwannoel kwannoel deleted the kwannoel/approx-percentile-frontend branch July 25, 2024 03:18
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.

4 participants