Convert WithClauseResult back to Row format
(
&self,
with_result: crate::exec::with_clause_processor::WithClauseResult,
)
| 1775 | |
| 1776 | /// Convert WithClauseResult back to Row format |
| 1777 | fn convert_processor_result_to_rows( |
| 1778 | &self, |
| 1779 | with_result: crate::exec::with_clause_processor::WithClauseResult, |
| 1780 | ) -> Result<Vec<Row>, ExecutionError> { |
| 1781 | use std::collections::HashMap; |
| 1782 | |
| 1783 | let mut result_rows = Vec::new(); |
| 1784 | |
| 1785 | if with_result.has_aggregation && !with_result.group_results.is_empty() { |
| 1786 | // Convert each group result to a row (for aggregated WITH clauses) |
| 1787 | for group_result in with_result.group_results { |
| 1788 | let mut row_values = HashMap::new(); |
| 1789 | |
| 1790 | // Add computed values (like aggregations) |
| 1791 | for (key, value) in group_result.computed_values { |
| 1792 | row_values.insert(key, value); |
| 1793 | } |
| 1794 | |
| 1795 | // Add variable bindings as values |
| 1796 | for (var_name, nodes) in group_result.variable_bindings { |
| 1797 | if let Some(node) = nodes.first() { |
| 1798 | // Preserve the full Node object instead of just the ID string |
| 1799 | // This allows property access like u.id, u.name, etc. to work correctly |
| 1800 | row_values.insert(var_name, crate::storage::Value::Node(node.clone())); |
| 1801 | } |
| 1802 | } |
| 1803 | |
| 1804 | result_rows.push(Row::from_values(row_values)); |
| 1805 | } |
| 1806 | } else { |
| 1807 | // For non-aggregated WITH clauses, use the main computed_values and variable_bindings |
| 1808 | let mut row_values = HashMap::new(); |
| 1809 | |
| 1810 | // Add computed values (like function calls) |
| 1811 | for (key, value) in with_result.computed_values { |
| 1812 | row_values.insert(key, value); |
| 1813 | } |
| 1814 | |
| 1815 | // Add variable bindings as values |
| 1816 | for (var_name, nodes) in with_result.variable_bindings { |
| 1817 | if let Some(node) = nodes.first() { |
| 1818 | // Preserve the full Node object instead of just the ID string |
| 1819 | // This allows property access like u.id, u.name, etc. to work correctly |
| 1820 | row_values.insert(var_name, crate::storage::Value::Node(node.clone())); |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | // Only create a row if we have values to include |
| 1825 | if !row_values.is_empty() { |
| 1826 | result_rows.push(Row::from_values(row_values)); |
| 1827 | } |
| 1828 | } |
| 1829 | |
| 1830 | log::debug!("DEBUG: Converted to {} result rows", result_rows.len()); |
| 1831 | Ok(result_rows) |
| 1832 | } |
| 1833 | |
| 1834 | /// Evaluate an aggregate expression over a group of rows |