test(promql): cover label_replace normalization with distinct series (#9485)

The duplicate-label-set rejection must not fire when a label rewrite keeps
every series distinct through another label. Normalizing mixed histogram
boundary representations (`10.0` -> `10`) while `instance` still differs is
the false positive reported in #9444. The check already accounts for it
since it became a per-timestamp row count instead of a planning-time
rejection, but no fixture covered the positive case. Add one, together
with the aggregation variant that produces a genuine duplicate and must
still fail.

Signed-off-by: fengyue-xve <1759519137@qq.com>
This commit is contained in:
fengyue-xve
2026-10-09 09:59:20 +00:00
committed by GitHub
parent f1a27ab599
commit 764ab8bc1a
2 changed files with 78 additions and 0 deletions
@@ -484,3 +484,52 @@ DROP TABLE test;
Affected Rows: 0
-- Issue 9444 --
-- Normalizing mixed histogram boundary representations must not be rejected while
-- another label still tells the series apart.
CREATE TABLE demo_bucket (
ts timestamp(3) time index,
instance STRING,
le STRING,
val DOUBLE,
PRIMARY KEY(instance, le),
);
Affected Rows: 0
INSERT INTO TABLE demo_bucket VALUES
(3000000, 'a', '10', 40),
(3000000, 'a', '100', 50),
(3000000, 'a', '+Inf', 50),
(3000000, 'b', '10.0', 40),
(3000000, 'b', '100.0', 50),
(3000000, 'b', '1000.0', 50),
(3000000, 'b', '+Inf', 50);
Affected Rows: 7
-- SQLNESS SORT_RESULT 3 1
TQL EVAL (3000, 3000, '5s') label_replace(demo_bucket, "le", "$1", "le", "([0-9]+)[.]0+");
+---------------------+------+------+----------+
| ts | val | le | instance |
+---------------------+------+------+----------+
| 1970-01-01T00:50:00 | 40.0 | 10 | a |
| 1970-01-01T00:50:00 | 40.0 | 10 | b |
| 1970-01-01T00:50:00 | 50.0 | +Inf | a |
| 1970-01-01T00:50:00 | 50.0 | +Inf | b |
| 1970-01-01T00:50:00 | 50.0 | 100 | a |
| 1970-01-01T00:50:00 | 50.0 | 100 | b |
| 1970-01-01T00:50:00 | 50.0 | 1000 | b |
+---------------------+------+------+----------+
-- Aggregating `instance` away first makes the same rewrite collapse two series into
-- one label set, which is a genuine duplicate and must still fail.
TQL EVAL (3000, 3000, '5s') label_replace(sum by (le) (demo_bucket), "le", "$1", "le", "([0-9]+)[.]0+");
Error: 3001(EngineExecuteQuery), Execution error: vector cannot contain metrics with the same labelset
DROP TABLE demo_bucket;
Affected Rows: 0
@@ -144,3 +144,32 @@ TQL EVAL (0, 1, '5s') test{job=""};
TQL EVAL (0, 1, '5s') test{job!=""};
DROP TABLE test;
-- Issue 9444 --
-- Normalizing mixed histogram boundary representations must not be rejected while
-- another label still tells the series apart.
CREATE TABLE demo_bucket (
ts timestamp(3) time index,
instance STRING,
le STRING,
val DOUBLE,
PRIMARY KEY(instance, le),
);
INSERT INTO TABLE demo_bucket VALUES
(3000000, 'a', '10', 40),
(3000000, 'a', '100', 50),
(3000000, 'a', '+Inf', 50),
(3000000, 'b', '10.0', 40),
(3000000, 'b', '100.0', 50),
(3000000, 'b', '1000.0', 50),
(3000000, 'b', '+Inf', 50);
-- SQLNESS SORT_RESULT 3 1
TQL EVAL (3000, 3000, '5s') label_replace(demo_bucket, "le", "$1", "le", "([0-9]+)[.]0+");
-- Aggregating `instance` away first makes the same rewrite collapse two series into
-- one label set, which is a genuine duplicate and must still fail.
TQL EVAL (3000, 3000, '5s') label_replace(sum by (le) (demo_bucket), "le", "$1", "le", "([0-9]+)[.]0+");
DROP TABLE demo_bucket;