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: split match arms in prom_expr_to_plan into smaller methods #4317

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

waynexia
Copy link
Member

@waynexia waynexia commented Jul 8, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

What's changed and what's your intention?

No logic changes. Breakdown prom_expr_to_plan into several small functions.

Stack size in debug mode after this patch:

Link to the issue for the third time 😣 : rust-lang/rust#34283

Summary by CodeRabbit

  • Refactor
    • Improved performance and code organization for PromQL query planning by restructuring logic into separate async functions.

@waynexia waynexia requested a review from evenyag as a code owner July 8, 2024 11:37
Copy link
Contributor

coderabbitai bot commented Jul 8, 2024

Walkthrough

The promql/planner.rs file has been significantly refactored to improve code organization and maintainability. This refactoring involves breaking down the PromPlanner implementation into multiple async functions, each handling different types of PromQL expressions such as Aggregate, Unary, Binary, Paren, and Subquery. These changes help separate concerns and enhance readability.

Changes

Files Change Summary
.../promql/planner.rs Refactored PromPlanner by adding several async functions to handle different PromQL expressions.

Poem

In the realm of Prometheus' plan,
A rabbit spun his clever hands,
Async functions now do stand,
PromQL's logic finely spanned.
Code's clearer than ever before,
PromPlanner's now hard to ignore! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Jul 8, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c0e9b3d and 1f68d6e.

Files selected for processing (1)
  • src/query/src/promql/planner.rs (1 hunks)
Additional comments not posted (10)
src/query/src/promql/planner.rs (10)

172-174: Verify delegation to new functions.

The prom_expr_to_plan function correctly delegates to the new functions for handling specific PromQL expressions. Ensure that all new functions (prom_aggr_expr_to_plan, prom_unary_expr_to_plan, etc.) are implemented correctly and integrated properly.

Also applies to: 182-193


196-230: Ensure correct processing of aggregate expressions.

The prom_aggr_expr_to_plan function correctly processes the components of the aggregate expression and builds a logical plan. Verify that the group expressions and aggregate expressions are handled correctly, and the plan is built as expected.


232-243: Ensure correct processing of unary expressions.

The prom_unary_expr_to_plan function correctly processes the unary expression and builds a logical plan with the - operator. Verify that the function handles the - operator as expected and integrates correctly with the overall plan.


245-445: Ensure correct processing of binary expressions.

The prom_binary_expr_to_plan function correctly processes the components of the binary expression and builds a logical plan. Verify that the function handles literals, columns, and binary operators as expected, and integrates correctly with the overall plan.


448-469: Ensure correct processing of number literals.

The prom_number_lit_to_plan function correctly processes the number literal and builds a logical plan with the literal expression. Verify that the function handles the literal expression as expected and integrates correctly with the overall plan.


471-492: Ensure correct processing of string literals.

The prom_string_lit_to_plan function correctly processes the string literal and builds a logical plan with the literal expression. Verify that the function handles the literal expression as expected and integrates correctly with the overall plan.


494-524: Ensure correct processing of vector selectors.

The prom_vector_selector_to_plan function correctly processes the vector selector components and builds a logical plan. Verify that the function handles matchers, normalization, and manipulation as expected, and integrates correctly with the overall plan.


526-565: Ensure correct processing of matrix selectors.

The prom_matrix_selector_to_plan function correctly processes the matrix selector components and builds a logical plan. Verify that the function handles vector selectors, normalization, and manipulation as expected, and integrates correctly with the overall plan.


567-615: Ensure correct processing of function calls.

The prom_call_expr_to_plan function correctly processes the function call components and builds a logical plan. Verify that the function handles special functions and function arguments as expected, and integrates correctly with the overall plan.


617-657: Ensure correct processing of extension expressions.

The prom_ext_expr_to_plan function correctly processes the extension expression components and builds a logical plan. Verify that the function handles explain and analyze operations as expected, and integrates correctly with the overall plan.

Copy link

codecov bot commented Jul 8, 2024

Codecov Report

Attention: Patch coverage is 72.25131% with 106 lines in your changes missing coverage. Please review.

Project coverage is 84.85%. Comparing base (59afa70) to head (1f68d6e).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4317      +/-   ##
==========================================
- Coverage   85.13%   84.85%   -0.29%     
==========================================
  Files        1060     1060              
  Lines      187669   187648      -21     
==========================================
- Hits       159777   159226     -551     
- Misses      27892    28422     +530     

@WenyXu
Copy link
Member

WenyXu commented Jul 8, 2024

It works on my machine🤩
Before

Function: query::promql::planner::{impl#1}::prom_expr_to_plan::{async_block#0}, Stack Size: 148304
Function: core::future::future::{impl#1}::poll<alloc::boxed::Box<(dyn core::future::future::Future<Output=core::result::Result<datafusion_expr::logical_plan::plan::LogicalPlan, query::promql::error::Error>> + core::marker::Send), alloc::alloc::Global>>, Stack Size: 96
Function: query::promql::planner::{impl#1}::prom_expr_to_plan::{async_block#0}, Stack Size: 148304
Function: core::future::future::{impl#1}::poll<alloc::boxed::Box<(dyn core::future::future::Future<Output=core::result::Result<datafusion_expr::logical_plan::plan::LogicalPlan, query::promql::error::Error>> + core::marker::Send), alloc::alloc::Global>>, Stack Size: 96
Function: query::promql::planner::{impl#1}::prom_expr_to_plan::{async_block#0}, Stack Size: 148304
Function: core::future::future::{impl#1}::poll<alloc::boxed::Box<(dyn core::future::future::Future<Output=core::result::Result<datafusion_expr::logical_plan::plan::LogicalPlan, query::promql::error::Error>> + core::marker::Send), alloc::alloc::Global>>, Stack Size: 96
Function: query::promql::planner::{impl#1}::prom_expr_to_plan::{async_block#0}, Stack Size: 148304
Function: core::future::future::{impl#1}::poll<alloc::boxed::Box<(dyn core::future::future::Future<Output=core::result::Result<datafusion_expr::logical_plan::plan::LogicalPlan, query::promql::error::Error>> + core::marker::Send), alloc::alloc::Global>>, Stack Size: 96
Function: query::promql::planner::{impl#1}::prom_expr_to_plan::{async_block#0}, Stack Size: 148304
Function: core::future::future::{impl#1}::poll<alloc::boxed::Box<(dyn core::future::future::Future<Output=core::result::Result<datafusion_expr::logical_plan::plan::LogicalPlan, query::promql::error::Error>> + core::marker::Send), alloc::alloc::Global>>, Stack Size: 96
Function: query::promql::planner::{impl#1}::prom_expr_to_plan::{async_block#0}, Stack Size: 148304
Function: core::future::future::{impl#1}::poll<alloc::boxed::Box<(dyn core::future::future::Future<Output=core::result::Result<datafusion_expr::logical_plan::plan::LogicalPlan, query::promql::error::Error>> + core::marker::Send), alloc::alloc::Global>>, Stack Size: 96
Function: query::promql::planner::{impl#1}::prom_expr_to_plan::{async_block#0}, Stack Size: 148304
Function: core::future::future::{impl#1}::poll<alloc::boxed::Box<(dyn core::future::future::Future<Output=core::result::Result<datafusion_expr::logical_plan::plan::LogicalPlan, query::promql::error::Error>> + core::marker::Send), alloc::alloc::Global>>, Stack Size: 96
Function: query::promql::planner::{impl#1}::stmt_to_plan::{async_fn#0}, Stack Size: 1760

After this PR:

Function: query::promql::planner::{impl#1}::prom_expr_to_plan::{async_block#0}, Stack Size: 37552, i: 17
Function: core::future::future::{impl#1}::poll<alloc::boxed::Box<(dyn core::future::future::Future<Output=core::result::Result<datafusion_expr::logical_plan::plan::LogicalPlan, query::promql::error::Error>> + core::marker::Send), alloc::alloc::Global>>, Stack Size: 96, i: 18
Function: query::promql::planner::{impl#1}::prom_call_expr_to_plan::{async_fn#0}, Stack Size: 21488, i: 19
Function: query::promql::planner::{impl#1}::prom_expr_to_plan::{async_block#0}, Stack Size: 37552, i: 20
Function: core::future::future::{impl#1}::poll<alloc::boxed::Box<(dyn core::future::future::Future<Output=core::result::Result<datafusion_expr::logical_plan::plan::LogicalPlan, query::promql::error::Error>> + core::marker::Send), alloc::alloc::Global>>, Stack Size: 96, i: 21
Function: query::promql::planner::{impl#1}::prom_aggr_expr_to_plan::{async_fn#0}, Stack Size: 11952, i: 22
Function: query::promql::planner::{impl#1}::prom_expr_to_plan::{async_block#0}, Stack Size: 37552, i: 23
Function: core::future::future::{impl#1}::poll<alloc::boxed::Box<(dyn core::future::future::Future<Output=core::result::Result<datafusion_expr::logical_plan::plan::LogicalPlan, query::promql::error::Error>> + core::marker::Send), alloc::alloc::Global>>, Stack Size: 96, i: 24
Function: query::promql::planner::{impl#1}::prom_binary_expr_to_plan::{async_fn#0}, Stack Size: 31360, i: 25
Function: query::promql::planner::{impl#1}::prom_expr_to_plan::{async_block#0}, Stack Size: 37552, i: 26
Function: core::future::future::{impl#1}::poll<alloc::boxed::Box<(dyn core::future::future::Future<Output=core::result::Result<datafusion_expr::logical_plan::plan::LogicalPlan, query::promql::error::Error>> + core::marker::Send), alloc::alloc::Global>>, Stack Size: 96, i: 27
Function: query::promql::planner::{impl#1}::prom_expr_to_plan::{async_block#0}, Stack Size: 37552, i: 28
Function: core::future::future::{impl#1}::poll<alloc::boxed::Box<(dyn core::future::future::Future<Output=core::result::Result<datafusion_expr::logical_plan::plan::LogicalPlan, query::promql::error::Error>> + core::marker::Send), alloc::alloc::Global>>, Stack Size: 96, i: 29
Function: query::promql::planner::{impl#1}::prom_binary_expr_to_plan::{async_fn#0}, Stack Size: 31360, i: 30
Function: query::promql::planner::{impl#1}::prom_expr_to_plan::{async_block#0}, Stack Size: 37552, i: 31
Function: core::future::future::{impl#1}::poll<alloc::boxed::Box<(dyn core::future::future::Future<Output=core::result::Result<datafusion_expr::logical_plan::plan::LogicalPlan, query::promql::error::Error>> + core::marker::Send), alloc::alloc::Global>>, Stack Size: 96, i: 32
Function: query::promql::planner::{impl#1}::stmt_to_plan::{async_fn#0}, Stack Size: 1760, i: 33

@WenyXu WenyXu requested a review from v0y4g3r July 8, 2024 11:57
Copy link
Contributor

@v0y4g3r v0y4g3r left a comment

Choose a reason for hiding this comment

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

LGTM

@WenyXu WenyXu added this pull request to the merge queue Jul 8, 2024
@waynexia waynexia requested a review from discord9 July 8, 2024 12:01
Copy link
Contributor

@discord9 discord9 left a comment

Choose a reason for hiding this comment

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

DLJB

Merged via the queue into GreptimeTeam:main with commit e5730a3 Jul 8, 2024
58 checks passed
@waynexia waynexia deleted the breakdown-match-arms branch July 8, 2024 12:15
@waynexia
Copy link
Member Author

waynexia commented Jul 8, 2024

The script to compute stack size: https://wiki.waynest.com/#/page/gdb%20compute%20stack%20size

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required This change does not impact docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants