Skip to content

Commit

Permalink
GH-4659 Fix for shared var name between context and subject in Statem…
Browse files Browse the repository at this point in the history
…entPatternQueryEvaluationStep (#4677)
  • Loading branch information
hmottestad authored Jul 21, 2023
2 parents 8b95eae + 878255a commit 3518f72
Show file tree
Hide file tree
Showing 5 changed files with 368 additions and 311 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class GenericPlanNode {
private final static String uniqueIdPrefix = UUID.randomUUID().toString().replace("-", "");
private final static AtomicLong uniqueIdSuffix = new AtomicLong();

private static final String spoc[] = { "s", "p", "o", "c" };

private final static String newLine = System.getProperty("line.separator");

private final String id = "UUID_" + uniqueIdPrefix + uniqueIdSuffix.incrementAndGet();
Expand Down Expand Up @@ -292,28 +294,47 @@ private String getHumanReadable(int prettyBoxDrawingType) {

String left = plans.get(0).getHumanReadable(prettyBoxDrawingType + 1);
String right = plans.get(1).getHumanReadable(prettyBoxDrawingType + 1);
boolean join = type.contains("Join");

{
String[] split = left.split(newLine);
sb.append(start).append(horizontal).append(split[0]).append(newLine);
sb.append(start).append(horizontal).append(" ").append(split[0]);
if (join)
sb.append(" [left]");
sb.append(newLine);
for (int i = 1; i < split.length; i++) {
sb.append(vertical).append(" ").append(split[i]).append(newLine);
}
}

{
String[] split = right.split(newLine);
sb.append(end).append(horizontal).append(split[0]).append(newLine);
sb.append(end).append(horizontal).append(" ").append(split[0]);
if (join)
sb.append(" [right]");
sb.append(newLine);

for (int i = 1; i < split.length; i++) {
sb.append(" ").append(split[i]).append(newLine);
}
}

} else {
plans.forEach(
child -> sb.append(Arrays.stream(child.getHumanReadable(prettyBoxDrawingType + 1).split(newLine))
.map(c -> " " + c)
.reduce((a, b) -> a + newLine + b)
.orElse("") + newLine));

for (int i = 0; i < plans.size(); i++) {
GenericPlanNode child = plans.get(i);
int j = i;
sb.append(Arrays.stream(child.getHumanReadable(prettyBoxDrawingType + 1).split(newLine))
.map(c -> {
if (type.startsWith("StatementPattern") && child.type.startsWith("Var")) {
return spoc[j] + ": " + c;
}
return c;
})
.map(c -> " " + c)
.reduce((a, b) -> a + newLine + b)
.orElse("")).append(newLine);
}
}

return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ public StatementPatternQueryEvaluationStep(StatementPattern statementPattern, Qu
Var objVar = statementPattern.getObjectVar();
Var conVar = statementPattern.getContextVar();

// First create the getters before removing duplicate vars since we need the getters when creating
// JoinStatementWithBindingSetIterator. If there are duplicate vars, for instance ?v1 as both subject and
// context then we still need to bind the value from ?v1 in the subject and context arguments of
// getStatement(...).
getContextVar = makeGetVarValue(conVar, context);
getSubjectVar = makeGetVarValue(subjVar, context);
getPredicateVar = makeGetVarValue(predVar, context);
getObjectVar = makeGetVarValue(objVar, context);

// then remove duplicate vars
if (subjVar != null) {
if (predVar != null && predVar.getName().equals(subjVar.getName())) {
predVar = null;
Expand Down Expand Up @@ -125,11 +135,6 @@ public StatementPatternQueryEvaluationStep(StatementPattern statementPattern, Qu

unboundTest = getUnboundTest(context, subjVar, predVar, objVar, conVar);

getContextVar = makeGetVarValue(conVar, context);
getSubjectVar = makeGetVarValue(subjVar, context);
getPredicateVar = makeGetVarValue(predVar, context);
getObjectVar = makeGetVarValue(objVar, context);

}

// test if the variable must remain unbound for this solution see
Expand Down
Loading

0 comments on commit 3518f72

Please sign in to comment.