Skip to main content

reifydb_engine/flow/compiler/operator/
aggregate_validation.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4use reifydb_core::error::diagnostic::flow::flow_unsupported_aggregate_expression;
5use reifydb_routine::routine::registry::Routines;
6use reifydb_rql::expression::{Expression, name::display_label};
7use reifydb_value::{Result, error::Error};
8
9use crate::flow::aggregate::{AggregateContext, is_representable};
10
11pub(crate) fn validate_flow_aggregations(
12	routines: &Routines,
13	aggregations: &[Expression],
14	context: AggregateContext,
15) -> Result<()> {
16	if aggregations.is_empty() {
17		return Err(Error(Box::new(flow_unsupported_aggregate_expression("<none>"))));
18	}
19	for expr in aggregations {
20		if !is_representable(routines, expr, context) {
21			let output = display_label(expr).text().to_string();
22			return Err(Error(Box::new(flow_unsupported_aggregate_expression(&output))));
23		}
24	}
25	Ok(())
26}