feat: bump promql-parser to v0.7.1 (#7521)

* feat: bump promql-parser to v0.7.0

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* add sqlness tests

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* update other sqlness results

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* Update tests/cases/standalone/common/tql/case_sensitive.result

Co-authored-by: Ning Sun <sunng@protonmail.com>

* remove escape on greptimedb side

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* update to v0.7.1

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* remove unused deps

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

---------

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Co-authored-by: Ning Sun <sunng@protonmail.com>
This commit is contained in:
Ruihang Xia
2026-01-07 15:23:40 +08:00
committed by GitHub
parent 2f242927a8
commit 9a4b7cbb32
9 changed files with 115 additions and 31 deletions

15
Cargo.lock generated
View File

@@ -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"

View File

@@ -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 }

View File

@@ -74,7 +74,6 @@ substrait.workspace = true
table.workspace = true
tokio.workspace = true
tracing.workspace = true
unescaper = "0.1"
uuid.workspace = true
[dev-dependencies]

View File

@@ -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(

View File

@@ -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<Vec<Matcher>
matchers
.into_iter()
.filter(|m| !matches!(m.op, MatchOp::Equal))
.map(normalize_matcher)
.collect::<Vec<_>>()
})
}

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;