From 6837c95268bd0b7c0d672faddaf1681f07da292b Mon Sep 17 00:00:00 2001 From: Alex Ivliev Date: Tue, 2 Apr 2024 10:12:59 +0200 Subject: [PATCH] Bug/428 (#459) * Fix #428 by considering subtraction of zero column tries to be empty --------- Co-authored-by: Alex Ivliev --- nemo-physical/src/tabular/operations/subtract.rs | 5 +++++ .../testcases/regression/unbound_negation/run.rls | 15 +++++++++++++++ .../unbound_negation/run/NonNegative.csv | 0 .../unbound_negation/run/NonPositive.csv | 1 + 4 files changed, 21 insertions(+) create mode 100644 resources/testcases/regression/unbound_negation/run.rls create mode 100644 resources/testcases/regression/unbound_negation/run/NonNegative.csv create mode 100644 resources/testcases/regression/unbound_negation/run/NonPositive.csv diff --git a/nemo-physical/src/tabular/operations/subtract.rs b/nemo-physical/src/tabular/operations/subtract.rs index e4c0b7675..ac2906f27 100644 --- a/nemo-physical/src/tabular/operations/subtract.rs +++ b/nemo-physical/src/tabular/operations/subtract.rs @@ -76,6 +76,11 @@ impl OperationGenerator for GeneratorSubtract { return None; } + if tries_subtract.iter().any(|scan| scan.arity() == 0) { + // If we subtract a non empty zero column trie the result is defined as empty + return None; + } + let mut active_scans = Vec::with_capacity(trie_main.arity() + 1); active_scans.push(Rc::new(RefCell::new(vec![true; tries_subtract.len()]))); diff --git a/resources/testcases/regression/unbound_negation/run.rls b/resources/testcases/regression/unbound_negation/run.rls new file mode 100644 index 000000000..d4c1e4273 --- /dev/null +++ b/resources/testcases/regression/unbound_negation/run.rls @@ -0,0 +1,15 @@ +%%% Test related to +%%% https://github.com/knowsys/nemo/issues/428 +%%% +%%% Previously, subtracting a zero arity table resulted in a crash + +Input(-1). + +Assert(positive) :- Input(?i), ?i > 0. +Assert(negative) :- Input(?i), ?i < 0. + +NonPositive(?r) :- Input(?r), ~Assert(positive). +NonNegative(?r) :- Input(?r), ~Assert(negative). + +@export NonPositive :- csv {} . +@export NonNegative :- csv {} . \ No newline at end of file diff --git a/resources/testcases/regression/unbound_negation/run/NonNegative.csv b/resources/testcases/regression/unbound_negation/run/NonNegative.csv new file mode 100644 index 000000000..e69de29bb diff --git a/resources/testcases/regression/unbound_negation/run/NonPositive.csv b/resources/testcases/regression/unbound_negation/run/NonPositive.csv new file mode 100644 index 000000000..d7d17fcbe --- /dev/null +++ b/resources/testcases/regression/unbound_negation/run/NonPositive.csv @@ -0,0 +1 @@ +-1 \ No newline at end of file