Skip to content

Fix NOT BETWEEN compiling to the same filter as BETWEEN in metrics SQL#9719

Merged
nishantmonu51 merged 2 commits into
mainfrom
nishantmonu51/fix-not-between-filter
Jul 21, 2026
Merged

Fix NOT BETWEEN compiling to the same filter as BETWEEN in metrics SQL#9719
nishantmonu51 merged 2 commits into
mainfrom
nishantmonu51/fix-not-between-filter

Conversation

@nishantmonu51

Copy link
Copy Markdown
Collaborator
  • parseBetween in runtime/metricsview/metricssql/filter_parser.go ignored the AST's Not flag, so x NOT BETWEEN 1 AND 10 compiled to the same expression as x BETWEEN 1 AND 10 — the range filter was silently inverted.
  • Now NOT BETWEEN compiles to (x < low OR x > high); plain BETWEEN output is unchanged.
  • Added TestParseFilter cases for both forms.

Steps to reproduce:

  1. Call metricssql.ParseFilter("x NOT BETWEEN 1 AND 10") (or use the filter in any metrics SQL WHERE clause).
  2. Before this fix it returned {op: and, [{gte, x, 1}, {lte, x, 10}]} — identical to x BETWEEN 1 AND 10, so every row the filter was meant to exclude was included and vice versa.
  3. With this fix it returns {op: or, [{lt, x, 1}, {gt, x, 10}]}.

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

…-between-filter

# Conflicts:
#	runtime/metricsview/metricssql/filter_parser_test.go
@nishantmonu51
nishantmonu51 merged commit 2c1972b into main Jul 21, 2026
11 checks passed
@nishantmonu51
nishantmonu51 deleted the nishantmonu51/fix-not-between-filter branch July 21, 2026 04:55
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.

2 participants