diff --git a/lib/src/sparql/eval.rs b/lib/src/sparql/eval.rs index 82862db3..255323a3 100644 --- a/lib/src/sparql/eval.rs +++ b/lib/src/sparql/eval.rs @@ -2703,8 +2703,8 @@ fn get_triple_template_value<'a>( TripleTemplateValue::Triple(triple) => Some( EncodedTriple { subject: get_triple_template_value(&triple.subject, tuple, bnodes)?, - predicate: get_triple_template_value(&triple.subject, tuple, bnodes)?, - object: get_triple_template_value(&triple.subject, tuple, bnodes)?, + predicate: get_triple_template_value(&triple.predicate, tuple, bnodes)?, + object: get_triple_template_value(&triple.object, tuple, bnodes)?, } .into(), ), diff --git a/spargebra/src/algebra.rs b/spargebra/src/algebra.rs index 1456701d..5714eb16 100644 --- a/spargebra/src/algebra.rs +++ b/spargebra/src/algebra.rs @@ -648,15 +648,7 @@ impl GraphPattern { match self { GraphPattern::Bgp(p) => { for pattern in p { - if let TermPattern::Variable(s) = &pattern.subject { - vars.insert(s); - } - if let NamedNodePattern::Variable(p) = &pattern.predicate { - vars.insert(p); - } - if let TermPattern::Variable(o) = &pattern.object { - vars.insert(o); - } + add_triple_pattern_variables(pattern, vars) } } GraphPattern::Path { @@ -664,9 +656,13 @@ impl GraphPattern { } => { if let TermPattern::Variable(s) = subject { vars.insert(s); + } else if let TermPattern::Triple(s) = subject { + add_triple_pattern_variables(s, vars) } if let TermPattern::Variable(o) = object { vars.insert(o); + } else if let TermPattern::Triple(o) = object { + add_triple_pattern_variables(o, vars) } } GraphPattern::Join { left, right } @@ -704,6 +700,22 @@ impl GraphPattern { } } +fn add_triple_pattern_variables<'a>(pattern: &'a TriplePattern, vars: &mut BTreeSet<&'a Variable>) { + if let TermPattern::Variable(s) = &pattern.subject { + vars.insert(s); + } else if let TermPattern::Triple(s) = &pattern.subject { + add_triple_pattern_variables(s, vars) + } + if let NamedNodePattern::Variable(p) = &pattern.predicate { + vars.insert(p); + } + if let TermPattern::Variable(o) = &pattern.object { + vars.insert(o); + } else if let TermPattern::Triple(o) = &pattern.object { + add_triple_pattern_variables(o, vars) + } +} + struct SparqlGraphPattern<'a>(&'a GraphPattern); impl<'a> fmt::Display for SparqlGraphPattern<'a> {