Skip to content

Commit 2ad1fb1

Browse files
authored
Feature/refactor planning (#726)
This PR replaces `ChaseRule` and `RuleAnalysis` with `NormalizedRule`s. It also reworks the planning code.
2 parents 46c1967 + d19caac commit 2ad1fb1

File tree

102 files changed

+5022
-5622
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+5022
-5622
lines changed

nemo-physical/src/management/database.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ impl DatabaseInstance {
546546
let (result_tree, results_dependent) = self
547547
.execute_tree(&temporary_storage, tree, dependent_reorderings)
548548
.await;
549+
549550
TimedCode::instance().sub(&timed_string).stop();
550551

551552
if tree_used > 0 {

nemo-physical/src/management/execution_plan.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ impl ExecutionNodeRef {
155155
| ExecutionOperation::Function(subnode, _)
156156
| ExecutionOperation::Null(subnode)
157157
| ExecutionOperation::Aggregate(subnode, _)
158-
| ExecutionOperation::IncrementalImport(subnode, _) => vec![subnode.clone()],
158+
| ExecutionOperation::IncrementalImport(subnode, _)
159+
| ExecutionOperation::Rename(subnode) => vec![subnode.clone()],
159160
}
160161
}
161162
}
@@ -197,6 +198,8 @@ pub(crate) enum ExecutionOperation {
197198
Aggregate(ExecutionNodeRef, AggregateAssignment),
198199
/// Perform an incremental import
199200
IncrementalImport(ExecutionNodeRef, Rc<Box<dyn TableProvider>>),
201+
/// Renaming of the columns of the table
202+
Rename(ExecutionNodeRef),
200203
}
201204

202205
/// Declares whether the resulting table form executing a plan should be kept temporarily or permamently
@@ -421,6 +424,16 @@ impl ExecutionPlan {
421424

422425
import_node
423426
}
427+
428+
/// Return an [ExecutionNodeRef] with renamed column markers.
429+
pub fn rename(
430+
&mut self,
431+
subnode: ExecutionNodeRef,
432+
markers: OperationTable,
433+
) -> ExecutionNodeRef {
434+
let operation = ExecutionOperation::Rename(subnode);
435+
self.push_and_return_reference(operation, markers)
436+
}
424437
}
425438

426439
impl ExecutionPlan {
@@ -732,6 +745,7 @@ impl ExecutionPlan {
732745
}
733746
ExecutionOperation::Subtract(subnode_main, subnodes_subtract) => {
734747
let markers_main = node_markers;
748+
735749
let (markers_subtract, subtract_reorderings): (
736750
Vec<OperationTable>,
737751
Vec<Permutation>,
@@ -905,6 +919,15 @@ impl ExecutionPlan {
905919
subnode: subtree,
906920
}
907921
}
922+
ExecutionOperation::Rename(subnode) => Self::execution_node(
923+
root_node_id,
924+
subnode.clone(),
925+
order,
926+
output_nodes,
927+
computed_trees,
928+
computed_trees_map,
929+
loaded_tables,
930+
),
908931
}
909932
}
910933

nemo-physical/src/tabular/buffer/tuple_buffer.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,18 +477,20 @@ impl TupleBuffer {
477477
return true;
478478
}
479479

480-
for pattern in &self.patterns {
480+
'pattern: for pattern in &self.patterns {
481481
if !self.pattern_matches(pattern) {
482482
continue;
483483
}
484484

485485
let data_values = self.current_tuple_data_values.clone();
486486
for transformation in &pattern.transformations {
487-
let value = transformation
488-
.program
489-
.evaluate_data(&data_values)
490-
.expect("should evaluate to a value");
491-
self.current_tuple_data_values[transformation.position] = value;
487+
if let Some(value) = transformation.program.evaluate_data(&data_values) {
488+
self.current_tuple_data_values[transformation.position] = value;
489+
} else {
490+
// We skip this pattern if the operation did not return a result,
491+
// e.g. when using a builtin with a value of an incorrect type
492+
continue 'pattern;
493+
}
492494
}
493495

494496
// first matching pattern wins

nemo-physical/src/tabular/operations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl Deref for OperationTable {
196196
/// mainly by providing a translation between
197197
/// user defined "markers" (supplied as a generic parameter to this object)
198198
/// and [OperationColumnMarker]s.
199-
#[derive(Default)]
199+
#[derive(Default, Clone)]
200200
pub struct OperationTableGenerator<ExternalMarker>
201201
where
202202
ExternalMarker: Clone + PartialEq + Eq + Hash,

nemo-python/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::{collections::HashSet, fs::read_to_string, time::Duration};
22

33
use nemo::{
44
api::load_program,
5-
chase_model::ChaseAtom,
65
datavalues::{AnyDataValue, DataValue},
76
error::Error,
87
execution::{ExecutionEngine, tracing::trace::ExecutionTraceTree},
@@ -201,7 +200,7 @@ fn datavalue_to_python(py: Python<'_>, v: AnyDataValue) -> PyResult<Bound<'_, Py
201200
}
202201

203202
#[pyclass]
204-
struct NemoFact(nemo::chase_model::GroundAtom);
203+
struct NemoFact(nemo::execution::planning::normalization::atom::ground::GroundAtom);
205204

206205
#[pymethods]
207206
impl NemoFact {

nemo-python/tests/test_example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def setUp(self):
4141
self.engine.reason()
4242

4343
self.expected_api_result = [
44-
["<world>", "_:0"],
45-
["<circle>", "_:1"],
44+
["<circle>", "_:0"],
45+
["<world>", "_:1"],
4646
[
4747
NemoLiteral("hello world", lang="en"),
4848
"_:2",
@@ -53,8 +53,8 @@ def setUp(self):
5353
]
5454

5555
self.expected_serialized_result = [
56-
["world", "_:0"],
57-
["circle", "_:1"],
56+
["circle", "_:0"],
57+
["world", "_:1"],
5858
[
5959
'"hello world"@en',
6060
"_:2",

nemo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ assert_fs = "1.0"
6565
test-log = "0.2"
6666
quickcheck = "1"
6767
quickcheck_macros = "1"
68-
tokio = "1.47.1"
68+
tokio = { version = "1.47.1", features = [ "rt", "macros" ] }
6969

nemo/src/api.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ pub fn output_predicates(engine: &Engine) -> Vec<Tag> {
125125
.exports()
126126
.iter()
127127
.map(|export| export.predicate())
128-
.cloned()
129-
.collect()
128+
.collect::<Vec<_>>()
130129
}
131130

132131
// TODO: Disabled write API. This API is designed in a way that does not fit how Nemo controls exporting.

nemo/src/chase_model.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

nemo/src/chase_model/analysis.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)