Skip to content

Commit 3a074be

Browse files
committed
feat(cognitarium): introduce query plan model
1 parent cb7a159 commit 3a074be

File tree

1 file changed

+51
-0
lines changed
  • contracts/okp4-cognitarium/src/querier

1 file changed

+51
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use crate::msg::{Prefix, SelectQuery, SimpleWhereCondition, TriplePattern, WhereCondition};
2+
use crate::state::{Object, Predicate, Subject};
3+
use std::collections::{BTreeMap, BTreeSet, HashMap};
4+
5+
/// Represents a querying plan.
6+
pub struct QueryPlan {
7+
/// References the ending node of the plan, when evaluated others nodes will be invoked in
8+
/// cascade.
9+
pub entrypoint: QueryNode,
10+
11+
/// Contains all the query variables, their index in this array are internally used as
12+
/// identifiers.
13+
pub variables: Vec<String>,
14+
}
15+
16+
/// Represents a single part of the query plan processing. Each node is intended to provide a
17+
/// specific behavior given an evaluation context.
18+
pub enum QueryNode {
19+
/// Match the triple pattern against the state. The triple elements can be either a variable or
20+
/// a constant value, in the case of a variable it'll be either provided by the context of
21+
/// previous evaluation or calculated and present in output.
22+
TriplePattern {
23+
subject: PatternValue<Subject>,
24+
predicate: PatternValue<Predicate>,
25+
object: PatternValue<Object>,
26+
},
27+
28+
/// Join two nodes by applying the cartesian product of the nodes variables.
29+
///
30+
/// This should be used when the nodes doesn't have variables in common, and can be seen as a
31+
/// full join of disjoint datasets.
32+
CartesianProductJoin { left: Self, right: Self },
33+
34+
/// Join two nodes by using the variables values from the left node as replacement in the right
35+
/// node.
36+
///
37+
/// This results to an inner join, but the underlying processing stream the variables from the
38+
/// left node to use them as right node values.
39+
ForLoopJoin { left: Self, right: Self },
40+
41+
/// Skip the specified first elements from the child node.
42+
Skip { child: Self, first: usize },
43+
44+
/// Limit to the specified first elements from the child node.
45+
Limit { child: Self, first: usize },
46+
}
47+
48+
pub enum PatternValue<V> {
49+
Constant(V),
50+
Variable(usize),
51+
}

0 commit comments

Comments
 (0)