pub async fn execute_aggregate(
registry: &TableRegistry,
sources: SourceSpec,
filter: Option<ListFilter>,
aggregator: AliasAggregator,
schema: &SchemaConfig,
) -> Result<AliasRunResult, MiniAppError>Expand description
Execute a multi-table aggregation request.
Resolves each source table via registry, mounts every backing .db
file into a fresh in-memory connection with ATTACH DATABASE, composes
a UNION ALL inner sub-query (or a single SELECT for
SourceSpec::Single), and wraps it in an outer SELECT <aggregate>
(with GROUP BY + optional HAVING for AliasAggregator::GroupBy).
§Crux compliance
- Crux #1: reuses the existing
ListFilter::build_sqlvia the siblingListFilter::build_subquerymethod (no signature change). - Crux #2:
havingis emitted as a literalHAVINGclause afterGROUP BY, never asWHERE. - Crux #3: multi-table sources are combined with literal
UNION ALL;JOINis never emitted and no application-layer merge happens.
§Errors
MiniAppError::Aggregator— emptyMulti, ATTACH-limit exceeded, nestedGroupBy, or non-UTF-8 db path.MiniAppError::Validation— schema field missing, identifier regex mismatch, or filter validation failure.MiniAppError::TableNotFound— propagated from the registry.MiniAppError::Storage—rusqlitefailure (ATTACH, query execution, etc.).MiniAppError::Schema—spawn_blockingpanic.