Skip to content

Commit

Permalink
fix: remove __name__ matcher from processed matcher list (#3213)
Browse files Browse the repository at this point in the history
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
  • Loading branch information
waynexia authored Jan 22, 2024
1 parent 278e4c8 commit 8cc7129
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/promql/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ impl PromPlanner {
name: &Option<String>,
) -> Result<Matchers> {
self.ctx.reset();

let metric_name;
if let Some(name) = name.clone() {
metric_name = Some(name);
Expand All @@ -581,7 +582,7 @@ impl PromPlanner {
.field_column_matcher
.get_or_insert_default()
.push(matcher.clone());
} else {
} else if matcher.name != METRIC_NAME {
let _ = matchers.insert(matcher.clone());
}
}
Expand Down
29 changes: 29 additions & 0 deletions tests/cases/standalone/common/tql/basic.result
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,35 @@ TQL EVAL (0, 10, '5s') test;
| 2.0 | 1970-01-01T00:00:10 | a |
+-----+---------------------+---+

-- SQLNESS SORT_RESULT 2 1
TQL EVAL (0, 10, '5s') {__name__="test"};

+-----+---------------------+---+
| i | j | k |
+-----+---------------------+---+
| 1.0 | 1970-01-01T00:00:05 | b |
| 1.0 | 1970-01-01T00:00:10 | b |
| 2.0 | 1970-01-01T00:00:05 | a |
| 2.0 | 1970-01-01T00:00:10 | a |
+-----+---------------------+---+

-- SQLNESS SORT_RESULT 2 1
TQL EVAL (0, 10, '5s') {__name__="test", __field__="i"};

+-----+---+---------------------+
| i | k | j |
+-----+---+---------------------+
| 1.0 | b | 1970-01-01T00:00:05 |
| 1.0 | b | 1970-01-01T00:00:10 |
| 2.0 | a | 1970-01-01T00:00:05 |
| 2.0 | a | 1970-01-01T00:00:10 |
+-----+---+---------------------+

-- NOT SUPPORTED: `__name__` matcher without equal condition
TQL EVAL (0, 10, '5s') {__name__!="test"};

Error: 2000(InvalidSyntax), vector selector must contain at least one non-empty matcher

-- the point at 1ms will be shadowed by the point at 2ms
TQL EVAL (0, 10, '5s') test{k="a"};

Expand Down
9 changes: 9 additions & 0 deletions tests/cases/standalone/common/tql/basic.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ INSERT INTO test VALUES (1, 1, "a"), (1, 1, "b"), (2, 2, "a");
-- evaluate at 0s, 5s and 10s. No point at 0s.
TQL EVAL (0, 10, '5s') test;

-- SQLNESS SORT_RESULT 2 1
TQL EVAL (0, 10, '5s') {__name__="test"};

-- SQLNESS SORT_RESULT 2 1
TQL EVAL (0, 10, '5s') {__name__="test", __field__="i"};

-- NOT SUPPORTED: `__name__` matcher without equal condition
TQL EVAL (0, 10, '5s') {__name__!="test"};

-- the point at 1ms will be shadowed by the point at 2ms
TQL EVAL (0, 10, '5s') test{k="a"};

Expand Down

0 comments on commit 8cc7129

Please sign in to comment.