Skip to content

Commit f55fe02

Browse files
authored
Bug/500 constant filters (#501)
I had code that computed the column on which a filter is going to be applied on. This depended upon the input variables, e.g. when computing `a(x, y, z), 2 * x > z`, the less-than filter should be applied on column `z` as the value for `x` has to be bound when computing the filter. The code that finds the last occurrence of a variable panicked if the filter did not contain any variable. To fix this I simply assign constant filters to the first column. Fixes #500.
2 parents 0e0aa79 + 699874d commit f55fe02

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

nemo-physical/src/tabular/operations/filter.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,20 @@ impl GeneratorFilter {
117117

118118
/// Helper function that finds the [OperationColumnMarker] used in the given [Filter]
119119
/// that appears closest to the end of the given [OperationTable].
120-
fn find_last_reference(table: &OperationTable, filter: &Filter) -> OperationColumnMarker {
120+
///
121+
/// Returns `None` if the given filter does not use any values as input.
122+
fn find_last_reference(
123+
table: &OperationTable,
124+
filter: &Filter,
125+
) -> Option<OperationColumnMarker> {
121126
let references = filter.references();
122127
for marker in table.iter().rev() {
123128
if references.contains(marker) {
124-
return *marker;
129+
return Some(*marker);
125130
}
126131
}
127132

128-
unreachable!("Filter must only use markers from the table.")
133+
None
129134
}
130135

131136
/// Helper function that takes a list of boolean [Filter]s
@@ -139,7 +144,7 @@ impl GeneratorFilter {
139144
let mut grouped_filters = HashMap::<OperationColumnMarker, Vec<&Filter>>::new();
140145

141146
for filter in filters {
142-
let marker = Self::find_last_reference(input, filter);
147+
let marker = Self::find_last_reference(input, filter).unwrap_or(input[0]);
143148
grouped_filters.entry(marker).or_default().push(filter);
144149
}
145150

nemo/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! A fast in-memory rule engine
22
3+
#![type_length_limit = "5000000000"]
34
#![deny(
45
missing_debug_implementations,
56
missing_copy_implementations,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
%%% Test related to
2+
%%% https://github.com/knowsys/nemo/issues/500
3+
%%%
4+
%%% A panic was caused by having a filter consisting of constants
5+
6+
pair(1, 2) .
7+
pair(3, 3) .
8+
9+
equal(?x) :- pair(?x, ?y), c = d .
10+
11+
@export equal :- csv {} .

resources/testcases/regression/planning_engine/constants_filter/run/equal.csv

Whitespace-only changes.

0 commit comments

Comments
 (0)