Skip to content

Conversation

atimin
Copy link
Member

@atimin atimin commented Aug 9, 2025

Closes #894

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • CHANGELOG.md has been updated (for bug fixes / features / docs)

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:

@atimin atimin linked an issue Aug 9, 2025 that may be closed by this pull request
1 task
@atimin atimin requested a review from Copilot August 9, 2025 15:44
Copy link
Contributor

@Copilot Copilot AI left a 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 of remove
  • 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);
Copy link
Member Author

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.

@atimin atimin changed the base branch from main to stable August 9, 2025 15:47
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link

codecov bot commented Aug 9, 2025

Codecov Report

❌ Patch coverage is 99.23664% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.54%. Comparing base (ceb730e) to head (52783c6).
⚠️ Report is 1 commits behind head on stable.

Files with missing lines Patch % Lines
reductstore/src/storage/query/condition/parser.rs 94.44% 1 Missing ⚠️
@@            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     
Files with missing lines Coverage Δ
reductstore/src/storage/query/condition.rs 82.35% <ø> (ø)
reductstore/src/storage/query/filters/when.rs 100.00% <100.00%> (ø)
...tstore/src/storage/query/filters/when/ctx_after.rs 100.00% <100.00%> (ø)
...store/src/storage/query/filters/when/ctx_before.rs 100.00% <100.00%> (ø)
...re/src/storage/query/filters/when/select_labels.rs 100.00% <100.00%> (ø)
reductstore/src/storage/query/condition/parser.rs 99.39% <94.44%> (-0.61%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@atimin atimin merged commit 360c8d6 into stable Aug 9, 2025
46 checks passed
@atimin atimin deleted the 894-bug-context-directives-and-limit-operator-dont-work-together branch August 9, 2025 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Context directives and $limit operator don't work together
1 participant