diff --git a/core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/GraphPattern.java b/core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/GraphPattern.java index ea764e486e1..0aeb74e4f69 100644 --- a/core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/GraphPattern.java +++ b/core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/GraphPattern.java @@ -19,6 +19,7 @@ import org.eclipse.rdf4j.common.annotation.InternalUseOnly; import org.eclipse.rdf4j.query.algebra.And; +import org.eclipse.rdf4j.query.algebra.BindingSetAssignment; import org.eclipse.rdf4j.query.algebra.Filter; import org.eclipse.rdf4j.query.algebra.Join; import org.eclipse.rdf4j.query.algebra.LeftJoin; @@ -64,6 +65,8 @@ public class GraphPattern { */ private List constraints = new ArrayList<>(); + private BindingSetAssignment inlineData; + /** * Creates a new graph pattern. */ @@ -156,6 +159,7 @@ public void clear() { requiredTEs.clear(); optionalTEs.clear(); constraints.clear(); + inlineData = null; } /** @@ -195,7 +199,19 @@ public TupleExpr buildTupleExpr() { result = new Filter(result, constraint); } + if (getInlineData() != null) { + result = new Join(getInlineData(), result); + } + return result; } + public BindingSetAssignment getInlineData() { + return inlineData; + } + + public void setInlineData(BindingSetAssignment bsa) { + this.inlineData = bsa; + } + } diff --git a/core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/TupleExprBuilder.java b/core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/TupleExprBuilder.java index 177b703f1b6..65a18c90096 100644 --- a/core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/TupleExprBuilder.java +++ b/core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/TupleExprBuilder.java @@ -2073,7 +2073,22 @@ public BindingSetAssignment visit(ASTInlineData node, Object data) throws Visito bsa.setBindingSets(bindingSets); - graphPattern.addRequiredTE(bsa); + if (graphPattern.getInlineData() != null) { + GraphPattern parentGP = graphPattern; + graphPattern = new GraphPattern(parentGP); + + graphPattern.setInlineData(bsa); + + TupleExpr te = graphPattern.buildTupleExpr(); + if (node.isScopeChange()) { + ((VariableScopeChange) te).setVariableScopeChange(true); + } + parentGP.addRequiredTE(te); + + graphPattern = parentGP; + } else { + graphPattern.setInlineData(bsa); + } return bsa; }