MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / extract_variables_from_node

Method extract_variables_from_node

graphlite/src/exec/executor.rs:9285–9360  ·  view source on GitHub ↗

Extract variables from a physical node (returns None if not a projection node)

(&self, node: &PhysicalNode)

Source from the content-addressed store, hash-verified

9283
9284 /// Extract variables from a physical node (returns None if not a projection node)
9285 fn extract_variables_from_node(&self, node: &PhysicalNode) -> Option<Vec<String>> {
9286 match node {
9287 PhysicalNode::Project { expressions, .. } => {
9288 let variables: Vec<String> = expressions
9289 .iter()
9290 .map(|expr| {
9291 // Use alias if available, otherwise try to derive variable name from expression
9292 if let Some(ref alias) = expr.alias {
9293 alias.clone()
9294 } else {
9295 self.derive_variable_name_from_expression(&expr.expression)
9296 }
9297 })
9298 .collect();
9299 Some(variables)
9300 }
9301
9302 // For Aggregate nodes, we need to figure out the output column order
9303 // This is a bit tricky because we need to reconstruct it from the aggregates and group_by
9304 PhysicalNode::HashAggregate {
9305 group_by,
9306 aggregates,
9307 ..
9308 }
9309 | PhysicalNode::SortAggregate {
9310 group_by,
9311 aggregates,
9312 ..
9313 } => {
9314 let mut variables = Vec::new();
9315
9316 // Add group-by columns first (in their original order)
9317 for expr in group_by {
9318 variables.push(self.expression_to_string(expr));
9319 }
9320
9321 // Add aggregate columns
9322 for aggregate in aggregates {
9323 let column_name = aggregate.alias.clone().unwrap_or_else(|| {
9324 let function_name = match &aggregate.function {
9325 crate::plan::logical::AggregateFunction::Count => "COUNT",
9326 crate::plan::logical::AggregateFunction::Sum => "SUM",
9327 crate::plan::logical::AggregateFunction::Avg => "AVERAGE",
9328 crate::plan::logical::AggregateFunction::Min => "MIN",
9329 crate::plan::logical::AggregateFunction::Max => "MAX",
9330 crate::plan::logical::AggregateFunction::Collect => "COLLECT",
9331 };
9332 format!(
9333 "{}_{}",
9334 function_name,
9335 self.expression_to_string(&aggregate.expression)
9336 )
9337 });
9338 variables.push(column_name);
9339 }
9340
9341 Some(variables)
9342 }

Callers 1

Calls 4

cloneMethod · 0.80
expression_to_stringMethod · 0.80
iterMethod · 0.45

Tested by

no test coverage detected