From e0697790e6c7676d1d08fc37110662e9f54f92be Mon Sep 17 00:00:00 2001 From: Ruihang Xia Date: Mon, 15 Dec 2025 16:12:12 +0800 Subject: [PATCH] chore: sort histogram sqlness result (#7406) Signed-off-by: Ruihang Xia --- .../common/promql/simple_histogram.result | 14 +++++++++++++- .../standalone/common/promql/simple_histogram.sql | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/cases/standalone/common/promql/simple_histogram.result b/tests/cases/standalone/common/promql/simple_histogram.result index 39baf6ea82..30b48b3455 100644 --- a/tests/cases/standalone/common/promql/simple_histogram.result +++ b/tests/cases/standalone/common/promql/simple_histogram.result @@ -56,6 +56,7 @@ tql eval (3000, 3000, '1s') histogram_quantile(NaN, histogram_bucket); +---------------------+----------+-----+ -- Quantile value in lowest bucket, which is positive. +-- SQLNESS SORT_RESULT 3 1 tql eval (3000, 3000, '1s') histogram_quantile(0, histogram_bucket{s="positive"}); +---------------------+----------+-----+ @@ -65,6 +66,7 @@ tql eval (3000, 3000, '1s') histogram_quantile(0, histogram_bucket{s="positive"} +---------------------+----------+-----+ -- Quantile value in lowest bucket, which is negative. +-- SQLNESS SORT_RESULT 3 1 tql eval (3000, 3000, '1s') histogram_quantile(0, histogram_bucket{s="negative"}); +---------------------+----------+------+ @@ -128,6 +130,7 @@ tql eval (3000, 3000, '1s') label_replace(histogram_quantile(0.8, histogram_buck -- More realistic with rates. -- This case doesn't contains value because other point are not inserted. -- quantile with rate is covered in other cases +-- SQLNESS SORT_RESULT 3 1 tql eval (3000, 3000, '1s') histogram_quantile(0.2, rate(histogram_bucket[5m])); ++ @@ -202,6 +205,7 @@ insert into histogram2_bucket values Affected Rows: 50 -- Want results exactly in the middle of the bucket. +-- SQLNESS SORT_RESULT 3 1 tql eval (420, 420, '1s') histogram_quantile(0.166, histogram2_bucket); +---------------------+-------+ @@ -210,6 +214,7 @@ tql eval (420, 420, '1s') histogram_quantile(0.166, histogram2_bucket); | 1970-01-01T00:07:00 | 0.996 | +---------------------+-------+ +-- SQLNESS SORT_RESULT 3 1 tql eval (420, 420, '1s') histogram_quantile(0.5, histogram2_bucket); +---------------------+-----+ @@ -218,6 +223,7 @@ tql eval (420, 420, '1s') histogram_quantile(0.5, histogram2_bucket); | 1970-01-01T00:07:00 | 3.0 | +---------------------+-----+ +-- SQLNESS SORT_RESULT 3 1 tql eval (420, 420, '1s') histogram_quantile(0.833, histogram2_bucket); +---------------------+-------------------+ @@ -226,6 +232,7 @@ tql eval (420, 420, '1s') histogram_quantile(0.833, histogram2_bucket); | 1970-01-01T00:07:00 | 4.997999999999999 | +---------------------+-------------------+ +-- SQLNESS SORT_RESULT 3 1 tql eval (2820, 2820, '1s') histogram_quantile(0.166, rate(histogram2_bucket[15m])); +---------------------+------------------------------------------+ @@ -234,6 +241,7 @@ tql eval (2820, 2820, '1s') histogram_quantile(0.166, rate(histogram2_bucket[15m | 1970-01-01T00:47:00 | 0.996 | +---------------------+------------------------------------------+ +-- SQLNESS SORT_RESULT 3 1 tql eval (2820, 2820, '1s') histogram_quantile(0.5, rate(histogram2_bucket[15m])); +---------------------+------------------------------------------+ @@ -242,6 +250,7 @@ tql eval (2820, 2820, '1s') histogram_quantile(0.5, rate(histogram2_bucket[15m]) | 1970-01-01T00:47:00 | 3.0 | +---------------------+------------------------------------------+ +-- SQLNESS SORT_RESULT 3 1 tql eval (2820, 2820, '1s') histogram_quantile(0.833, rate(histogram2_bucket[15m])); +---------------------+------------------------------------------+ @@ -282,6 +291,7 @@ insert into histogram3_bucket values Affected Rows: 12 +-- SQLNESS SORT_RESULT 3 1 tql eval (3000, 3005, '3s') histogram_quantile(0.5, sum by(le, s) (rate(histogram3_bucket[5m]))); +---+---------------------+-----------------------------------------------+ @@ -350,12 +360,14 @@ CREATE TABLE greptime_servers_postgres_query_elapsed_no_le ( Affected Rows: 0 --- should return empty result instead of error when 'le' column is missing +-- should return empty result instead of error when 'le' column is missin +-- SQLNESS SORT_RESULT 3 1 tql eval(0, 10, '10s') histogram_quantile(0.99, sum by(pod,instance, le) (rate(greptime_servers_postgres_query_elapsed_no_le{instance=~"xxx"}[1m]))); ++ ++ +-- SQLNESS SORT_RESULT 3 1 tql eval(0, 10, '10s') histogram_quantile(0.99, sum by(pod,instance, fbf) (rate(greptime_servers_postgres_query_elapsed_no_le{instance=~"xxx"}[1m]))); ++ diff --git a/tests/cases/standalone/common/promql/simple_histogram.sql b/tests/cases/standalone/common/promql/simple_histogram.sql index e6b07aaca6..d18df63804 100644 --- a/tests/cases/standalone/common/promql/simple_histogram.sql +++ b/tests/cases/standalone/common/promql/simple_histogram.sql @@ -32,9 +32,11 @@ tql eval (3000, 3000, '1s') histogram_quantile(1.01, histogram_bucket); tql eval (3000, 3000, '1s') histogram_quantile(NaN, histogram_bucket); -- Quantile value in lowest bucket, which is positive. +-- SQLNESS SORT_RESULT 3 1 tql eval (3000, 3000, '1s') histogram_quantile(0, histogram_bucket{s="positive"}); -- Quantile value in lowest bucket, which is negative. +-- SQLNESS SORT_RESULT 3 1 tql eval (3000, 3000, '1s') histogram_quantile(0, histogram_bucket{s="negative"}); -- Quantile value in highest bucket. @@ -57,6 +59,7 @@ tql eval (3000, 3000, '1s') label_replace(histogram_quantile(0.8, histogram_buck -- More realistic with rates. -- This case doesn't contains value because other point are not inserted. -- quantile with rate is covered in other cases +-- SQLNESS SORT_RESULT 3 1 tql eval (3000, 3000, '1s') histogram_quantile(0.2, rate(histogram_bucket[5m])); drop table histogram_bucket; @@ -122,16 +125,22 @@ insert into histogram2_bucket values (2700000, "+Inf", 30); -- Want results exactly in the middle of the bucket. +-- SQLNESS SORT_RESULT 3 1 tql eval (420, 420, '1s') histogram_quantile(0.166, histogram2_bucket); +-- SQLNESS SORT_RESULT 3 1 tql eval (420, 420, '1s') histogram_quantile(0.5, histogram2_bucket); +-- SQLNESS SORT_RESULT 3 1 tql eval (420, 420, '1s') histogram_quantile(0.833, histogram2_bucket); +-- SQLNESS SORT_RESULT 3 1 tql eval (2820, 2820, '1s') histogram_quantile(0.166, rate(histogram2_bucket[15m])); +-- SQLNESS SORT_RESULT 3 1 tql eval (2820, 2820, '1s') histogram_quantile(0.5, rate(histogram2_bucket[15m])); +-- SQLNESS SORT_RESULT 3 1 tql eval (2820, 2820, '1s') histogram_quantile(0.833, rate(histogram2_bucket[15m])); drop table histogram2_bucket; @@ -160,6 +169,7 @@ insert into histogram3_bucket values (3005000, "5", "a", 20), (3005000, "+Inf", "a", 30); +-- SQLNESS SORT_RESULT 3 1 tql eval (3000, 3005, '3s') histogram_quantile(0.5, sum by(le, s) (rate(histogram3_bucket[5m]))); drop table histogram3_bucket; @@ -201,8 +211,11 @@ CREATE TABLE greptime_servers_postgres_query_elapsed_no_le ( PRIMARY KEY (pod, instance) ); --- should return empty result instead of error when 'le' column is missing +-- should return empty result instead of error when 'le' column is missin +-- SQLNESS SORT_RESULT 3 1 tql eval(0, 10, '10s') histogram_quantile(0.99, sum by(pod,instance, le) (rate(greptime_servers_postgres_query_elapsed_no_le{instance=~"xxx"}[1m]))); + +-- SQLNESS SORT_RESULT 3 1 tql eval(0, 10, '10s') histogram_quantile(0.99, sum by(pod,instance, fbf) (rate(greptime_servers_postgres_query_elapsed_no_le{instance=~"xxx"}[1m]))); drop table greptime_servers_postgres_query_elapsed_no_le;