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: validate partition rule on create table #4213

Merged
merged 1 commit into from
Jun 25, 2024

Conversation

waynexia
Copy link
Member

@waynexia waynexia commented Jun 25, 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?

Validate partition rule on CREATE TABLE

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.

Summary by CodeRabbit

  • New Features

    • Improved error handling with a new InvalidPartition error variant, providing more specific error messages for invalid partition rules.
  • Bug Fixes

    • Enhanced validation for partition rules, ensuring errors are correctly flagged when rules are improperly defined.
  • Refactor

    • Streamlined method signatures for partition rule checking, simplifying the code and improving maintainability.
  • Tests

    • Added tests to check for appropriate error handling when creating tables with invalid partition rules.

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
@waynexia waynexia requested a review from a team as a code owner June 25, 2024 12:40
Copy link
Contributor

coderabbitai bot commented Jun 25, 2024

Walkthrough

The changes across the files focus on enhancing error handling and partitioning logic within the system. Key modifications include adding a new InvalidPartition error variant, improving the MultiDimPartitionRule implementation, and expanding test cases to cover invalid partition rules. These updates aim to make the system more robust and informative when dealing with partition-related errors.

Changes

Files Change Summary
src/operator/src/error.rs Added InvalidPartition variant with associated fields and updated ErrorExt for handling it.
src/operator/src/statement/ddl.rs Renamed InvalidPartitionRuleSnafu to InvalidPartitionSnafu and added MultiDimPartitionRule.
src/partition/src/multi_dim.rs Refactored check method in RuleChecker struct to use instance variables directly.
tests/cases/standalone/common/partition.sql Introduced invalid partition rule resulting in error for incorrect partition conditions.
tests/cases/standalone/common/partition.result Reflected changes in error output for invalid partition rule with specific error messages.

Sequence Diagram(s)

(Omitted; the changes don't significantly alter control flow functionality.)

Poem

Partitions tall, partitions wide,
New rules and checks now on our side,
Errors caught with greater might,
Ensuring data stays just right.
A journey through our every query,
Ends in results accurate, not dreary.
🌟📝


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 Jun 25, 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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8cbe716 and e17b36c.

Files selected for processing (5)
  • src/operator/src/error.rs (2 hunks)
  • src/operator/src/statement/ddl.rs (4 hunks)
  • src/partition/src/multi_dim.rs (2 hunks)
  • tests/cases/standalone/common/partition.result (1 hunks)
  • tests/cases/standalone/common/partition.sql (1 hunks)
Additional comments not posted (6)
tests/cases/standalone/common/partition.sql (1)

73-83: Review the test for incorrect partition rule.

The SQL statement for creating a table with an incorrect partition rule is added for testing purposes. Ensure that this test case is included in the test suite and that it is expected to fail as intended.

tests/cases/standalone/common/partition.result (1)

170-183: Validate the expected result for incorrect partition rule.

The expected error message for the incorrect partition rule is correctly added. This ensures that the system properly handles and reports partition rule errors.

src/partition/src/multi_dim.rs (2)

192-192: Review changes in RuleChecker::check method.

The refactoring of the check method in RuleChecker should be carefully examined to ensure it does not introduce any regressions or overlook potential edge cases in partition rule validation.


69-69: Ensure proper error handling in try_new method.

The try_new method of MultiDimPartitionRule uses the check method of RuleChecker to validate the rule. Ensure that this validation is comprehensive and covers all necessary cases to prevent invalid partition rules.

Verification successful

Ensure proper error handling in try_new method.

The try_new method of MultiDimPartitionRule uses the check method of RuleChecker to validate the rule. Ensure that this validation is comprehensive and covers all necessary cases to prevent invalid partition rules.


Ensure proper error handling in try_new method.

The try_new method of MultiDimPartitionRule uses the check method of RuleChecker to validate the rule. Ensure that this validation is comprehensive and covers all necessary cases to prevent invalid partition rules.


Ensure proper error handling in try_new method.

The try_new method of MultiDimPartitionRule uses the check method of RuleChecker to validate the rule. Ensure that this validation is comprehensive and covers all necessary cases to prevent invalid partition rules.


Ensure proper error handling in try_new method.

The try_new method of MultiDimPartitionRule uses the check method of RuleChecker to validate the rule. Ensure that this validation is comprehensive and covers all necessary cases to prevent invalid partition rules.


Ensure proper error handling in try_new method.

The try_new method of MultiDimPartitionRule uses the check method of RuleChecker to validate the rule. Ensure that this validation is comprehensive and covers all necessary cases to prevent invalid partition rules.


Ensure proper error handling in try_new method.

The try_new method of MultiDimPartitionRule uses the check method of RuleChecker to validate the rule. Ensure that this validation is comprehensive and covers all necessary cases to prevent invalid partition rules.


Ensure proper error handling in try_new method.

The try_new method of MultiDimPartitionRule uses the check method of RuleChecker to validate the rule. The check method, along with the walk_expr and check_axis methods, provides comprehensive validation by ensuring that expressions are well-formed and all split points in the axis are properly closed. This validation covers all necessary cases to prevent invalid partition rules.

  • check method: Iterates over expressions and calls walk_expr.
  • walk_expr method: Recursively validates expressions.
  • check_axis method: Ensures all split points in the axis are properly closed.

These methods collectively ensure that the validation is thorough and robust.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all necessary cases are covered in the `check` method.
# Test: Search for the `check` method usage. Expect: Comprehensive validation logic.
rg --type rust $'check'

Length of output: 139608



Script:

#!/bin/bash
# Description: Retrieve the implementation of the `check` method and related methods within the `multi_dim.rs` file to ensure comprehensive validation.
ast-grep --lang rust --pattern $'impl RuleChecker {
  $_
  pub fn check(&mut self) -> Result<()> {
    $_
  }
  $_
}' --debug

Length of output: 344



Script:

#!/bin/bash
# Description: Retrieve the implementation of the `check` method and related methods within the `multi_dim.rs` file to ensure comprehensive validation.
ast-grep --lang rust --pattern $'impl RuleChecker {
  $_
  pub fn check(&mut self) -> Result<()> {
    $_
  }
  $_
}' --debug-query

Length of output: 302



Script:

#!/bin/bash
# Description: Retrieve the implementation of the `check` method and related methods within the `multi_dim.rs` file to ensure comprehensive validation.
rg 'impl RuleChecker' -A 20 src/partition/src/multi_dim.rs

Length of output: 60



Script:

#!/bin/bash
# Description: Retrieve the implementation of the `check` method and related methods within the `multi_dim.rs` file to ensure comprehensive validation.
rg 'impl RuleChecker' -A 50 src/partition/src/multi_dim.rs

Length of output: 60



Script:

#!/bin/bash
# Description: Retrieve the implementation of the `check` method directly within the `multi_dim.rs` file to ensure comprehensive validation.
rg 'pub fn check' -A 20 src/partition/src/multi_dim.rs

Length of output: 785



Script:

#!/bin/bash
# Description: Retrieve the full implementation of the `walk_expr` and `check_axis` methods within the `multi_dim.rs` file to ensure comprehensive validation.
rg 'fn walk_expr' -A 30 src/partition/src/multi_dim.rs
rg 'fn check_axis' -A 30 src/partition/src/multi_dim.rs

Length of output: 2128

src/operator/src/statement/ddl.rs (2)

43-43: Updated import statement for partitioning logic.

The import statement for MultiDimPartitionRule has been added to support the new partitioning validation logic. This is correctly placed in the import section and is necessary for the changes in partition rule validation.


73-75: Error variant renaming and addition.

The error variant InvalidPartitionRuleSnafu has been renamed to InvalidPartitionSnafu, which is a clearer name reflecting that it deals with invalid partition errors in general, not just rules. This change improves readability and maintainability of the error handling code.

src/operator/src/statement/ddl.rs Show resolved Hide resolved
@waynexia waynexia enabled auto-merge June 25, 2024 12:48
@waynexia waynexia added this pull request to the merge queue Jun 25, 2024
Copy link

codecov bot commented Jun 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.61%. Comparing base (0fc18b6) to head (e17b36c).
Report is 40 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4213      +/-   ##
==========================================
- Coverage   84.92%   84.61%   -0.31%     
==========================================
  Files        1023     1039      +16     
  Lines      179298   182766    +3468     
==========================================
+ Hits       152272   154653    +2381     
- Misses      27026    28113    +1087     

Merged via the queue into GreptimeTeam:main with commit 4d4a6cd Jun 25, 2024
55 checks passed
@waynexia waynexia deleted the validate-partition-rule branch June 25, 2024 13:10
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.

3 participants