reifydb-rql 0.9.0

ReifyDB Query Language (RQL) parser and AST
Documentation
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2026 ReifyDB

use reifydb_core::error::diagnostic::flow::flow_unsupported_aggregate_expression;
use reifydb_routine_abi::registry::Routines;
use reifydb_value::{Result, error::Error};

use crate::{
	expression::{Expression, name::display_label},
	flow::aggregate::{AggregateContext, is_representable},
};

pub(crate) fn validate_flow_aggregations(
	routines: &Routines,
	aggregations: &[Expression],
	context: AggregateContext,
) -> Result<()> {
	if aggregations.is_empty() {
		return Err(Error(Box::new(flow_unsupported_aggregate_expression("<none>"))));
	}
	for expr in aggregations {
		if !is_representable(routines, expr, context) {
			let output = display_label(expr).text().to_string();
			return Err(Error(Box::new(flow_unsupported_aggregate_expression(&output))));
		}
	}
	Ok(())
}