Skip to content

Commit

Permalink
Bug/452 (#457)
Browse files Browse the repository at this point in the history
* Add new testcase

* Fix bug related to applying applying negative filters

---------

Co-authored-by: Alex Ivliev <[email protected]>
  • Loading branch information
Alex Ivliev and aannleax authored Apr 2, 2024
1 parent 834a8d3 commit 7d44277
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
20 changes: 17 additions & 3 deletions nemo/src/execution/planning/operations/negation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub(crate) fn node_negation(
.iter()
.map(|atom| {
let subtract_markers = variable_translation.operation_table(atom.terms().iter());

let node = subplan_union(
plan,
table_manager,
Expand All @@ -36,9 +37,22 @@ pub(crate) fn node_negation(
subtract_markers.clone(),
);

// We simply apply all constraints to this node
// Constraints which do not reference this atom will be filtered in the physical layer
let node_filtered = node_filter(plan, variable_translation, node, subtracted_filters);
// We only keep those constraints that can be evaluated within the current atom
let filters = subtracted_filters
.iter()
.filter(|filter| {
filter.variables().all(|variable| {
subtract_markers.contains(
variable_translation
.get(variable)
.expect("variable translation must know every variable"),
)
})
})
.cloned()
.collect::<Vec<Constraint>>();

let node_filtered = node_filter(plan, variable_translation, node, &filters);

// The tables may contain columns that are not part of `node_main`.
// These need to be projected away.
Expand Down
2 changes: 0 additions & 2 deletions nemo/src/execution/planning/plan_head_restricted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ impl RestrictedChaseStrategy {
let head_join_atoms = analysis.existential_aux_rule.positive_body().clone();
let head_join_constraints = analysis.existential_aux_rule.positive_constraints().clone();

println!("{:?}, {:?}", head_join_atoms, head_join_constraints);

let aux_head = &analysis.existential_aux_rule.head()[0];
let mut aux_head_order = VariableOrder::new();
let mut used_join_head_variables = HashSet::<Variable>::new();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
%%% Test related to
%%% https://github.com/knowsys/nemo/issues/452
%%%
%%% Previously, an incorrect plan was produced, which lead to a crash.

S(a, b, c).
S(r, r, r).
T(a, b).
T(a, c).

R(?x, ?y, ?z) :-
S(?x, ?y, ?z),
~ T(?x, ?y),
~ T(a, ?z).

R(?x, ?y, ?z) :-
S(?x, ?y, ?z),
~ T(a, ?y),
~ T(a, ?z).

@export R :- csv {} .
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
r,r,r

0 comments on commit 7d44277

Please sign in to comment.