-
Notifications
You must be signed in to change notification settings - Fork 308
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): improve interval expression, support shortened version #4182
feat(sql): improve interval expression, support shortened version #4182
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4182 +/- ##
==========================================
- Coverage 85.03% 84.76% -0.28%
==========================================
Files 1030 1031 +1
Lines 181129 181276 +147
==========================================
- Hits 154020 153653 -367
- Misses 27109 27623 +514 |
I see that one
strangely enough I don't see the same behaviour running those tests locally. Keep looking though |
@etolbakov Could you rebase the branch with the main branch? Looks like it's an issue after upgrading DataFusion and fixed. |
🤔
seems that the error message format became different.
|
@etolbakov Let me try it on my machine, thank you 👍 |
Did you forget to commit Yes, the error message is different after upgrading DataFusion, you have to commit and push it too. |
My result is,
It's different from your branch result. |
Thank you very much for validating! let me double check now (maybe it's me being inattentive) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What a great job! Thanks, @etolbakov
I have a few suggestions, please take a look.
WalkthroughThis update introduces a new transformer rule for SQL statements to expand short interval names to their full names, such as converting 'h' to 'hours'. Additionally, it includes new SQL test cases to validate these changes, and a minor comment update regarding type aliases in a different module. Changes
Sequence Diagram(s)sequenceDiagram
participant SQLParser
participant TransformEngine
participant ExpandIntervalTransformRule
participant SQLExecutor
SQLParser->>TransformEngine: Parse query
TransformEngine->>ExpandIntervalTransformRule: Apply expansion rule
ExpandIntervalTransformRule-->>TransformEngine: Expanded intervals
TransformEngine->>SQLExecutor: Transformed query
SQLExecutor->>SQLExecutor: Execute query
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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
Files selected for processing (5)
- src/sql/src/statements/transform.rs (1 hunks)
- src/sql/src/statements/transform/expand_interval.rs (1 hunks)
- src/sql/src/statements/transform/type_alias.rs (1 hunks)
- tests/cases/standalone/common/types/interval/interval.result (1 hunks)
- tests/cases/standalone/common/types/interval/interval.sql (1 hunks)
Files skipped from review due to trivial changes (3)
- src/sql/src/statements/transform/type_alias.rs
- tests/cases/standalone/common/types/interval/interval.result
- tests/cases/standalone/common/types/interval/interval.sql
Additional comments not posted (9)
src/sql/src/statements/transform.rs (4)
23-26
: Ensure consistent module usage.The
expand_interval
module is correctly declared and used. However, ensure that any functionality from this module is correctly integrated and tested elsewhere in the codebase.
33-33
: Addition ofExpandIntervalTransformRule
to rules vector.This addition is crucial for integrating the new interval expansion functionality. Ensure that the
ExpandIntervalTransformRule
is thoroughly tested to maintain the robustness of the transformation logic.
Line range hint
37-46
: Review theTransformRule
trait.The trait provides a framework for implementing transformation rules but does not contain specific logic. Ensure that all implementations of this trait handle their specific logic correctly and efficiently.
Line range hint
52-67
: Review thetransform_statements
function.The function systematically applies transformation rules to each statement and expression. Ensure that this does not introduce performance issues with large numbers of statements or complex nested expressions.
src/sql/src/statements/transform/expand_interval.rs (5)
24-37
: Review the interval short name mappings.The mappings are comprehensive and cover a wide range of interval units. Ensure that these mappings are kept up-to-date with any changes in the SQL standards or user requirements.
54-54
: Struct declaration for interval transformation.The
ExpandIntervalTransformRule
struct is well-defined. Ensure that its implementation in thevisit_expr
method correctly handles all edge cases for interval expressions.
56-81
: Review the implementation of interval expression transformation.The method
visit_expr
effectively handles interval expressions by expanding short names. Ensure that this method handles all possible input variations and correctly reports any errors or invalid inputs.
84-94
: Review the utility function for getting interval short names.The function
get_interval_short_name
correctly extracts the unit from the interval string. Ensure that this function is robust against malformed inputs and performs necessary validations.
96-105
: Review the utility function for expanding interval names.The function
expand_interval_name
uses the mapping to expand short names to their full equivalents. Ensure that this function correctly handles cases where no mapping exists and does not alter the input inappropriately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@waynexia @fengjiachun Please take a look. |
There was a problem hiding this 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
Files selected for processing (3)
- src/sql/src/statements/transform/expand_interval.rs (1 hunks)
- tests/cases/standalone/common/types/interval/interval.result (1 hunks)
- tests/cases/standalone/common/types/interval/interval.sql (1 hunks)
Files skipped from review as they are similar to previous changes (3)
- src/sql/src/statements/transform/expand_interval.rs
- tests/cases/standalone/common/types/interval/interval.result
- tests/cases/standalone/common/types/interval/interval.sql
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good patch! I ever introduced a difference between InfluxQL and SQL that SQL has a standard interval literal syntax, but this patch supports the convenient syntax for interval literal :D
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?
improve interval expression by handling shortened version
Checklist
Summary by CodeRabbit
New Features
Documentation
Int8
alias for PostgresBigint
.Tests