Skip to content

Commit 9c3c1e1

Browse files
committed
Ignore match nodes that are not part of the output and return unique results in execute_query_on_graph
1 parent 72d12db commit 9c3c1e1

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

  • graphannis/src/annis/db/aql

graphannis/src/annis/db/aql/mod.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod operators;
66

77
use boolean_expression::Expr;
88
use graphannis_core::annostorage::MatchGroup;
9+
use itertools::Itertools;
910
lalrpop_mod!(
1011
#[allow(clippy::all)]
1112
#[allow(clippy::panic)]
@@ -77,7 +78,28 @@ pub fn execute_query_on_graph<'a>(
7778
let timeout = TimeoutCheck::new(timeout);
7879

7980
let config = Config { use_parallel_joins };
80-
let it = ExecutionPlan::from_disjunction(query, graph, &config, timeout)?;
81+
let it = ExecutionPlan::from_disjunction(query, graph, &config, timeout)?
82+
.map_ok(|mg| {
83+
// Rewrite match group to only include nodes that are included in the query
84+
// check if query node actually should be included
85+
let mut new_match_group = MatchGroup::with_capacity(mg.len());
86+
for (node_nr, m) in mg.into_iter().enumerate() {
87+
let include_in_output = query
88+
.get_variable_by_node_nr(node_nr)
89+
.is_some_and(|var| query.is_included_in_output(&var));
90+
if include_in_output {
91+
new_match_group.push(m);
92+
}
93+
}
94+
new_match_group
95+
})
96+
.unique_by(move |mg| {
97+
// Map an error to an empty match group
98+
match mg {
99+
Ok(mg) => mg.clone(),
100+
Err(_) => MatchGroup::new(),
101+
}
102+
});
81103

82104
Ok(Box::from(it))
83105
}

0 commit comments

Comments
 (0)