Skip to content

Commit

Permalink
Fix bug with unknown constants in filter expressions (#392)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Ivliev <[email protected]>
  • Loading branch information
Alex Ivliev and aannleax authored Oct 30, 2023
1 parent 2e3868a commit 2348953
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
5 changes: 4 additions & 1 deletion nemo-physical/src/arithmetic/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ impl<T> StackProgram<T> {
}

/// Creates a new [`StackProgram`], where all [`StackOperation::Push`] operations have been mapped with `f`.
pub fn map_values<S>(&self, f: impl Fn(&StackValue<T>) -> StackValue<S>) -> StackProgram<S> {
pub fn map_values<S>(
&self,
mut f: impl FnMut(&StackValue<T>) -> StackValue<S>,
) -> StackProgram<S> {
let instructions = self
.instructions
.iter()
Expand Down
2 changes: 1 addition & 1 deletion nemo-physical/src/management/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ impl DatabaseInstance {

if let Some(subiterator) = subiterator_opt {
let restrict_scan = TrieScanRestrictValues::new(
&self.dict_constants.borrow_mut(),
&mut self.dict_constants.borrow_mut(),
subiterator,
conditions,
);
Expand Down
4 changes: 2 additions & 2 deletions nemo-physical/src/tabular/operations/triescan_prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,9 @@ mod test {
) -> TrieScanPrune {
let scan = TrieScanEnum::TrieScanGeneric(TrieScanGeneric::new(input_trie));

let dict = Dict::default();
let mut dict = Dict::default();
let scan = TrieScanEnum::TrieScanRestrictValues(TrieScanRestrictValues::new(
&dict,
&mut dict,
scan,
&[
ConditionStatement::equal(
Expand Down
23 changes: 11 additions & 12 deletions nemo-physical/src/tabular/operations/triescan_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pub struct TrieScanRestrictValues<'a> {
impl<'a> TrieScanRestrictValues<'a> {
/// Construct new TrieScanRestrictValues object.
pub fn new(
dict: &Dict,
dict: &mut Dict,
base_trie: TrieScanEnum<'a>,
conditions: &[ConditionStatement<DataValueT>],
) -> Self {
Expand Down Expand Up @@ -304,11 +304,10 @@ impl<'a> TrieScanRestrictValues<'a> {
}

// Translates DataValueT into $type and the references according to map_index
let translate_type_index = |l: &StackValue<DataValueT>| match l {
let mut translate_type_index = |l: &StackValue<DataValueT>| match l {
StackValue::Constant(t) => {
if let StorageValueT::$variant(value) = t
.to_storage_value(dict)
.expect("We don't have string operations so this cannot fail.")
.to_storage_value_mut(dict)
{
StackValue::Constant(value)
} else {
Expand All @@ -329,8 +328,8 @@ impl<'a> TrieScanRestrictValues<'a> {
.into_iter()
.map(|c| ConditionStatement {
operation: c.operation,
lhs: c.lhs.map_values(&translate_type_index),
rhs: c.rhs.map_values(&translate_type_index),
lhs: c.lhs.map_values(&mut translate_type_index),
rhs: c.rhs.map_values(&mut translate_type_index),
})
.collect();

Expand Down Expand Up @@ -506,9 +505,9 @@ mod test {
let trie = Trie::new(vec![column_fst, column_snd, column_trd, column_fth]);
let trie_iter = TrieScanEnum::TrieScanGeneric(TrieScanGeneric::new(&trie));

let dict = Dict::default();
let mut dict = Dict::default();
let mut restrict_iter = TrieScanRestrictValues::new(
&dict,
&mut dict,
trie_iter,
&[
ConditionStatement::equal(
Expand Down Expand Up @@ -576,9 +575,9 @@ mod test {
let trie = Trie::new(vec![column_fst, column_snd]);
let trie_iter = TrieScanEnum::TrieScanGeneric(TrieScanGeneric::new(&trie));

let dict = Dict::default();
let mut dict = Dict::default();
let mut restrict_iter = TrieScanRestrictValues::new(
&dict,
&mut dict,
trie_iter,
&[ConditionStatement::less_than(
StackValue::Reference(1),
Expand Down Expand Up @@ -625,9 +624,9 @@ mod test {
let trie = Trie::new(vec![column_fst, column_snd]);
let trie_iter = TrieScanEnum::TrieScanGeneric(TrieScanGeneric::new(&trie));

let dict = Dict::default();
let mut dict = Dict::default();
let mut restrict_iter = TrieScanRestrictValues::new(
&dict,
&mut dict,
trie_iter,
&[ConditionStatement::unequal(
StackValue::Reference(1),
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/model/rule_model/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl Term {
StackValue::Constant(t) => {
if let StorageValueT::$variant(value) = t
.to_storage_value(dict)
.expect("We don't have string operations so this cannot fail.")
.expect("We expect all strings to be known at this point.")
{
StackValue::Constant(value)
} else {
Expand Down
4 changes: 4 additions & 0 deletions resources/testcases/datalog_constants/run.rls
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ ConstantBodyHead(Q, ?Y, A, B, ?X, Z) :- sourceA("A", ?X, ?Y), sourceB(?X, "D", "

OnlyNewConstants(A, B, C) :- sourceA(?X, ?Y, ?Z) .
OnlyNewConstantsEmpty(A, B, C) :- sourceA("C", "C", "C") .

sourceC("A", "B", "X").

Unknown(?X) :- sourceC(?X, ?Y, "R") .
Empty file.

0 comments on commit 2348953

Please sign in to comment.