-
Notifications
You must be signed in to change notification settings - Fork 17
Fix directive parsing and order of operators in conditional query #899
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
Fix directive parsing and order of operators in conditional query #899
Conversation
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.
Pull Request Overview
This PR fixes a bug in the query parser where directive parsing broke the order of operators in conditional queries. The solution preserves operator order by using the preserve_order
feature of serde_json
and refactors directive validation by moving it from the parser to the respective directive modules.
- Directive parsing refactored to preserve operator order by using
shift_remove
instead ofremove
- Directive validation moved from the parser to individual directive modules (
CtxBefore
,CtxAfter
,LabelSelector
) - Added comprehensive test coverage for invalid directive inputs
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
reductstore/Cargo.toml | Enables preserve_order feature for serde_json to maintain operator order |
reductstore/src/storage/query/condition/parser.rs | Simplifies directive parsing and uses shift_remove to preserve order |
reductstore/src/storage/query/condition.rs | Re-exports Value type for use in directive modules |
reductstore/src/storage/query/filters/when.rs | Updates to use new directive constructors and removes inline validation |
reductstore/src/storage/query/filters/when/ctx_before.rs | Adds try_new constructor with validation for #ctx_before directive |
reductstore/src/storage/query/filters/when/ctx_after.rs | Adds try_new constructor with validation for #ctx_after directive |
reductstore/src/storage/query/filters/when/select_labels.rs | New module with validation for #select_labels directive |
CHANGELOG.md | Documents the bug fix |
keys_to_remove.push(key.to_string()); | ||
} | ||
} | ||
|
||
// Remove directives from the original JSON object | ||
for key in keys_to_remove { | ||
json.as_object_mut().unwrap().remove(&key); | ||
json.as_object_mut().unwrap().shift_remove(&key); |
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.
@AnthonyCvn FIY, this part broke the order. If a query had a directive, this method was called and it shuffled the operators in the query.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## stable #899 +/- ##
==========================================
+ Coverage 95.35% 95.54% +0.18%
==========================================
Files 166 167 +1
Lines 10061 10102 +41
==========================================
+ Hits 9594 9652 +58
+ Misses 467 450 -17
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
Closes #894
Please check if the PR fulfills these requirements
What kind of change does this PR introduce?
Bug fix + refactoring
What was changed?
The query parser broke the order of operators after directive parsing. The PR fixes this by preserving the order of operators. Additionally, it refactors the parser and moves the directive checks to the directives modules.
Related issues
#894 #866 #888
Does this PR introduce a breaking change?
No
Other information: