fix: sort condition in HistogramFold (#2674)

* sort ts before le

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

* add test case

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

---------

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
Ruihang Xia
2023-11-01 16:28:53 +08:00
committed by GitHub
parent 5f3bbdca4f
commit a9137b77f0
3 changed files with 78 additions and 9 deletions
@@ -52,7 +52,7 @@ use futures::{ready, Stream, StreamExt};
/// Due to the folding or sampling, the output rows number will become `input_rows` / `bucket_num`.
///
/// # Requirement
/// - Input should be sorted on `<tag list>, le ASC, ts`.
/// - Input should be sorted on `<tag list>, ts, le ASC`.
/// - The value set of `le` should be same. I.e., buckets of every series should be same.
///
/// [1]: https://prometheus.io/docs/concepts/metric_types/#histogram
@@ -248,6 +248,14 @@ impl ExecutionPlan for HistogramFoldExec {
options: None,
})
.collect::<Vec<PhysicalSortRequirement>>();
// add ts
cols.push(PhysicalSortRequirement {
expr: Arc::new(PhyColumn::new(
self.input.schema().field(self.ts_column_index).name(),
self.ts_column_index,
)),
options: None,
});
// add le ASC
cols.push(PhysicalSortRequirement {
expr: Arc::new(PhyCast::new(
@@ -263,14 +271,6 @@ impl ExecutionPlan for HistogramFoldExec {
nulls_first: false, // not nullable
}),
});
// add ts
cols.push(PhysicalSortRequirement {
expr: Arc::new(PhyColumn::new(
self.input.schema().field(self.ts_column_index).name(),
self.ts_column_index,
)),
options: None,
});
vec![Some(cols)]
}