Skip to content

Commit

Permalink
GH-4232 ensure VALUES clause always covers entire group graph pattern
Browse files Browse the repository at this point in the history
This is the generically correct way to parse VALUES clauses. An
optimizer can potentially look at the ordering in the algebra to push
the values clause down into the join tree (by inspecting which parts of
the tree have variables bound in the VALUES clause).
  • Loading branch information
abrokenjester committed Dec 17, 2022
1 parent 1657d05 commit 60abb41
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,6 +65,8 @@ public class GraphPattern {
*/
private List<ValueExpr> constraints = new ArrayList<>();

private BindingSetAssignment inlineData;

/**
* Creates a new graph pattern.
*/
Expand Down Expand Up @@ -156,6 +159,7 @@ public void clear() {
requiredTEs.clear();
optionalTEs.clear();
constraints.clear();
inlineData = null;
}

/**
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 60abb41

Please sign in to comment.