From 8cc7129397e33784bc098ae3ede351b7f8378cd7 Mon Sep 17 00:00:00 2001 From: Ruihang Xia Date: Mon, 22 Jan 2024 16:50:28 +0800 Subject: [PATCH] fix: remove __name__ matcher from processed matcher list (#3213) Signed-off-by: Ruihang Xia --- src/promql/src/planner.rs | 3 +- .../cases/standalone/common/tql/basic.result | 29 +++++++++++++++++++ tests/cases/standalone/common/tql/basic.sql | 9 ++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/promql/src/planner.rs b/src/promql/src/planner.rs index 69333348f5a5..072b71228af5 100644 --- a/src/promql/src/planner.rs +++ b/src/promql/src/planner.rs @@ -557,6 +557,7 @@ impl PromPlanner { name: &Option, ) -> Result { self.ctx.reset(); + let metric_name; if let Some(name) = name.clone() { metric_name = Some(name); @@ -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()); } } diff --git a/tests/cases/standalone/common/tql/basic.result b/tests/cases/standalone/common/tql/basic.result index 12fab1cbb0fe..8d0229dd3164 100644 --- a/tests/cases/standalone/common/tql/basic.result +++ b/tests/cases/standalone/common/tql/basic.result @@ -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"}; diff --git a/tests/cases/standalone/common/tql/basic.sql b/tests/cases/standalone/common/tql/basic.sql index 0a94bad4492d..bd21518665f7 100644 --- a/tests/cases/standalone/common/tql/basic.sql +++ b/tests/cases/standalone/common/tql/basic.sql @@ -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"};