diff --git a/Cargo.lock b/Cargo.lock index fadd08359e..1cf1bfeb48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9953,9 +9953,9 @@ dependencies = [ [[package]] name = "promql-parser" -version = "0.6.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "328fe69c2443ec4f8e6c33ea925dde04a1026e6c95928e89ed02343944cac9bf" +checksum = "6c3c2199b84e1253aade469e92ae16cd8dbe1de031c66a00f4f5cdd650290a86" dependencies = [ "cfgrammar", "chrono", @@ -9965,7 +9965,6 @@ dependencies = [ "regex", "serde", "serde_json", - "unescaper", ] [[package]] @@ -10326,7 +10325,6 @@ dependencies = [ "tokio", "tokio-stream", "tracing", - "unescaper", "uuid", ] @@ -14169,15 +14167,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "unescaper" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c01d12e3a56a4432a8b436f293c25f4808bdf9e9f9f98f9260bba1f1bc5a1f26" -dependencies = [ - "thiserror 2.0.17", -] - [[package]] name = "unicase" version = "2.8.1" diff --git a/Cargo.toml b/Cargo.toml index a62ded4c53..6829c0f18a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -189,7 +189,7 @@ paste = "1.0" pin-project = "1.0" pretty_assertions = "1.4.0" prometheus = { version = "0.13.3", features = ["process"] } -promql-parser = { version = "0.6", features = ["ser"] } +promql-parser = { version = "0.7.1", features = ["ser"] } prost = { version = "0.13", features = ["no-recursion-limit"] } prost-types = "0.13" raft-engine = { version = "0.4.1", default-features = false } diff --git a/src/query/Cargo.toml b/src/query/Cargo.toml index 89a356e9a1..0d19450b4f 100644 --- a/src/query/Cargo.toml +++ b/src/query/Cargo.toml @@ -74,7 +74,6 @@ substrait.workspace = true table.workspace = true tokio.workspace = true tracing.workspace = true -unescaper = "0.1" uuid.workspace = true [dev-dependencies] diff --git a/src/query/src/promql/planner.rs b/src/query/src/promql/planner.rs index 8fc90d7f71..0de53ab60a 100644 --- a/src/query/src/promql/planner.rs +++ b/src/query/src/promql/planner.rs @@ -187,14 +187,6 @@ pub struct PromPlanner { ctx: PromPlannerContext, } -/// Unescapes the value of the matcher -pub fn normalize_matcher(mut matcher: Matcher) -> Matcher { - if let Ok(unescaped_value) = unescaper::unescape(&matcher.value) { - matcher.value = unescaped_value; - } - matcher -} - impl PromPlanner { pub async fn stmt_to_plan_with_alias( table_provider: DfTableSourceProvider, @@ -1060,9 +1052,7 @@ impl PromPlanner { } } - Ok(Matchers::new( - matchers.into_iter().map(normalize_matcher).collect(), - )) + Ok(Matchers::new(matchers.into_iter().collect())) } async fn selector_to_series_normalize_plan( diff --git a/src/servers/src/http/prometheus.rs b/src/servers/src/http/prometheus.rs index 26a91d51fa..31a712a68b 100644 --- a/src/servers/src/http/prometheus.rs +++ b/src/servers/src/http/prometheus.rs @@ -54,7 +54,6 @@ use promql_parser::parser::{ SubqueryExpr, UnaryExpr, VectorSelector, }; use query::parser::{DEFAULT_LOOKBACK_STRING, PromQuery, QueryLanguageParser}; -use query::promql::planner::normalize_matcher; use serde::de::{self, MapAccess, Visitor}; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -1241,7 +1240,6 @@ fn find_metric_name_not_equal_matchers(expr: &PromqlExpr) -> Option matchers .into_iter() .filter(|m| !matches!(m.op, MatchOp::Equal)) - .map(normalize_matcher) .collect::>() }) } diff --git a/tests/cases/standalone/common/promql/string_identifier.result b/tests/cases/standalone/common/promql/string_identifier.result new file mode 100644 index 0000000000..77414c6810 --- /dev/null +++ b/tests/cases/standalone/common/promql/string_identifier.result @@ -0,0 +1,72 @@ +CREATE TABLE promql_string_identifier ( + ts timestamp(3) time index, + "service.name" STRING, + host STRING, + val BIGINT, + PRIMARY KEY("service.name", host), +); + +Affected Rows: 0 + +INSERT INTO TABLE promql_string_identifier VALUES + (0, 'api-server', 'h1', 1), + (5000, 'db', 'host2', 2); + +Affected Rows: 2 + +-- string identifier for label names with dots +-- SQLNESS SORT_RESULT 3 1 +TQL EVAL (0, 10, '5s') promql_string_identifier{"service.name"="api-server"}; + ++---------------------+--------------+------+-----+ +| ts | service.name | host | val | ++---------------------+--------------+------+-----+ +| 1970-01-01T00:00:00 | api-server | h1 | 1 | +| 1970-01-01T00:00:05 | api-server | h1 | 1 | +| 1970-01-01T00:00:10 | api-server | h1 | 1 | ++---------------------+--------------+------+-----+ + +-- string identifier for metric names in label matchers +-- SQLNESS SORT_RESULT 3 1 +TQL EVAL (0, 10, '5s') {"promql_string_identifier"}; + ++---------------------+--------------+-------+-----+ +| ts | service.name | host | val | ++---------------------+--------------+-------+-----+ +| 1970-01-01T00:00:00 | api-server | h1 | 1 | +| 1970-01-01T00:00:05 | api-server | h1 | 1 | +| 1970-01-01T00:00:05 | db | host2 | 2 | +| 1970-01-01T00:00:10 | api-server | h1 | 1 | +| 1970-01-01T00:00:10 | db | host2 | 2 | ++---------------------+--------------+-------+-----+ + +-- string identifier in grouping labels +-- SQLNESS SORT_RESULT 3 1 +TQL EVAL (0, 10, '5s') sum by ("service.name") (promql_string_identifier); + ++--------------+---------------------+-----------------------------------+ +| service.name | ts | sum(promql_string_identifier.val) | ++--------------+---------------------+-----------------------------------+ +| api-server | 1970-01-01T00:00:00 | 1 | +| api-server | 1970-01-01T00:00:05 | 1 | +| api-server | 1970-01-01T00:00:10 | 1 | +| db | 1970-01-01T00:00:05 | 2 | +| db | 1970-01-01T00:00:10 | 2 | ++--------------+---------------------+-----------------------------------+ + +-- escaped hex in label matcher value +-- SQLNESS SORT_RESULT 3 1 +TQL EVAL (0, 10, '5s') promql_string_identifier{host="\x68\x31"}; + ++---------------------+--------------+------+-----+ +| ts | service.name | host | val | ++---------------------+--------------+------+-----+ +| 1970-01-01T00:00:00 | api-server | h1 | 1 | +| 1970-01-01T00:00:05 | api-server | h1 | 1 | +| 1970-01-01T00:00:10 | api-server | h1 | 1 | ++---------------------+--------------+------+-----+ + +DROP TABLE promql_string_identifier; + +Affected Rows: 0 + diff --git a/tests/cases/standalone/common/promql/string_identifier.sql b/tests/cases/standalone/common/promql/string_identifier.sql new file mode 100644 index 0000000000..1e83ec1cd6 --- /dev/null +++ b/tests/cases/standalone/common/promql/string_identifier.sql @@ -0,0 +1,29 @@ +CREATE TABLE promql_string_identifier ( + ts timestamp(3) time index, + "service.name" STRING, + host STRING, + val BIGINT, + PRIMARY KEY("service.name", host), +); + +INSERT INTO TABLE promql_string_identifier VALUES + (0, 'api-server', 'h1', 1), + (5000, 'db', 'host2', 2); + +-- string identifier for label names with dots +-- SQLNESS SORT_RESULT 3 1 +TQL EVAL (0, 10, '5s') promql_string_identifier{"service.name"="api-server"}; + +-- string identifier for metric names in label matchers +-- SQLNESS SORT_RESULT 3 1 +TQL EVAL (0, 10, '5s') {"promql_string_identifier"}; + +-- string identifier in grouping labels +-- SQLNESS SORT_RESULT 3 1 +TQL EVAL (0, 10, '5s') sum by ("service.name") (promql_string_identifier); + +-- escaped hex in label matcher value +-- SQLNESS SORT_RESULT 3 1 +TQL EVAL (0, 10, '5s') promql_string_identifier{host="\x68\x31"}; + +DROP TABLE promql_string_identifier; diff --git a/tests/cases/standalone/common/tql/case_sensitive.result b/tests/cases/standalone/common/tql/case_sensitive.result index 1ccbd5da0e..2da2473690 100644 --- a/tests/cases/standalone/common/tql/case_sensitive.result +++ b/tests/cases/standalone/common/tql/case_sensitive.result @@ -119,10 +119,18 @@ tql eval (0,10,'5s') sum by (AbCdE) (metric); | host2 | 1970-01-01T00:00:10 | 6.0 | +-------+---------------------+-----------------+ --- not allowed by the parser tql eval (0,10,'5s') sum by (`AbCdE`) (metric); -Error: 2000(InvalidSyntax), invalid promql query ++-------+---------------------+-----------------+ +| AbCdE | ts | sum(metric.val) | ++-------+---------------------+-----------------+ +| host1 | 1970-01-01T00:00:00 | 1.0 | +| host1 | 1970-01-01T00:00:05 | 2.0 | +| host1 | 1970-01-01T00:00:10 | 3.0 | +| host2 | 1970-01-01T00:00:00 | 4.0 | +| host2 | 1970-01-01T00:00:05 | 5.0 | +| host2 | 1970-01-01T00:00:10 | 6.0 | ++-------+---------------------+-----------------+ drop table metric; diff --git a/tests/cases/standalone/common/tql/case_sensitive.sql b/tests/cases/standalone/common/tql/case_sensitive.sql index f1c8e3b3d0..a250e6b270 100644 --- a/tests/cases/standalone/common/tql/case_sensitive.sql +++ b/tests/cases/standalone/common/tql/case_sensitive.sql @@ -55,7 +55,6 @@ tql eval (0,10,'5s') sum by (abcde) (metric); tql eval (0,10,'5s') sum by (AbCdE) (metric); --- not allowed by the parser tql eval (0,10,'5s') sum by (`AbCdE`) (metric); drop table metric;