Adds support of GRAPH evaluation

pull/10/head
Tpt 6 years ago
parent ab43ff1f48
commit 9251ceff49
  1. 14
      lib/src/sparql/eval.rs
  2. 34
      lib/src/sparql/plan.rs

@ -43,11 +43,12 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
match node { match node {
PlanNode::Init => Box::new(once(Ok(from))), PlanNode::Init => Box::new(once(Ok(from))),
PlanNode::StaticBindings { tuples } => Box::new(tuples.into_iter().map(Ok)), PlanNode::StaticBindings { tuples } => Box::new(tuples.into_iter().map(Ok)),
PlanNode::TriplePatternJoin { PlanNode::QuadPatternJoin {
child, child,
subject, subject,
predicate, predicate,
object, object,
graph_name,
} => { } => {
let eval = self.clone(); let eval = self.clone();
Box::new( Box::new(
@ -60,7 +61,9 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
get_pattern_value(&subject, &tuple), get_pattern_value(&subject, &tuple),
get_pattern_value(&predicate, &tuple), get_pattern_value(&predicate, &tuple),
get_pattern_value(&object, &tuple), get_pattern_value(&object, &tuple),
None, //TODO graph_name.and_then(|graph_name| {
get_pattern_value(&graph_name, &tuple)
}),
) { ) {
Ok(mut iter) => { Ok(mut iter) => {
if subject.is_var() && subject == predicate { if subject.is_var() && subject == predicate {
@ -95,6 +98,13 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
&mut new_tuple, &mut new_tuple,
); );
put_pattern_value(&object, quad.object, &mut new_tuple); put_pattern_value(&object, quad.object, &mut new_tuple);
if let Some(graph_name) = graph_name {
put_pattern_value(
&graph_name,
quad.graph_name,
&mut new_tuple,
);
}
Ok(new_tuple) Ok(new_tuple)
})) }))
} }

@ -12,11 +12,12 @@ pub enum PlanNode {
StaticBindings { StaticBindings {
tuples: Vec<EncodedTuple>, tuples: Vec<EncodedTuple>,
}, },
TriplePatternJoin { QuadPatternJoin {
child: Box<PlanNode>, child: Box<PlanNode>,
subject: PatternValue, subject: PatternValue,
predicate: PatternValue, predicate: PatternValue,
object: PatternValue, object: PatternValue,
graph_name: Option<PatternValue>,
}, },
Filter { Filter {
child: Box<PlanNode>, child: Box<PlanNode>,
@ -162,6 +163,7 @@ impl<'a, S: EncodedQuadsStore> PlanBuilder<'a, S> {
pattern, pattern,
PlanNode::Init, PlanNode::Init,
&mut variables, &mut variables,
None,
)?; )?;
Ok((plan, variables)) Ok((plan, variables))
} }
@ -171,13 +173,14 @@ impl<'a, S: EncodedQuadsStore> PlanBuilder<'a, S> {
pattern: &GraphPattern, pattern: &GraphPattern,
input: PlanNode, input: PlanNode,
variables: &mut Vec<Variable>, variables: &mut Vec<Variable>,
graph_name: Option<PatternValue>,
) -> Result<PlanNode> { ) -> Result<PlanNode> {
Ok(match pattern { Ok(match pattern {
GraphPattern::BGP(p) => { GraphPattern::BGP(p) => {
let mut plan = input; let mut plan = input;
for pattern in p { for pattern in p {
plan = match pattern { plan = match pattern {
TripleOrPathPattern::Triple(pattern) => PlanNode::TriplePatternJoin { TripleOrPathPattern::Triple(pattern) => PlanNode::QuadPatternJoin {
child: Box::new(plan), child: Box::new(plan),
subject: self subject: self
.pattern_value_from_term_or_variable(&pattern.subject, variables)?, .pattern_value_from_term_or_variable(&pattern.subject, variables)?,
@ -187,6 +190,7 @@ impl<'a, S: EncodedQuadsStore> PlanBuilder<'a, S> {
)?, )?,
object: self object: self
.pattern_value_from_term_or_variable(&pattern.object, variables)?, .pattern_value_from_term_or_variable(&pattern.object, variables)?,
graph_name,
}, },
TripleOrPathPattern::Path(pattern) => unimplemented!(), TripleOrPathPattern::Path(pattern) => unimplemented!(),
} }
@ -195,12 +199,13 @@ impl<'a, S: EncodedQuadsStore> PlanBuilder<'a, S> {
} }
GraphPattern::Join(a, b) => self.build_for_graph_pattern( GraphPattern::Join(a, b) => self.build_for_graph_pattern(
b, b,
self.build_for_graph_pattern(a, input, variables)?, self.build_for_graph_pattern(a, input, variables, graph_name)?,
variables, variables,
graph_name,
)?, )?,
GraphPattern::LeftJoin(a, b, e) => unimplemented!(), GraphPattern::LeftJoin(a, b, e) => unimplemented!(),
GraphPattern::Filter(e, p) => PlanNode::Filter { GraphPattern::Filter(e, p) => PlanNode::Filter {
child: Box::new(self.build_for_graph_pattern(p, input, variables)?), child: Box::new(self.build_for_graph_pattern(p, input, variables, graph_name)?),
expression: self.build_for_expression(e, variables)?, expression: self.build_for_expression(e, variables)?,
}, },
GraphPattern::Union(a, b) => { GraphPattern::Union(a, b) => {
@ -218,6 +223,7 @@ impl<'a, S: EncodedQuadsStore> PlanBuilder<'a, S> {
a, a,
PlanNode::Init, PlanNode::Init,
variables, variables,
graph_name,
)?), )?),
} }
} }
@ -226,9 +232,12 @@ impl<'a, S: EncodedQuadsStore> PlanBuilder<'a, S> {
children, children,
} }
} }
GraphPattern::Graph(g, p) => unimplemented!(), GraphPattern::Graph(g, p) => {
let graph_name = self.pattern_value_from_named_node_or_variable(g, variables)?;
self.build_for_graph_pattern(p, input, variables, Some(graph_name))?
}
GraphPattern::Extend(p, v, e) => PlanNode::Extend { GraphPattern::Extend(p, v, e) => PlanNode::Extend {
child: Box::new(self.build_for_graph_pattern(p, input, variables)?), child: Box::new(self.build_for_graph_pattern(p, input, variables, graph_name)?),
position: variable_key(variables, &v), position: variable_key(variables, &v),
expression: self.build_for_expression(e, variables)?, expression: self.build_for_expression(e, variables)?,
}, },
@ -238,12 +247,15 @@ impl<'a, S: EncodedQuadsStore> PlanBuilder<'a, S> {
GraphPattern::Data(bs) => PlanNode::StaticBindings { GraphPattern::Data(bs) => PlanNode::StaticBindings {
tuples: self.encode_bindings(bs, variables)?, tuples: self.encode_bindings(bs, variables)?,
}, },
GraphPattern::OrderBy(l, o) => self.build_for_graph_pattern(l, input, variables)?, //TODO GraphPattern::OrderBy(l, o) => {
self.build_for_graph_pattern(l, input, variables, graph_name)?
} //TODO
GraphPattern::Project(l, new_variables) => PlanNode::Project { GraphPattern::Project(l, new_variables) => PlanNode::Project {
child: Box::new(self.build_for_graph_pattern( child: Box::new(self.build_for_graph_pattern(
l, l,
input, input,
&mut new_variables.clone(), &mut new_variables.clone(),
graph_name,
)?), )?),
mapping: new_variables mapping: new_variables
.iter() .iter()
@ -251,11 +263,13 @@ impl<'a, S: EncodedQuadsStore> PlanBuilder<'a, S> {
.collect(), .collect(),
}, },
GraphPattern::Distinct(l) => PlanNode::HashDeduplicate { GraphPattern::Distinct(l) => PlanNode::HashDeduplicate {
child: Box::new(self.build_for_graph_pattern(l, input, variables)?), child: Box::new(self.build_for_graph_pattern(l, input, variables, graph_name)?),
}, },
GraphPattern::Reduced(l) => self.build_for_graph_pattern(l, input, variables)?, GraphPattern::Reduced(l) => {
self.build_for_graph_pattern(l, input, variables, graph_name)?
}
GraphPattern::Slice(l, start, length) => { GraphPattern::Slice(l, start, length) => {
let mut plan = self.build_for_graph_pattern(l, input, variables)?; let mut plan = self.build_for_graph_pattern(l, input, variables, graph_name)?;
if *start > 0 { if *start > 0 {
plan = PlanNode::Skip { plan = PlanNode::Skip {
child: Box::new(plan), child: Box::new(plan),

Loading…
Cancel
Save