Validate that two query results have compatible schemas for set operations
(
&self,
left: &QueryResult,
right: &QueryResult,
)
| 7559 | |
| 7560 | /// Validate that two query results have compatible schemas for set operations |
| 7561 | fn validate_set_operation_compatibility( |
| 7562 | &self, |
| 7563 | left: &QueryResult, |
| 7564 | right: &QueryResult, |
| 7565 | ) -> Result<(), ExecutionError> { |
| 7566 | // Handle special case where one side has no results but should have the same number of variables |
| 7567 | // This happens when a query has a RETURN clause but matches no rows |
| 7568 | |
| 7569 | // If both sides have no variables, that's fine (both are empty queries) |
| 7570 | if left.variables.is_empty() && right.variables.is_empty() { |
| 7571 | return Ok(()); |
| 7572 | } |
| 7573 | |
| 7574 | // If one side has no variables but the other has variables, use the non-empty side's variables |
| 7575 | // This handles cases where one query returns no rows but still has a RETURN clause |
| 7576 | let effective_left_count = |
| 7577 | if left.variables.is_empty() && left.rows.is_empty() && !right.variables.is_empty() { |
| 7578 | right.variables.len() // Assume same variable count as right side |
| 7579 | } else { |
| 7580 | left.variables.len() |
| 7581 | }; |
| 7582 | |
| 7583 | let effective_right_count = |
| 7584 | if right.variables.is_empty() && right.rows.is_empty() && !left.variables.is_empty() { |
| 7585 | left.variables.len() // Assume same variable count as left side |
| 7586 | } else { |
| 7587 | right.variables.len() |
| 7588 | }; |
| 7589 | |
| 7590 | if effective_left_count != effective_right_count { |
| 7591 | return Err(ExecutionError::RuntimeError(format!( |
| 7592 | "Set operation variable count mismatch: left has {} variables, right has {} variables", |
| 7593 | effective_left_count, |
| 7594 | effective_right_count |
| 7595 | ))); |
| 7596 | } |
| 7597 | |
| 7598 | // Note: In a more complete implementation, we might also check variable types |
| 7599 | // For now, we just ensure the same number of variables in the RETURN clause |
| 7600 | |
| 7601 | Ok(()) |
| 7602 | } |
| 7603 | |
| 7604 | /// Convert rows to positional format for set operations |
| 7605 | fn convert_to_positional_rows(&self, rows: Vec<Row>, variables: &[String]) -> Vec<Row> { |
no test coverage detected