From d5731c7b05ccc277df1a027b6c0ca65a3a58f43b Mon Sep 17 00:00:00 2001 From: Alexey Orlenko Date: Fri, 1 Dec 2023 17:06:21 +0100 Subject: [PATCH] Revert "Project node's selection result into dependent's field selection" This reverts commit 6ee982ba5bb65fe9e1894cf5b4dcf443dd9481f7. --- .../core/src/interpreter/interpreter_impl.rs | 2 +- .../query-structure/src/field_selection.rs | 5 ++-- .../query-structure/src/selection_result.rs | 28 ++++++++----------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/query-engine/core/src/interpreter/interpreter_impl.rs b/query-engine/core/src/interpreter/interpreter_impl.rs index e3454bfe8f2..8aa3d77ae76 100644 --- a/query-engine/core/src/interpreter/interpreter_impl.rs +++ b/query-engine/core/src/interpreter/interpreter_impl.rs @@ -52,7 +52,7 @@ impl ExpressionResult { let converted = match self { Self::Query(ref result) => match result { QueryResult::Id(id) => match id { - Some(id) if field_selection.matches(id) => Some(vec![id.project(field_selection)]), + Some(id) if field_selection.matches(id) => Some(vec![id.clone()]), None => Some(vec![]), Some(id) => { trace!( diff --git a/query-engine/query-structure/src/field_selection.rs b/query-engine/query-structure/src/field_selection.rs index f7998af3815..b44529793a5 100644 --- a/query-engine/query-structure/src/field_selection.rs +++ b/query-engine/query-structure/src/field_selection.rs @@ -111,10 +111,9 @@ impl FieldSelection { } } - /// Checks if a given `SelectionResult` satisfies this `FieldSelection` - /// (i.e., if the fields from `SelectionResult` are a superset of this `FieldSelection`). + /// Checks if a given `SelectionResult` belongs to this `FieldSelection`. pub fn matches(&self, result: &SelectionResult) -> bool { - self.selections().all(|s| result.get(s).is_some()) + result.pairs.iter().all(|(rt, _)| self.selections.contains(rt)) } /// Merges all given `FieldSelection` a set union of all. diff --git a/query-engine/query-structure/src/selection_result.rs b/query-engine/query-structure/src/selection_result.rs index 10e3f5c2211..d6e1ef46349 100644 --- a/query-engine/query-structure/src/selection_result.rs +++ b/query-engine/query-structure/src/selection_result.rs @@ -70,23 +70,19 @@ impl SelectionResult { pub fn split_into(self, field_selections: &[FieldSelection]) -> Vec { field_selections .iter() - .map(|field_selection| self.project(field_selection)) - .collect() - } - - /// Projects this `SelectionResult` into a smaller or equal `SelectionResult` - /// according to the provided [`FieldSelection`]. - pub fn project(&self, field_selection: &FieldSelection) -> SelectionResult { - let pairs: Vec<_> = field_selection - .selections() - .map(|selected_field| { - self.get(selected_field) - .map(|value| (selected_field.clone(), value.clone())) - .expect("Error splitting `ReturnValues`: `FieldSelection` doesn't match.") + .map(|field_selection| { + let pairs: Vec<_> = field_selection + .selections() + .map(|selected_field| { + self.get(selected_field) + .map(|value| (selected_field.clone(), value.clone())) + .expect("Error splitting `ReturnValues`: `FieldSelection` doesn't match.") + }) + .collect(); + + SelectionResult::new(pairs) }) - .collect(); - - SelectionResult::new(pairs) + .collect() } /// Checks if `self` only contains scalar field selections and if so, returns them all in a list.