Skip to content

Commit

Permalink
Revert "Project node's selection result into dependent's field select…
Browse files Browse the repository at this point in the history
…ion"

This reverts commit 6ee982b.
  • Loading branch information
aqrln committed Dec 1, 2023
1 parent b5584df commit 94c60ce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion query-engine/core/src/interpreter/interpreter_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
5 changes: 2 additions & 3 deletions query-engine/query-structure/src/field_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 12 additions & 16 deletions query-engine/query-structure/src/selection_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,19 @@ impl SelectionResult {
pub fn split_into(self, field_selections: &[FieldSelection]) -> Vec<SelectionResult> {
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.
Expand Down

0 comments on commit 94c60ce

Please sign in to comment.