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

Function resolve_grouping_col

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

Resolve the canonical index for a `GROUPING(col)` argument. Matches by display string against `canonical_names`.

(col_expr: &ast::Expr, canonical_keys: &[SqlExpr])

Source from the content-addressed store, hash-verified

184///
185/// Matches by display string against `canonical_names`.
186pub fn resolve_grouping_col(col_expr: &ast::Expr, canonical_keys: &[SqlExpr]) -> Result<usize> {
187 let display = format!("{col_expr}");
188 // Find by rebuilding the display of each canonical key via its SqlExpr.
189 // Since canonical_keys are built from the same AST exprs, we can compare
190 // their SqlExpr display strings.
191 for (i, key) in canonical_keys.iter().enumerate() {
192 if format!("{key:?}").contains(&display) {
193 return Ok(i);
194 }
195 }
196 // Fallback: try normalized ident match.
197 if let ast::Expr::Identifier(ident) = col_expr {
198 let name = normalize_ident(ident);
199 for (i, key) in canonical_keys.iter().enumerate() {
200 if let SqlExpr::Column { name: col_name, .. } = key
201 && col_name.eq_ignore_ascii_case(&name)
202 {
203 return Ok(i);
204 }
205 }
206 }
207 Err(SqlError::Unsupported {
208 detail: format!(
209 "GROUPING({col_expr}) references a column not found in the canonical key list"
210 ),
211 })
212}
213
214#[cfg(test)]
215mod tests {

Callers 1

Calls 3

normalize_identFunction · 0.85
iterMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected