diff --git a/src/promql/src/extension_plan/series_divide.rs b/src/promql/src/extension_plan/series_divide.rs index e0e0172d4f..b24c53397f 100644 --- a/src/promql/src/extension_plan/series_divide.rs +++ b/src/promql/src/extension_plan/series_divide.rs @@ -34,6 +34,7 @@ use datafusion::physical_plan::{ SendableRecordBatchStream, }; use datatypes::arrow::compute; +use datatypes::compute::SortOptions; use futures::{ready, Stream, StreamExt}; use greptime_proto::substrait_extension as pb; use prost::Message; @@ -157,7 +158,10 @@ impl ExecutionPlan for SeriesDivideExec { .map(|tag| PhysicalSortRequirement { // Safety: the tag column names is verified in the planning phase expr: Arc::new(ColumnExpr::new_with_schema(tag, &input_schema).unwrap()), - options: None, + options: Some(SortOptions { + descending: true, + nulls_first: false, + }), }) .collect(); if !exprs.is_empty() { diff --git a/src/query/src/dist_plan/merge_scan.rs b/src/query/src/dist_plan/merge_scan.rs index 47a9512583..dd42406b5f 100644 --- a/src/query/src/dist_plan/merge_scan.rs +++ b/src/query/src/dist_plan/merge_scan.rs @@ -121,6 +121,7 @@ impl MergeScanLogicalPlan { &self.input } } + pub struct MergeScanExec { table: TableName, regions: Vec, diff --git a/src/query/src/promql/planner.rs b/src/query/src/promql/planner.rs index 22477d5049..0942fee15c 100644 --- a/src/query/src/promql/planner.rs +++ b/src/query/src/promql/planner.rs @@ -285,7 +285,7 @@ impl PromPlanner { let group_sort_expr = group_exprs .clone() .into_iter() - .map(|expr| expr.sort(true, false)); + .map(|expr| expr.sort(false, false)); LogicalPlanBuilder::from(input) .aggregate(group_exprs.clone(), aggr_exprs) .context(DataFusionPlanningSnafu)? @@ -363,7 +363,7 @@ impl PromPlanner { let group_sort_expr = new_group_exprs .into_iter() - .map(|expr| expr.sort(true, false)); + .map(|expr| expr.sort(false, false)); let project_fields = self .create_field_column_exprs()? @@ -3258,7 +3258,7 @@ mod test { .await .unwrap(); let expected_no_without = String::from( - "Sort: some_metric.tag_1 ASC NULLS LAST, some_metric.timestamp ASC NULLS LAST [tag_1:Utf8, timestamp:Timestamp(Millisecond, None), TEMPLATE(some_metric.field_0):Float64;N, TEMPLATE(some_metric.field_1):Float64;N]\ + "Sort: some_metric.tag_1 DESC NULLS LAST, some_metric.timestamp DESC NULLS LAST [tag_1:Utf8, timestamp:Timestamp(Millisecond, None), TEMPLATE(some_metric.field_0):Float64;N, TEMPLATE(some_metric.field_1):Float64;N]\ \n Aggregate: groupBy=[[some_metric.tag_1, some_metric.timestamp]], aggr=[[TEMPLATE(some_metric.field_0), TEMPLATE(some_metric.field_1)]] [tag_1:Utf8, timestamp:Timestamp(Millisecond, None), TEMPLATE(some_metric.field_0):Float64;N, TEMPLATE(some_metric.field_1):Float64;N]\ \n PromInstantManipulate: range=[0..100000000], lookback=[1000], interval=[5000], time index=[timestamp] [tag_0:Utf8, tag_1:Utf8, timestamp:Timestamp(Millisecond, None), field_0:Float64;N, field_1:Float64;N]\ \n PromSeriesNormalize: offset=[0], time index=[timestamp], filter NaN: [false] [tag_0:Utf8, tag_1:Utf8, timestamp:Timestamp(Millisecond, None), field_0:Float64;N, field_1:Float64;N]\ @@ -3288,7 +3288,7 @@ mod test { .await .unwrap(); let expected_without = String::from( - "Sort: some_metric.tag_0 ASC NULLS LAST, some_metric.timestamp ASC NULLS LAST [tag_0:Utf8, timestamp:Timestamp(Millisecond, None), TEMPLATE(some_metric.field_0):Float64;N, TEMPLATE(some_metric.field_1):Float64;N]\ + "Sort: some_metric.tag_0 DESC NULLS LAST, some_metric.timestamp DESC NULLS LAST [tag_0:Utf8, timestamp:Timestamp(Millisecond, None), TEMPLATE(some_metric.field_0):Float64;N, TEMPLATE(some_metric.field_1):Float64;N]\ \n Aggregate: groupBy=[[some_metric.tag_0, some_metric.timestamp]], aggr=[[TEMPLATE(some_metric.field_0), TEMPLATE(some_metric.field_1)]] [tag_0:Utf8, timestamp:Timestamp(Millisecond, None), TEMPLATE(some_metric.field_0):Float64;N, TEMPLATE(some_metric.field_1):Float64;N]\ \n PromInstantManipulate: range=[0..100000000], lookback=[1000], interval=[5000], time index=[timestamp] [tag_0:Utf8, tag_1:Utf8, timestamp:Timestamp(Millisecond, None), field_0:Float64;N, field_1:Float64;N]\ \n PromSeriesNormalize: offset=[0], time index=[timestamp], filter NaN: [false] [tag_0:Utf8, tag_1:Utf8, timestamp:Timestamp(Millisecond, None), field_0:Float64;N, field_1:Float64;N]\ @@ -4189,7 +4189,7 @@ mod test { let plan = PromPlanner::stmt_to_plan(table_provider, &eval_stmt, &build_session_state()) .await .unwrap(); - let expected = r#"Sort: prometheus_tsdb_head_series.timestamp ASC NULLS LAST [timestamp:Timestamp(Millisecond, None), sum(prometheus_tsdb_head_series.field_0):Float64;N, sum(prometheus_tsdb_head_series.field_1):Float64;N, sum(prometheus_tsdb_head_series.field_2):Float64;N] + let expected = r#"Sort: prometheus_tsdb_head_series.timestamp DESC NULLS LAST [timestamp:Timestamp(Millisecond, None), sum(prometheus_tsdb_head_series.field_0):Float64;N, sum(prometheus_tsdb_head_series.field_1):Float64;N, sum(prometheus_tsdb_head_series.field_2):Float64;N] Aggregate: groupBy=[[prometheus_tsdb_head_series.timestamp]], aggr=[[sum(prometheus_tsdb_head_series.field_0), sum(prometheus_tsdb_head_series.field_1), sum(prometheus_tsdb_head_series.field_2)]] [timestamp:Timestamp(Millisecond, None), sum(prometheus_tsdb_head_series.field_0):Float64;N, sum(prometheus_tsdb_head_series.field_1):Float64;N, sum(prometheus_tsdb_head_series.field_2):Float64;N] PromInstantManipulate: range=[0..100000000], lookback=[1000], interval=[5000], time index=[timestamp] [tag_0:Utf8, tag_1:Utf8, tag_2:Utf8, timestamp:Timestamp(Millisecond, None), field_0:Float64;N, field_1:Float64;N, field_2:Float64;N] PromSeriesNormalize: offset=[0], time index=[timestamp], filter NaN: [false] [tag_0:Utf8, tag_1:Utf8, tag_2:Utf8, timestamp:Timestamp(Millisecond, None), field_0:Float64;N, field_1:Float64;N, field_2:Float64;N] @@ -4234,10 +4234,10 @@ mod test { .await .unwrap(); let expected = r#"Projection: sum(prometheus_tsdb_head_series.greptime_value), prometheus_tsdb_head_series.ip, prometheus_tsdb_head_series.greptime_timestamp [sum(prometheus_tsdb_head_series.greptime_value):Float64;N, ip:Utf8, greptime_timestamp:Timestamp(Millisecond, None)] - Sort: prometheus_tsdb_head_series.greptime_timestamp ASC NULLS LAST, row_number() PARTITION BY [prometheus_tsdb_head_series.greptime_timestamp] ORDER BY [sum(prometheus_tsdb_head_series.greptime_value) DESC NULLS LAST, prometheus_tsdb_head_series.ip DESC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ASC NULLS LAST [ip:Utf8, greptime_timestamp:Timestamp(Millisecond, None), sum(prometheus_tsdb_head_series.greptime_value):Float64;N, row_number() PARTITION BY [prometheus_tsdb_head_series.greptime_timestamp] ORDER BY [sum(prometheus_tsdb_head_series.greptime_value) DESC NULLS LAST, prometheus_tsdb_head_series.ip DESC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW:UInt64] + Sort: prometheus_tsdb_head_series.greptime_timestamp DESC NULLS LAST, row_number() PARTITION BY [prometheus_tsdb_head_series.greptime_timestamp] ORDER BY [sum(prometheus_tsdb_head_series.greptime_value) DESC NULLS LAST, prometheus_tsdb_head_series.ip DESC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW DESC NULLS LAST [ip:Utf8, greptime_timestamp:Timestamp(Millisecond, None), sum(prometheus_tsdb_head_series.greptime_value):Float64;N, row_number() PARTITION BY [prometheus_tsdb_head_series.greptime_timestamp] ORDER BY [sum(prometheus_tsdb_head_series.greptime_value) DESC NULLS LAST, prometheus_tsdb_head_series.ip DESC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW:UInt64] Filter: row_number() PARTITION BY [prometheus_tsdb_head_series.greptime_timestamp] ORDER BY [sum(prometheus_tsdb_head_series.greptime_value) DESC NULLS LAST, prometheus_tsdb_head_series.ip DESC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW <= Float64(10) [ip:Utf8, greptime_timestamp:Timestamp(Millisecond, None), sum(prometheus_tsdb_head_series.greptime_value):Float64;N, row_number() PARTITION BY [prometheus_tsdb_head_series.greptime_timestamp] ORDER BY [sum(prometheus_tsdb_head_series.greptime_value) DESC NULLS LAST, prometheus_tsdb_head_series.ip DESC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW:UInt64] WindowAggr: windowExpr=[[row_number() PARTITION BY [prometheus_tsdb_head_series.greptime_timestamp] ORDER BY [sum(prometheus_tsdb_head_series.greptime_value) DESC NULLS LAST, prometheus_tsdb_head_series.ip DESC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW]] [ip:Utf8, greptime_timestamp:Timestamp(Millisecond, None), sum(prometheus_tsdb_head_series.greptime_value):Float64;N, row_number() PARTITION BY [prometheus_tsdb_head_series.greptime_timestamp] ORDER BY [sum(prometheus_tsdb_head_series.greptime_value) DESC NULLS LAST, prometheus_tsdb_head_series.ip DESC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW:UInt64] - Sort: prometheus_tsdb_head_series.ip ASC NULLS LAST, prometheus_tsdb_head_series.greptime_timestamp ASC NULLS LAST [ip:Utf8, greptime_timestamp:Timestamp(Millisecond, None), sum(prometheus_tsdb_head_series.greptime_value):Float64;N] + Sort: prometheus_tsdb_head_series.ip DESC NULLS LAST, prometheus_tsdb_head_series.greptime_timestamp DESC NULLS LAST [ip:Utf8, greptime_timestamp:Timestamp(Millisecond, None), sum(prometheus_tsdb_head_series.greptime_value):Float64;N] Aggregate: groupBy=[[prometheus_tsdb_head_series.ip, prometheus_tsdb_head_series.greptime_timestamp]], aggr=[[sum(prometheus_tsdb_head_series.greptime_value)]] [ip:Utf8, greptime_timestamp:Timestamp(Millisecond, None), sum(prometheus_tsdb_head_series.greptime_value):Float64;N] PromInstantManipulate: range=[0..100000000], lookback=[1000], interval=[5000], time index=[greptime_timestamp] [ip:Utf8, greptime_timestamp:Timestamp(Millisecond, None), greptime_value:Float64;N] PromSeriesNormalize: offset=[0], time index=[greptime_timestamp], filter NaN: [false] [ip:Utf8, greptime_timestamp:Timestamp(Millisecond, None), greptime_value:Float64;N] diff --git a/tests-integration/tests/grpc.rs b/tests-integration/tests/grpc.rs index 11db34acb8..425b3b8d5d 100644 --- a/tests-integration/tests/grpc.rs +++ b/tests-integration/tests/grpc.rs @@ -657,15 +657,6 @@ pub async fn test_prom_gateway_query(store_type: StorageType) { data: PrometheusResponse::PromData(PromData { result_type: "vector".to_string(), result: PromQueryResult::Vector(vec![ - PromSeriesVector { - metric: [ - ("k".to_string(), "a".to_string()), - ("__name__".to_string(), "test".to_string()), - ] - .into_iter() - .collect(), - value: Some((5.0, "2".to_string())), - }, PromSeriesVector { metric: [ ("__name__".to_string(), "test".to_string()), @@ -675,6 +666,15 @@ pub async fn test_prom_gateway_query(store_type: StorageType) { .collect(), value: Some((5.0, "1".to_string())), }, + PromSeriesVector { + metric: [ + ("k".to_string(), "a".to_string()), + ("__name__".to_string(), "test".to_string()), + ] + .into_iter() + .collect(), + value: Some((5.0, "2".to_string())), + }, ]), }), error: None, @@ -709,15 +709,6 @@ pub async fn test_prom_gateway_query(store_type: StorageType) { data: PrometheusResponse::PromData(PromData { result_type: "matrix".to_string(), result: PromQueryResult::Matrix(vec![ - PromSeriesMatrix { - metric: [ - ("__name__".to_string(), "test".to_string()), - ("k".to_string(), "a".to_string()), - ] - .into_iter() - .collect(), - values: vec![(5.0, "2".to_string()), (10.0, "2".to_string())], - }, PromSeriesMatrix { metric: [ ("__name__".to_string(), "test".to_string()), @@ -727,6 +718,15 @@ pub async fn test_prom_gateway_query(store_type: StorageType) { .collect(), values: vec![(5.0, "1".to_string()), (10.0, "1".to_string())], }, + PromSeriesMatrix { + metric: [ + ("__name__".to_string(), "test".to_string()), + ("k".to_string(), "a".to_string()), + ] + .into_iter() + .collect(), + values: vec![(5.0, "2".to_string()), (10.0, "2".to_string())], + }, ]), }), error: None, diff --git a/tests/cases/standalone/common/promql/topk_bottomk.result b/tests/cases/standalone/common/promql/topk_bottomk.result index 978c2b1968..d181a464c9 100644 --- a/tests/cases/standalone/common/promql/topk_bottomk.result +++ b/tests/cases/standalone/common/promql/topk_bottomk.result @@ -30,10 +30,10 @@ TQL EVAL (0, 15, '5s') topk(1, test); +-----+-------+------+---------------------+ | val | host | idc | ts | +-----+-------+------+---------------------+ -| 3 | host3 | idc2 | 1970-01-01T00:00:00 | -| 4 | host2 | idc1 | 1970-01-01T00:00:05 | -| 5 | host2 | idc1 | 1970-01-01T00:00:10 | | 3 | host3 | idc2 | 1970-01-01T00:00:15 | +| 5 | host2 | idc1 | 1970-01-01T00:00:10 | +| 4 | host2 | idc1 | 1970-01-01T00:00:05 | +| 3 | host3 | idc2 | 1970-01-01T00:00:00 | +-----+-------+------+---------------------+ TQL EVAL (0, 15, '5s') topk(3, test); @@ -41,18 +41,18 @@ TQL EVAL (0, 15, '5s') topk(3, test); +-----+-------+------+---------------------+ | val | host | idc | ts | +-----+-------+------+---------------------+ -| 3 | host3 | idc2 | 1970-01-01T00:00:00 | -| 2 | host2 | idc1 | 1970-01-01T00:00:00 | -| 1 | host1 | idc1 | 1970-01-01T00:00:00 | -| 4 | host2 | idc1 | 1970-01-01T00:00:05 | -| 1 | host3 | idc2 | 1970-01-01T00:00:05 | -| 1 | host1 | idc1 | 1970-01-01T00:00:05 | -| 5 | host2 | idc1 | 1970-01-01T00:00:10 | -| 3 | host3 | idc2 | 1970-01-01T00:00:10 | -| 3 | host1 | idc1 | 1970-01-01T00:00:10 | -| 3 | host3 | idc2 | 1970-01-01T00:00:15 | -| 2 | host2 | idc1 | 1970-01-01T00:00:15 | | 1 | host1 | idc1 | 1970-01-01T00:00:15 | +| 2 | host2 | idc1 | 1970-01-01T00:00:15 | +| 3 | host3 | idc2 | 1970-01-01T00:00:15 | +| 3 | host1 | idc1 | 1970-01-01T00:00:10 | +| 3 | host3 | idc2 | 1970-01-01T00:00:10 | +| 5 | host2 | idc1 | 1970-01-01T00:00:10 | +| 1 | host1 | idc1 | 1970-01-01T00:00:05 | +| 1 | host3 | idc2 | 1970-01-01T00:00:05 | +| 4 | host2 | idc1 | 1970-01-01T00:00:05 | +| 1 | host1 | idc1 | 1970-01-01T00:00:00 | +| 2 | host2 | idc1 | 1970-01-01T00:00:00 | +| 3 | host3 | idc2 | 1970-01-01T00:00:00 | +-----+-------+------+---------------------+ TQL EVAL (0, 15, '5s') topk(1, sum(test) by (idc)); @@ -60,10 +60,10 @@ TQL EVAL (0, 15, '5s') topk(1, sum(test) by (idc)); +---------------+------+---------------------+ | sum(test.val) | idc | ts | +---------------+------+---------------------+ -| 3 | idc2 | 1970-01-01T00:00:00 | -| 5 | idc1 | 1970-01-01T00:00:05 | -| 8 | idc1 | 1970-01-01T00:00:10 | | 3 | idc2 | 1970-01-01T00:00:15 | +| 8 | idc1 | 1970-01-01T00:00:10 | +| 5 | idc1 | 1970-01-01T00:00:05 | +| 3 | idc2 | 1970-01-01T00:00:00 | +---------------+------+---------------------+ TQL EVAL (0, 15, '5s') topk(2, sum(test) by (idc)); @@ -71,14 +71,14 @@ TQL EVAL (0, 15, '5s') topk(2, sum(test) by (idc)); +---------------+------+---------------------+ | sum(test.val) | idc | ts | +---------------+------+---------------------+ -| 3 | idc2 | 1970-01-01T00:00:00 | -| 3 | idc1 | 1970-01-01T00:00:00 | -| 5 | idc1 | 1970-01-01T00:00:05 | -| 1 | idc2 | 1970-01-01T00:00:05 | -| 8 | idc1 | 1970-01-01T00:00:10 | -| 3 | idc2 | 1970-01-01T00:00:10 | -| 3 | idc2 | 1970-01-01T00:00:15 | | 3 | idc1 | 1970-01-01T00:00:15 | +| 3 | idc2 | 1970-01-01T00:00:15 | +| 3 | idc2 | 1970-01-01T00:00:10 | +| 8 | idc1 | 1970-01-01T00:00:10 | +| 1 | idc2 | 1970-01-01T00:00:05 | +| 5 | idc1 | 1970-01-01T00:00:05 | +| 3 | idc1 | 1970-01-01T00:00:00 | +| 3 | idc2 | 1970-01-01T00:00:00 | +---------------+------+---------------------+ TQL EVAL (0, 15, '5s') bottomk(1, test); @@ -86,10 +86,10 @@ TQL EVAL (0, 15, '5s') bottomk(1, test); +-----+-------+------+---------------------+ | val | host | idc | ts | +-----+-------+------+---------------------+ -| 1 | host1 | idc1 | 1970-01-01T00:00:00 | -| 1 | host1 | idc1 | 1970-01-01T00:00:05 | -| 3 | host1 | idc1 | 1970-01-01T00:00:10 | | 1 | host1 | idc1 | 1970-01-01T00:00:15 | +| 3 | host1 | idc1 | 1970-01-01T00:00:10 | +| 1 | host1 | idc1 | 1970-01-01T00:00:05 | +| 1 | host1 | idc1 | 1970-01-01T00:00:00 | +-----+-------+------+---------------------+ TQL EVAL (0, 15, '5s') bottomk(3, test); @@ -97,18 +97,18 @@ TQL EVAL (0, 15, '5s') bottomk(3, test); +-----+-------+------+---------------------+ | val | host | idc | ts | +-----+-------+------+---------------------+ -| 1 | host1 | idc1 | 1970-01-01T00:00:00 | -| 2 | host2 | idc1 | 1970-01-01T00:00:00 | -| 3 | host3 | idc2 | 1970-01-01T00:00:00 | -| 1 | host1 | idc1 | 1970-01-01T00:00:05 | -| 1 | host3 | idc2 | 1970-01-01T00:00:05 | -| 4 | host2 | idc1 | 1970-01-01T00:00:05 | -| 3 | host1 | idc1 | 1970-01-01T00:00:10 | -| 3 | host3 | idc2 | 1970-01-01T00:00:10 | -| 5 | host2 | idc1 | 1970-01-01T00:00:10 | -| 1 | host1 | idc1 | 1970-01-01T00:00:15 | -| 2 | host2 | idc1 | 1970-01-01T00:00:15 | | 3 | host3 | idc2 | 1970-01-01T00:00:15 | +| 2 | host2 | idc1 | 1970-01-01T00:00:15 | +| 1 | host1 | idc1 | 1970-01-01T00:00:15 | +| 5 | host2 | idc1 | 1970-01-01T00:00:10 | +| 3 | host3 | idc2 | 1970-01-01T00:00:10 | +| 3 | host1 | idc1 | 1970-01-01T00:00:10 | +| 4 | host2 | idc1 | 1970-01-01T00:00:05 | +| 1 | host3 | idc2 | 1970-01-01T00:00:05 | +| 1 | host1 | idc1 | 1970-01-01T00:00:05 | +| 3 | host3 | idc2 | 1970-01-01T00:00:00 | +| 2 | host2 | idc1 | 1970-01-01T00:00:00 | +| 1 | host1 | idc1 | 1970-01-01T00:00:00 | +-----+-------+------+---------------------+ TQL EVAL (0, 15, '5s') bottomk(1, sum(test) by (idc)); @@ -116,10 +116,10 @@ TQL EVAL (0, 15, '5s') bottomk(1, sum(test) by (idc)); +---------------+------+---------------------+ | sum(test.val) | idc | ts | +---------------+------+---------------------+ -| 3 | idc1 | 1970-01-01T00:00:00 | -| 1 | idc2 | 1970-01-01T00:00:05 | -| 3 | idc2 | 1970-01-01T00:00:10 | | 3 | idc1 | 1970-01-01T00:00:15 | +| 3 | idc2 | 1970-01-01T00:00:10 | +| 1 | idc2 | 1970-01-01T00:00:05 | +| 3 | idc1 | 1970-01-01T00:00:00 | +---------------+------+---------------------+ TQL EVAL (0, 15, '5s') bottomk(2, sum(test) by (idc)); @@ -127,14 +127,14 @@ TQL EVAL (0, 15, '5s') bottomk(2, sum(test) by (idc)); +---------------+------+---------------------+ | sum(test.val) | idc | ts | +---------------+------+---------------------+ -| 3 | idc1 | 1970-01-01T00:00:00 | -| 3 | idc2 | 1970-01-01T00:00:00 | -| 1 | idc2 | 1970-01-01T00:00:05 | -| 5 | idc1 | 1970-01-01T00:00:05 | -| 3 | idc2 | 1970-01-01T00:00:10 | -| 8 | idc1 | 1970-01-01T00:00:10 | -| 3 | idc1 | 1970-01-01T00:00:15 | | 3 | idc2 | 1970-01-01T00:00:15 | +| 3 | idc1 | 1970-01-01T00:00:15 | +| 8 | idc1 | 1970-01-01T00:00:10 | +| 3 | idc2 | 1970-01-01T00:00:10 | +| 5 | idc1 | 1970-01-01T00:00:05 | +| 1 | idc2 | 1970-01-01T00:00:05 | +| 3 | idc2 | 1970-01-01T00:00:00 | +| 3 | idc1 | 1970-01-01T00:00:00 | +---------------+------+---------------------+ DROP table test; @@ -178,10 +178,10 @@ TQL EVAL (0, 15, '5s') topk(1, sum(test{__field__='cpu'}) by (idc)); +---------------+------+---------------------+ | sum(test.cpu) | idc | ts | +---------------+------+---------------------+ -| 3 | idc2 | 1970-01-01T00:00:00 | -| 5 | idc1 | 1970-01-01T00:00:05 | -| 8 | idc1 | 1970-01-01T00:00:10 | | 3 | idc2 | 1970-01-01T00:00:15 | +| 8 | idc1 | 1970-01-01T00:00:10 | +| 5 | idc1 | 1970-01-01T00:00:05 | +| 3 | idc2 | 1970-01-01T00:00:00 | +---------------+------+---------------------+ TQL EVAL (0, 15, '5s') topk(1, sum(test{__field__='mem'}) by (idc)); @@ -189,10 +189,10 @@ TQL EVAL (0, 15, '5s') topk(1, sum(test{__field__='mem'}) by (idc)); +---------------+------+---------------------+ | sum(test.mem) | idc | ts | +---------------+------+---------------------+ -| 5 | idc1 | 1970-01-01T00:00:00 | -| 5 | idc1 | 1970-01-01T00:00:05 | -| 8 | idc1 | 1970-01-01T00:00:10 | | 5 | idc1 | 1970-01-01T00:00:15 | +| 8 | idc1 | 1970-01-01T00:00:10 | +| 5 | idc1 | 1970-01-01T00:00:05 | +| 5 | idc1 | 1970-01-01T00:00:00 | +---------------+------+---------------------+ TQL EVAL (0, 15, '5s') bottomk(1, sum(test{__field__='cpu'}) by (idc)); @@ -200,10 +200,10 @@ TQL EVAL (0, 15, '5s') bottomk(1, sum(test{__field__='cpu'}) by (idc)); +---------------+------+---------------------+ | sum(test.cpu) | idc | ts | +---------------+------+---------------------+ -| 3 | idc1 | 1970-01-01T00:00:00 | -| 1 | idc2 | 1970-01-01T00:00:05 | -| 3 | idc2 | 1970-01-01T00:00:10 | | 3 | idc1 | 1970-01-01T00:00:15 | +| 3 | idc2 | 1970-01-01T00:00:10 | +| 1 | idc2 | 1970-01-01T00:00:05 | +| 3 | idc1 | 1970-01-01T00:00:00 | +---------------+------+---------------------+ TQL EVAL (0, 15, '5s') bottomk(1, sum(test{__field__='mem'}) by (idc)); @@ -211,10 +211,10 @@ TQL EVAL (0, 15, '5s') bottomk(1, sum(test{__field__='mem'}) by (idc)); +---------------+------+---------------------+ | sum(test.mem) | idc | ts | +---------------+------+---------------------+ -| 1 | idc2 | 1970-01-01T00:00:00 | -| 1 | idc2 | 1970-01-01T00:00:05 | -| 3 | idc2 | 1970-01-01T00:00:10 | | 1 | idc2 | 1970-01-01T00:00:15 | +| 3 | idc2 | 1970-01-01T00:00:10 | +| 1 | idc2 | 1970-01-01T00:00:05 | +| 1 | idc2 | 1970-01-01T00:00:00 | +---------------+------+---------------------+ DROP table test; diff --git a/tests/cases/standalone/common/select/tql_filter.result b/tests/cases/standalone/common/select/tql_filter.result index ffd221887a..7b4a7f8b5d 100644 --- a/tests/cases/standalone/common/select/tql_filter.result +++ b/tests/cases/standalone/common/select/tql_filter.result @@ -20,8 +20,8 @@ tql analyze (1, 3, '1s') t1{ a = "a" }; | 0_| 0_|_PromInstantManipulateExec: range=[1000..3000], lookback=[300000], interval=[1000], time index=[b] REDACTED |_|_|_PromSeriesNormalizeExec: offset=[0], time index=[b], filter NaN: [false] REDACTED |_|_|_PromSeriesDivideExec: tags=["a"] REDACTED -|_|_|_SortPreservingMergeExec: [a@0 ASC NULLS LAST] REDACTED -|_|_|_SortExec: expr=[a@0 ASC NULLS LAST], preserve_partitioning=[true] REDACTED +|_|_|_SortPreservingMergeExec: [a@0 DESC NULLS LAST] REDACTED +|_|_|_SortExec: expr=[a@0 DESC NULLS LAST], preserve_partitioning=[true] REDACTED |_|_|_MergeScanExec: REDACTED |_|_|_| | 1_| 0_|_SortPreservingMergeExec: [a@0 DESC NULLS LAST, b@1 DESC NULLS LAST] REDACTED @@ -48,8 +48,8 @@ tql analyze (1, 3, '1s') t1{ a =~ ".*" }; | 0_| 0_|_PromInstantManipulateExec: range=[1000..3000], lookback=[300000], interval=[1000], time index=[b] REDACTED |_|_|_PromSeriesNormalizeExec: offset=[0], time index=[b], filter NaN: [false] REDACTED |_|_|_PromSeriesDivideExec: tags=["a"] REDACTED -|_|_|_SortPreservingMergeExec: [a@0 ASC NULLS LAST] REDACTED -|_|_|_SortExec: expr=[a@0 ASC NULLS LAST], preserve_partitioning=[true] REDACTED +|_|_|_SortPreservingMergeExec: [a@0 DESC NULLS LAST] REDACTED +|_|_|_SortExec: expr=[a@0 DESC NULLS LAST], preserve_partitioning=[true] REDACTED |_|_|_MergeScanExec: REDACTED |_|_|_| | 1_| 0_|_SortPreservingMergeExec: [a@0 DESC NULLS LAST, b@1 DESC NULLS LAST] REDACTED @@ -76,8 +76,8 @@ tql analyze (1, 3, '1s') t1{ a =~ "a.*" }; | 0_| 0_|_PromInstantManipulateExec: range=[1000..3000], lookback=[300000], interval=[1000], time index=[b] REDACTED |_|_|_PromSeriesNormalizeExec: offset=[0], time index=[b], filter NaN: [false] REDACTED |_|_|_PromSeriesDivideExec: tags=["a"] REDACTED -|_|_|_SortPreservingMergeExec: [a@0 ASC NULLS LAST] REDACTED -|_|_|_SortExec: expr=[a@0 ASC NULLS LAST], preserve_partitioning=[true] REDACTED +|_|_|_SortPreservingMergeExec: [a@0 DESC NULLS LAST] REDACTED +|_|_|_SortExec: expr=[a@0 DESC NULLS LAST], preserve_partitioning=[true] REDACTED |_|_|_MergeScanExec: REDACTED |_|_|_| | 1_| 0_|_SortPreservingMergeExec: [a@0 DESC NULLS LAST, b@1 DESC NULLS LAST] REDACTED diff --git a/tests/cases/standalone/common/tql-explain-analyze/analyze.result b/tests/cases/standalone/common/tql-explain-analyze/analyze.result index b40f30f2c1..4707c3c44e 100644 --- a/tests/cases/standalone/common/tql-explain-analyze/analyze.result +++ b/tests/cases/standalone/common/tql-explain-analyze/analyze.result @@ -22,8 +22,8 @@ TQL ANALYZE (0, 10, '5s') test; | 0_| 0_|_PromInstantManipulateExec: range=[0..10000], lookback=[300000], interval=[5000], time index=[j] REDACTED |_|_|_PromSeriesNormalizeExec: offset=[0], time index=[j], filter NaN: [false] REDACTED |_|_|_PromSeriesDivideExec: tags=["k"] REDACTED -|_|_|_SortPreservingMergeExec: [k@2 ASC NULLS LAST] REDACTED -|_|_|_SortExec: expr=[k@2 ASC NULLS LAST], preserve_partitioning=[true] REDACTED +|_|_|_SortPreservingMergeExec: [k@2 DESC NULLS LAST] REDACTED +|_|_|_SortExec: expr=[k@2 DESC NULLS LAST], preserve_partitioning=[true] REDACTED |_|_|_MergeScanExec: REDACTED |_|_|_| | 1_| 0_|_SortPreservingMergeExec: [k@2 DESC NULLS LAST, j@1 DESC NULLS LAST] REDACTED @@ -52,8 +52,8 @@ TQL ANALYZE (0, 10, '1s', '2s') test; | 0_| 0_|_PromInstantManipulateExec: range=[0..10000], lookback=[2000], interval=[1000], time index=[j] REDACTED |_|_|_PromSeriesNormalizeExec: offset=[0], time index=[j], filter NaN: [false] REDACTED |_|_|_PromSeriesDivideExec: tags=["k"] REDACTED -|_|_|_SortPreservingMergeExec: [k@2 ASC NULLS LAST] REDACTED -|_|_|_SortExec: expr=[k@2 ASC NULLS LAST], preserve_partitioning=[true] REDACTED +|_|_|_SortPreservingMergeExec: [k@2 DESC NULLS LAST] REDACTED +|_|_|_SortExec: expr=[k@2 DESC NULLS LAST], preserve_partitioning=[true] REDACTED |_|_|_MergeScanExec: REDACTED |_|_|_| | 1_| 0_|_SortPreservingMergeExec: [k@2 DESC NULLS LAST, j@1 DESC NULLS LAST] REDACTED @@ -81,8 +81,8 @@ TQL ANALYZE ('1970-01-01T00:00:00'::timestamp, '1970-01-01T00:00:00'::timestamp | 0_| 0_|_PromInstantManipulateExec: range=[0..10000], lookback=[300000], interval=[5000], time index=[j] REDACTED |_|_|_PromSeriesNormalizeExec: offset=[0], time index=[j], filter NaN: [false] REDACTED |_|_|_PromSeriesDivideExec: tags=["k"] REDACTED -|_|_|_SortPreservingMergeExec: [k@2 ASC NULLS LAST] REDACTED -|_|_|_SortExec: expr=[k@2 ASC NULLS LAST], preserve_partitioning=[true] REDACTED +|_|_|_SortPreservingMergeExec: [k@2 DESC NULLS LAST] REDACTED +|_|_|_SortExec: expr=[k@2 DESC NULLS LAST], preserve_partitioning=[true] REDACTED |_|_|_MergeScanExec: REDACTED |_|_|_| | 1_| 0_|_SortPreservingMergeExec: [k@2 DESC NULLS LAST, j@1 DESC NULLS LAST] REDACTED @@ -112,8 +112,8 @@ TQL ANALYZE VERBOSE (0, 10, '5s') test; | 0_| 0_|_PromInstantManipulateExec: range=[0..10000], lookback=[300000], interval=[5000], time index=[j] REDACTED |_|_|_PromSeriesNormalizeExec: offset=[0], time index=[j], filter NaN: [false] REDACTED |_|_|_PromSeriesDivideExec: tags=["k"] REDACTED -|_|_|_SortPreservingMergeExec: [k@2 ASC NULLS LAST] REDACTED -|_|_|_SortExec: expr=[k@2 ASC NULLS LAST], preserve_partitioning=[true] REDACTED +|_|_|_SortPreservingMergeExec: [k@2 DESC NULLS LAST] REDACTED +|_|_|_SortExec: expr=[k@2 DESC NULLS LAST], preserve_partitioning=[true] REDACTED |_|_|_MergeScanExec: REDACTED |_|_|_| | 1_| 0_|_SortPreservingMergeExec: [k@2 DESC NULLS LAST, j@1 DESC NULLS LAST] REDACTED diff --git a/tests/cases/standalone/common/tql-explain-analyze/explain.result b/tests/cases/standalone/common/tql-explain-analyze/explain.result index 68be4f7ee2..02b11abb18 100644 --- a/tests/cases/standalone/common/tql-explain-analyze/explain.result +++ b/tests/cases/standalone/common/tql-explain-analyze/explain.result @@ -22,8 +22,8 @@ TQL EXPLAIN (0, 10, '5s') test; | physical_plan | PromInstantManipulateExec: range=[0..0], lookback=[300000], interval=[300000], time index=[j] | | | PromSeriesNormalizeExec: offset=[0], time index=[j], filter NaN: [false] | | | PromSeriesDivideExec: tags=["k"] | -| | SortPreservingMergeExec: [k@2 ASC NULLS LAST] | -| | SortExec: expr=[k@2 ASC NULLS LAST], preserve_partitioning=[true] | +| | SortPreservingMergeExec: [k@2 DESC NULLS LAST] | +| | SortExec: expr=[k@2 DESC NULLS LAST], preserve_partitioning=[true] | | | MergeScanExec: REDACTED | | | +---------------+-----------------------------------------------------------------------------------------------+ @@ -44,8 +44,8 @@ TQL EXPLAIN (0, 10, '1s', '2s') test; | physical_plan | PromInstantManipulateExec: range=[0..0], lookback=[2000], interval=[300000], time index=[j] | | | PromSeriesNormalizeExec: offset=[0], time index=[j], filter NaN: [false] | | | PromSeriesDivideExec: tags=["k"] | -| | SortPreservingMergeExec: [k@2 ASC NULLS LAST] | -| | SortExec: expr=[k@2 ASC NULLS LAST], preserve_partitioning=[true] | +| | SortPreservingMergeExec: [k@2 DESC NULLS LAST] | +| | SortExec: expr=[k@2 DESC NULLS LAST], preserve_partitioning=[true] | | | MergeScanExec: REDACTED | | | +---------------+---------------------------------------------------------------------------------------------+ @@ -65,8 +65,8 @@ TQL EXPLAIN ('1970-01-01T00:00:00'::timestamp, '1970-01-01T00:00:00'::timestamp | physical_plan | PromInstantManipulateExec: range=[0..0], lookback=[300000], interval=[300000], time index=[j] | | | PromSeriesNormalizeExec: offset=[0], time index=[j], filter NaN: [false] | | | PromSeriesDivideExec: tags=["k"] | -| | SortPreservingMergeExec: [k@2 ASC NULLS LAST] | -| | SortExec: expr=[k@2 ASC NULLS LAST], preserve_partitioning=[true] | +| | SortPreservingMergeExec: [k@2 DESC NULLS LAST] | +| | SortExec: expr=[k@2 DESC NULLS LAST], preserve_partitioning=[true] | | | MergeScanExec: REDACTED | | | +---------------+-----------------------------------------------------------------------------------------------+ @@ -170,8 +170,8 @@ TQL EXPLAIN VERBOSE (0, 10, '5s') test; |_|_PromInstantManipulateExec: range=[0..0], lookback=[300000], interval=[300000], time index=[j]_| |_|_PromSeriesNormalizeExec: offset=[0], time index=[j], filter NaN: [false]_| |_|_PromSeriesDivideExec: tags=["k"]_| -|_|_SortPreservingMergeExec: [k@2 ASC NULLS LAST]_| -|_|_SortExec: expr=[k@2 ASC NULLS LAST], preserve_partitioning=[true]_| +|_|_SortPreservingMergeExec: [k@2 DESC NULLS LAST]_| +|_|_SortExec: expr=[k@2 DESC NULLS LAST], preserve_partitioning=[true]_| |_|_MergeScanExec: REDACTED |_|_| | physical_plan after OptimizeAggregateOrder_| SAME TEXT AS ABOVE_| @@ -180,8 +180,8 @@ TQL EXPLAIN VERBOSE (0, 10, '5s') test; | physical_plan after OutputRequirements_| PromInstantManipulateExec: range=[0..0], lookback=[300000], interval=[300000], time index=[j]_| |_|_PromSeriesNormalizeExec: offset=[0], time index=[j], filter NaN: [false]_| |_|_PromSeriesDivideExec: tags=["k"]_| -|_|_SortPreservingMergeExec: [k@2 ASC NULLS LAST]_| -|_|_SortExec: expr=[k@2 ASC NULLS LAST], preserve_partitioning=[true]_| +|_|_SortPreservingMergeExec: [k@2 DESC NULLS LAST]_| +|_|_SortExec: expr=[k@2 DESC NULLS LAST], preserve_partitioning=[true]_| |_|_MergeScanExec: REDACTED |_|_| | physical_plan after LimitAggregation_| SAME TEXT AS ABOVE_| @@ -193,22 +193,22 @@ TQL EXPLAIN VERBOSE (0, 10, '5s') test; | physical_plan_| PromInstantManipulateExec: range=[0..0], lookback=[300000], interval=[300000], time index=[j]_| |_|_PromSeriesNormalizeExec: offset=[0], time index=[j], filter NaN: [false]_| |_|_PromSeriesDivideExec: tags=["k"]_| -|_|_SortPreservingMergeExec: [k@2 ASC NULLS LAST]_| -|_|_SortExec: expr=[k@2 ASC NULLS LAST], preserve_partitioning=[true]_| +|_|_SortPreservingMergeExec: [k@2 DESC NULLS LAST]_| +|_|_SortExec: expr=[k@2 DESC NULLS LAST], preserve_partitioning=[true]_| |_|_MergeScanExec: REDACTED |_|_| | physical_plan_with_stats_| PromInstantManipulateExec: range=[0..0], lookback=[300000], interval=[300000], time index=[j], statistics=[Rows=Inexact(0), Bytes=Absent, [(Col[0]:),(Col[1]:),(Col[2]:)]] | |_|_PromSeriesNormalizeExec: offset=[0], time index=[j], filter NaN: [false], statistics=[Rows=Absent, Bytes=Absent, [(Col[0]:),(Col[1]:),(Col[2]:)]]_| |_|_PromSeriesDivideExec: tags=["k"], statistics=[Rows=Absent, Bytes=Absent, [(Col[0]:),(Col[1]:),(Col[2]:)]]_| -|_|_SortPreservingMergeExec: [k@2 ASC NULLS LAST], statistics=[Rows=Absent, Bytes=Absent, [(Col[0]:),(Col[1]:),(Col[2]:)]]_| -|_|_SortExec: expr=[k@2 ASC NULLS LAST], preserve_partitioning=[true], statistics=[Rows=Absent, Bytes=Absent, [(Col[0]:),(Col[1]:),(Col[2]:)]]_| +|_|_SortPreservingMergeExec: [k@2 DESC NULLS LAST], statistics=[Rows=Absent, Bytes=Absent, [(Col[0]:),(Col[1]:),(Col[2]:)]]_| +|_|_SortExec: expr=[k@2 DESC NULLS LAST], preserve_partitioning=[true], statistics=[Rows=Absent, Bytes=Absent, [(Col[0]:),(Col[1]:),(Col[2]:)]]_| |_|_MergeScanExec: REDACTED |_|_| | physical_plan_with_schema_| PromInstantManipulateExec: range=[0..0], lookback=[300000], interval=[300000], time index=[j], schema=[i:Float64;N, j:Timestamp(Millisecond, None), k:Utf8;N]_| |_|_PromSeriesNormalizeExec: offset=[0], time index=[j], filter NaN: [false], schema=[i:Float64;N, j:Timestamp(Millisecond, None), k:Utf8;N]_| |_|_PromSeriesDivideExec: tags=["k"], schema=[i:Float64;N, j:Timestamp(Millisecond, None), k:Utf8;N]_| -|_|_SortPreservingMergeExec: [k@2 ASC NULLS LAST], schema=[i:Float64;N, j:Timestamp(Millisecond, None), k:Utf8;N]_| -|_|_SortExec: expr=[k@2 ASC NULLS LAST], preserve_partitioning=[true], schema=[i:Float64;N, j:Timestamp(Millisecond, None), k:Utf8;N]_| +|_|_SortPreservingMergeExec: [k@2 DESC NULLS LAST], schema=[i:Float64;N, j:Timestamp(Millisecond, None), k:Utf8;N]_| +|_|_SortExec: expr=[k@2 DESC NULLS LAST], preserve_partitioning=[true], schema=[i:Float64;N, j:Timestamp(Millisecond, None), k:Utf8;N]_| |_|_MergeScanExec: REDACTED |_|_| +-+-+ diff --git a/tests/cases/standalone/common/tql/basic.result b/tests/cases/standalone/common/tql/basic.result index ca0c7c9252..c2add8827a 100644 --- a/tests/cases/standalone/common/tql/basic.result +++ b/tests/cases/standalone/common/tql/basic.result @@ -157,10 +157,10 @@ TQL EVAL (0, 10, '5s') test{__field__="Field_I"}; +---------+-------+---------------------+ | Field_I | Tag_K | Ts_J | +---------+-------+---------------------+ -| 2.0 | a | 1970-01-01T00:00:05 | -| 2.0 | a | 1970-01-01T00:00:10 | | 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 | +---------+-------+---------------------+ TQL EVAL (0, 10, '5s') test{__field__="field_i"};