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: handle parentheses with unary ops #4290

Merged
merged 8 commits into from
Jul 9, 2024

Conversation

waynexia
Copy link
Member

@waynexia waynexia commented Jul 4, 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?

The one last piece

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

    • Introduced a new matches function for advanced pattern matching in SQL queries.
  • Bug Fixes

    • Enhanced parsing logic to handle unary operators (Must, Negative, Optional) more effectively in pattern matching.
  • Tests

    • Added new SQL test cases to demonstrate and verify the usage of the matches function.

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
@waynexia waynexia requested a review from a team as a code owner July 4, 2024 14:53
Copy link
Contributor

coderabbitai bot commented Jul 4, 2024

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Walkthrough

This update introduces several enhancements to the MatchesFunction in a Rust codebase. It includes the registration of MatchesFunction in the function registry, improvements to parsing logic for unary operators, and the introduction of new SQL test cases showcasing the practical application of the matches function. The new enum variants and parsing logic changes bolster the function's pattern-matching capabilities.

Changes

File Change Summary
src/common/function/src/function_registry.rs Added MatchesFunction to the imports and registered it in the FUNCTION_REGISTRY.
src/common/function/src/scalars/matches.rs Introduced registration method for MatchesFunction, enhanced pattern and token parsing logic.
tests/cases/standalone/common/select/matches.result, tests/cases/standalone/common/select/matches.sql Added SQL test cases demonstrating table creation, data insertion, selection with pattern matching, and table deletion.

Sequence Diagram(s)

sequenceDiagram
    participant Client as SQL Client
    participant DB as Database
    participant FuncReg as Function Registry
    participant MatchesFunc as MatchesFunction
    
    Client->>DB: CREATE TABLE test(id INT, name VARCHAR)
    DB-->>Client: Table created
    Client->>DB: INSERT INTO test VALUES (1, 'Alice'), (2, 'Bob')
    DB-->>Client: Data inserted
    Client->>FuncReg: Register MatchesFunction
    FuncReg-->>MatchesFunc: Called register
    Client->>DB: SELECT * FROM test WHERE name MATCHES 'A.*'
    DB->>MatchesFunc: Evaluate pattern
    MatchesFunc-->>DB: Matches result
    DB-->>Client: Query result
    Client->>DB: DROP TABLE test
    DB-->>Client: Table dropped
Loading

Poem

In lines of code so neat and tight,
Patterns now match, with new insight.
From tables built, to rows we seek,
Our functions strong, no longer meek.
Registry grows, the test it shows,
Data flows where logic glows.


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.

@waynexia
Copy link
Member Author

waynexia commented Jul 4, 2024

@coderabbitai pause

@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Jul 4, 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 b5c6c72 and de124e9.

Files selected for processing (4)
  • src/common/function/src/function_registry.rs (2 hunks)
  • src/common/function/src/scalars/matches.rs (24 hunks)
  • tests/cases/standalone/common/select/matches.result (1 hunks)
  • tests/cases/standalone/common/select/matches.sql (1 hunks)
Additional comments not posted (26)
tests/cases/standalone/common/select/matches.sql (4)

1-4: SQL Table Creation Looks Good.

The table creation statement for fox is correct.


6-13: SQL Insert Statements Look Good.

The insert statements are correct and insert various test cases for the matches function.


15-15: SQL Select Statement Looks Good.

The select statement correctly uses the matches function to filter rows.


17-17: SQL Drop Table Statement Looks Good.

The drop table statement correctly drops the fox table.

tests/cases/standalone/common/select/matches.result (4)

1-4: Result: Table Creation Affects Zero Rows.

The table creation statement does not affect any rows, which is expected.


8-15: Result: Insert Statements Affect Seven Rows.

The insert statements correctly affect seven rows.


19-29: Result: Select Statement Returns Correct Rows.

The select statement returns the correct rows based on the matches function.


31-33: Result: Drop Table Affects Zero Rows.

The drop table statement does not affect any rows, which is expected.

src/common/function/src/function_registry.rs (2)

25-25: New Import: MatchesFunction

The MatchesFunction has been correctly imported.


90-91: Registering MatchesFunction

The MatchesFunction is correctly registered in the function registry.

src/common/function/src/scalars/matches.rs (16)

36-36: New Import: FunctionRegistry

The FunctionRegistry has been correctly imported.


42-42: Visibility Change: MatchesFunction

The MatchesFunction struct is now pub(crate), which is appropriate for internal use.


44-48: New Method: register

The register method correctly registers the MatchesFunction in the FunctionRegistry.


144-153: New PatternAst Variant: Group

The PatternAst enum now includes a Group variant to represent sub-trees enclosed by parentheses. This change is necessary to handle parentheses with unary operations.


193-200: Handling Group Variant in into_like_expr

The into_like_expr method correctly handles the new Group variant.


253-253: Handling Group Variant in collapse_binary_branch_fn

The collapse_binary_branch_fn method correctly handles the new Group variant.


303-303: Handling Group Variant in eliminate_optional_fn

The eliminate_optional_fn method correctly handles the new Group variant.


364-364: Handling Group Variant in eliminate_single_child_fn

The eliminate_single_child_fn method correctly handles the new Group variant.


390-390: Handling Group Variant in TreeNode Implementation

The TreeNode implementation for PatternAst correctly handles the new Group variant.


428-428: New Method: accomplish_optional_unary_op

The accomplish_optional_unary_op method is correctly added to the ParserContext implementation.


453-497: Implementing accomplish_optional_unary_op

The accomplish_optional_unary_op method correctly processes the raw tokens to handle optional unary operations.


508-520: Handling Unary Operators in to_rpn

The to_rpn method correctly handles the new Optional unary operator.


554-573: Handling Must Operator in parse_one_impl

The parse_one_impl method correctly handles the Must operator.


577-596: Handling Negative Operator in parse_one_impl

The parse_one_impl method correctly handles the Negative operator.


599-622: Handling Optional Operator in parse_one_impl

The parse_one_impl method correctly handles the Optional operator.


697-702: New Token Variant: Optional

The Token enum now includes an Optional variant to represent optional unary operations.

Copy link
Contributor

coderabbitai bot commented Jul 4, 2024

Actions performed

Reviews paused.

Copy link

codecov bot commented Jul 4, 2024

Codecov Report

Attention: Patch coverage is 97.48954% with 6 lines in your changes missing coverage. Please review.

Project coverage is 84.88%. Comparing base (aa4d10e) to head (5ab443b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4290      +/-   ##
==========================================
- Coverage   85.13%   84.88%   -0.26%     
==========================================
  Files        1061     1061              
  Lines      187834   187974     +140     
==========================================
- Hits       159911   159560     -351     
- Misses      27923    28414     +491     

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Copy link
Contributor

@evenyag evenyag left a comment

Choose a reason for hiding this comment

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

Others LGTM

Copy link
Contributor

@killme2008 killme2008 left a comment

Choose a reason for hiding this comment

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

LGTM

@waynexia waynexia enabled auto-merge July 9, 2024 03:31
@waynexia waynexia added this pull request to the merge queue Jul 9, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 9, 2024
@killme2008 killme2008 added this pull request to the merge queue Jul 9, 2024
Merged via the queue into GreptimeTeam:main with commit 23bb9d9 Jul 9, 2024
52 of 53 checks passed
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