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(sql): add casting support for shortened intervals #4220

Merged
merged 2 commits into from
Jun 26, 2024

Conversation

etolbakov
Copy link
Collaborator

@etolbakov etolbakov commented Jun 26, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link

#4168

What's changed and what's your intention?

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

    • Enhanced support for SQL interval data types, including milliseconds, microseconds, and nanoseconds.
    • Added detailed interval type casting for better precision in SQL queries.
  • Bug Fixes

    • Improved handling and transformation logic for interval expressions, ensuring more accurate results.

@etolbakov etolbakov requested a review from a team as a code owner June 26, 2024 16:52
Copy link
Contributor

coderabbitai bot commented Jun 26, 2024

Walkthrough

The recent changes enhance handling and transformation of SQL INTERVAL data types by refining casting logic and enhancing support for varied time units like milliseconds, microseconds, and nanoseconds. The updates include modifications to the expand_interval.rs file and interval-related SQL queries to ensure accurate interval representations and seamless transformations.

Changes

File(s) Change Summary
src/sql/src/statements/transform/expand_interval.rs Added import for DataType, refined interval handling logic, and updated public entity declarations for better interval transformation.
tests/cases/standalone/common/types/interval/interval.result Added SQL queries showcasing results with INTERVAL data type for specific time durations, demonstrating ::INTERVAL casting.
tests/cases/standalone/common/types/interval/interval.sql Included new interval type casting queries such as '3 hours' and '3y2mon' to illustrate usage and results.

Poem

In the world of SQL so bright and true,
Intervals now shine with milliseconds too.
From hours to years, the time flows free,
Cast your queries, and let time be.
With code refined, transformations sing,
Celebrating each tick of the interval's ring.
🌟


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 26, 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

Outside diff range and nitpick comments (2)
src/sql/src/statements/transform/expand_interval.rs (2)

Line range hint 68-115: Refined logic for handling interval expressions.

The modifications to visit_expr method enhance the handling of both simple and complex interval expressions. The use of cloning and matching patterns is appropriate for the transformations required. However, there's a potential area of improvement in error handling when the expected data is not found.

Consider adding error handling or logging when expand_interval_name returns None, to aid in debugging and ensure robustness.


Line range hint 161-343: Comprehensive unit tests for interval transformations.

The tests cover a wide range of scenarios, including basic and compound conversions, and transformations within different types of expressions. This thorough testing is crucial for ensuring the reliability of the new interval handling features.

However, it would be beneficial to add negative test cases to verify the behavior when invalid inputs are provided.

Would you like assistance in writing these negative test cases?

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between df0fff2 and e225960.

Files selected for processing (3)
  • src/sql/src/statements/transform/expand_interval.rs (10 hunks)
  • tests/cases/standalone/common/types/interval/interval.result (2 hunks)
  • tests/cases/standalone/common/types/interval/interval.sql (2 hunks)
Files skipped from review due to trivial changes (2)
  • tests/cases/standalone/common/types/interval/interval.result
  • tests/cases/standalone/common/types/interval/interval.sql
Additional comments not posted (3)
src/sql/src/statements/transform/expand_interval.rs (3)

21-21: Updated import statement to include DataType.

This change is necessary for the new features related to interval type casting and is consistent with the PR objectives.


39-39: Addition of new interval abbreviations for better granularity.

Adding 'ms' for milliseconds, 'us' for microseconds, and 'ns' for nanoseconds enhances the functionality for handling more precise time intervals. This change aligns with the PR's goal to improve interval handling.


55-55: Documentation update for new interval abbreviations.

The documentation here is updated to reflect the new abbreviations, ensuring clarity and maintainability. It's important for future developers to understand these mappings quickly.

Copy link

codecov bot commented Jun 26, 2024

Codecov Report

Attention: Patch coverage is 99.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 84.57%. Comparing base (df0fff2) to head (bde41da).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4220      +/-   ##
==========================================
- Coverage   84.84%   84.57%   -0.28%     
==========================================
  Files        1041     1041              
  Lines      183028   183074      +46     
==========================================
- Hits       155291   154830     -461     
- Misses      27737    28244     +507     

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 e225960 and bde41da.

Files selected for processing (1)
  • src/sql/src/statements/transform/expand_interval.rs (10 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/sql/src/statements/transform/expand_interval.rs

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.

Thanks a lot @etolbakov

@killme2008 killme2008 requested a review from tisonkun June 26, 2024 21:45
Copy link
Collaborator

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

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

Thanks for your follow-up @etolbakov!

There can be also a follow-up to GreptimeTeam/docs#1021 (remove millis). Would you take a look at that? Or I can do it today.

@tisonkun tisonkun added this pull request to the merge queue Jun 26, 2024
@etolbakov
Copy link
Collaborator Author

Thanks @tisonkun!
Please go ahead ! 🤝

Merged via the queue into GreptimeTeam:main with commit 8702066 Jun 26, 2024
51 checks passed
@etolbakov etolbakov deleted the shortened-interval-cast branch June 27, 2024 07:46
zyy17 pushed a commit to zyy17/greptimedb that referenced this pull request Jun 28, 2024
…4220)

* feat(sql): add casting support for shortened intervals

* chore(sql): apply CR suggestion, minor renamings
zyy17 pushed a commit to zyy17/greptimedb that referenced this pull request Jun 28, 2024
…4220)

* feat(sql): add casting support for shortened intervals

* chore(sql): apply CR suggestion, minor renamings
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