MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / expand_rollup

Function expand_rollup

nodedb-sql/src/planner/grouping_sets.rs:158–164  ·  view source on GitHub ↗

Expand `ROLLUP(a, b, c)` → `[[a,b,c], [a,b], [a], []]`. The input is `Vec >` where each inner vec is one composite element. We flatten composite elements to individual expressions for simplicity — the outer product is: suffix-strip from all-present down to empty.

(groups: &[Vec<ast::Expr>])

Source from the content-addressed store, hash-verified

156/// We flatten composite elements to individual expressions for simplicity — the
157/// outer product is: suffix-strip from all-present down to empty.
158fn expand_rollup(groups: &[Vec<ast::Expr>]) -> Vec<Vec<&ast::Expr>> {
159 // Flatten composite groups (e.g. `(a, b)` as one element) into atoms.
160 let atoms: Vec<&ast::Expr> = groups.iter().flat_map(|g| g.iter()).collect();
161 let n = atoms.len();
162 // Prefixes: atoms[0..n], atoms[0..n-1], ..., atoms[0..0] (empty).
163 (0..=n).rev().map(|len| atoms[..len].to_vec()).collect()
164}
165
166/// Expand `CUBE(a, b)` → all 2^N subsets.
167fn expand_cube(groups: &[Vec<ast::Expr>]) -> Vec<Vec<&ast::Expr>> {

Callers 1

expand_group_byFunction · 0.85

Calls 4

collectMethod · 0.80
iterMethod · 0.45
lenMethod · 0.45
to_vecMethod · 0.45

Tested by

no test coverage detected