mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-12-04 00:15:29 +00:00
refactor(promql): type FusedSeries output modes and drop redundant checks (#10785)
- FusedSeriesExec picks its output kind (rows, evaluated, state) once; each stream pulls its own output from one shared driver, removing the mode bools, FusedOutput and the "cannot happen" adapter arms. - The evidence claim alone tracks completion; drop the duplicated flag, the extra Drop impl and the second Arc. - Remove the unused FusedSeriesExec::try_new, write-only matching_parallelism, and exec checks the logical node already makes (canonical producer format is now checked on decode). - Share router helpers in to_execution_plan, the plain-row classification, and the aggregate-state schema conversions. - split: compute the state binding at the cut so into_trees cannot return None or a missing-grid error. - Trim restating comments. Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -26,12 +26,13 @@ use std::sync::Arc;
|
||||
|
||||
use datafusion::error::{DataFusionError, Result as DfResult};
|
||||
use datatypes::series::SeriesOrdering;
|
||||
use datatypes::series::aggregate_state::{AggregateStateKind, StateComponent};
|
||||
use datatypes::series::samples::{FieldSpec, SeriesSchema};
|
||||
|
||||
use crate::map::MathOp;
|
||||
use crate::native::plan::{
|
||||
AggregateKind, AggregateStage, AggregateStateSchema, BoundAggregate, BoundInput, BoundVectorOp,
|
||||
Grouping, MapOp, NativeExpr, NativeNode, NativeTree, NativeType, aggregate_state_binding,
|
||||
AggregateStage, AggregateStateSchema, BoundAggregate, BoundInput, BoundVectorOp, Grouping,
|
||||
MapOp, NativeExpr, NativeNode, NativeTree, NativeType, aggregate_state_binding,
|
||||
};
|
||||
|
||||
pub(crate) struct Split {
|
||||
@@ -42,6 +43,8 @@ pub(crate) struct Split {
|
||||
op: BoundAggregate,
|
||||
/// The cut aggregate's output, which the exported state is indexed by.
|
||||
schema: Arc<SeriesSchema>,
|
||||
/// The state the cut aggregate exports.
|
||||
state: Arc<AggregateStateSchema>,
|
||||
/// The suffix reads whole histograms rather than individual groups.
|
||||
histogram: bool,
|
||||
/// The suffix rewrites at least one label of the histogram routing key.
|
||||
@@ -102,7 +105,7 @@ pub(crate) fn split(
|
||||
Ok(Some(inner))
|
||||
}
|
||||
NativeExpr::Aggregate { input, op } => {
|
||||
check_cut(op, fields, time_index)?;
|
||||
let (kind, components) = check_cut(op, fields, time_index)?;
|
||||
match split(input, fields, time_index)? {
|
||||
Some(_) => Err(declined("an aggregate above a split aggregate")),
|
||||
None => {
|
||||
@@ -110,9 +113,16 @@ pub(crate) fn split(
|
||||
let NativeType::Samples(schema) = &node.output else {
|
||||
return Err(declined("an aggregate that produces no values"));
|
||||
};
|
||||
if schema.eval_grid.is_none() {
|
||||
let Some(grid) = &schema.eval_grid else {
|
||||
return Err(declined("an aggregate that produces no values"));
|
||||
}
|
||||
};
|
||||
let state = Arc::new(AggregateStateSchema {
|
||||
group: op.group.clone(),
|
||||
kind,
|
||||
components: components.into(),
|
||||
accumulators: schema.fields.clone(),
|
||||
grid: Arc::clone(grid),
|
||||
});
|
||||
Ok(Some(Split {
|
||||
prefix: (**input).clone(),
|
||||
// Source indices are local to one execution; the suffix has one input.
|
||||
@@ -127,6 +137,7 @@ pub(crate) fn split(
|
||||
},
|
||||
op: op.clone(),
|
||||
schema: Arc::clone(schema),
|
||||
state,
|
||||
histogram: false,
|
||||
label_rewrite: false,
|
||||
}))
|
||||
@@ -351,19 +362,19 @@ pub(crate) fn prefix_fields(tree: &NativeTree) -> DfResult<Vec<FieldSpec>> {
|
||||
.ok_or_else(|| declined("a tree that reads no raw series"))
|
||||
}
|
||||
|
||||
/// Refuses a non-`Complete` aggregate, a `quantile` (no fixed-width state), and a `by(...)` naming
|
||||
/// a value field or the time index.
|
||||
/// The state `op` exports when it is cut. Refuses a non-`Complete` aggregate, a `quantile` (no
|
||||
/// fixed-width state), and a `by(...)` naming a value field or the time index.
|
||||
pub(crate) fn check_cut(
|
||||
op: &BoundAggregate,
|
||||
fields: &[FieldSpec],
|
||||
time_index: &str,
|
||||
) -> DfResult<()> {
|
||||
) -> DfResult<(AggregateStateKind, Vec<StateComponent>)> {
|
||||
if op.stage != AggregateStage::Complete {
|
||||
return Err(declined("an aggregate that is not `Complete`"));
|
||||
}
|
||||
if matches!(op.kind, AggregateKind::Quantile { .. }) {
|
||||
let Some(state) = aggregate_state_binding(op.kind, op.field_kind) else {
|
||||
return Err(declined("a `quantile` aggregate"));
|
||||
}
|
||||
};
|
||||
if let Grouping::By(labels) = &op.group
|
||||
&& labels.iter().any(|label| {
|
||||
label.as_ref() == time_index
|
||||
@@ -374,7 +385,7 @@ pub(crate) fn check_cut(
|
||||
{
|
||||
return Err(declined("an aggregate grouped by a value field"));
|
||||
}
|
||||
Ok(())
|
||||
Ok(state)
|
||||
}
|
||||
|
||||
/// Checks that the prefix answers one series from one series' samples: maps and constant-sided
|
||||
@@ -447,31 +458,16 @@ pub struct SplitTrees {
|
||||
}
|
||||
|
||||
impl Split {
|
||||
/// `Ok(None)` when the aggregate has no mergeable state.
|
||||
pub fn into_trees(self) -> DfResult<Option<SplitTrees>> {
|
||||
pub fn into_trees(self) -> DfResult<SplitTrees> {
|
||||
let Self {
|
||||
prefix,
|
||||
suffix,
|
||||
op,
|
||||
schema,
|
||||
state,
|
||||
histogram: _,
|
||||
label_rewrite: _,
|
||||
} = self;
|
||||
let Some((kind, components)) = aggregate_state_binding(op.kind, op.field_kind) else {
|
||||
return Ok(None);
|
||||
};
|
||||
let Some(grid) = schema.eval_grid.clone() else {
|
||||
return Err(DataFusionError::Internal(
|
||||
"a split aggregate has no evaluation grid".into(),
|
||||
));
|
||||
};
|
||||
let state = Arc::new(AggregateStateSchema {
|
||||
group: op.group.clone(),
|
||||
kind,
|
||||
components: components.into(),
|
||||
accumulators: schema.fields.clone(),
|
||||
grid,
|
||||
});
|
||||
let partial = NativeTree::try_new(NativeNode {
|
||||
expr: NativeExpr::Aggregate {
|
||||
input: Box::new(prefix),
|
||||
@@ -501,10 +497,10 @@ impl Split {
|
||||
output: NativeType::Samples(Arc::clone(&schema)),
|
||||
};
|
||||
let root = enter_suffix(suffix, &merged)?;
|
||||
Ok(Some(SplitTrees {
|
||||
Ok(SplitTrees {
|
||||
partial,
|
||||
final_tree: NativeTree::try_new(root)?,
|
||||
}))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user