Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hmottestad committed Nov 28, 2024
1 parent dcbd4c5 commit 57df70a
Showing 1 changed file with 30 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,11 @@ protected QueryEvaluationStep prepare(Join node, QueryEvaluationContext context)
}

try {
if (leftArg instanceof StatementPattern && rightArg instanceof StatementPattern
&& tripleSource instanceof EndpointTripleSource) {
StatementPattern left = (StatementPattern) leftArg;
StatementPattern right = (StatementPattern) rightArg;
EndpointTripleSource endpointTripleSource = (EndpointTripleSource) tripleSource;

HDTValue leftSubject = left.getSubjectVar() != null ? (HDTValue) left.getSubjectVar().getValue() : null;
SimpleIRIHDT leftPredicate = left.getPredicateVar() != null
? (SimpleIRIHDT) left.getPredicateVar().getValue()
: null;
HDTValue leftObject = left.getObjectVar() != null ? (HDTValue) left.getObjectVar().getValue() : null;
HDTValue leftContext = left.getContextVar() != null ? (HDTValue) left.getContextVar().getValue() : null;

HDTValue rightSubject = right.getSubjectVar() != null ? (HDTValue) right.getSubjectVar().getValue()
: null;
SimpleIRIHDT rightPredicate = right.getPredicateVar() != null
? (SimpleIRIHDT) right.getPredicateVar().getValue()
: null;
HDTValue rightObject = right.getObjectVar() != null ? (HDTValue) right.getObjectVar().getValue() : null;
HDTValue rightContext = right.getContextVar() != null ? (HDTValue) right.getContextVar().getValue()
: null;
if (leftArg instanceof StatementPattern left && rightArg instanceof StatementPattern right
&& tripleSource instanceof EndpointTripleSource endpointTripleSource) {

HDTValues leftValues = getHdtValues(left);
HDTValues rightValues = getHdtValues(right);

try {
if (!left.getSubjectVar().getName().equals(right.getSubjectVar().getName())) {
Expand Down Expand Up @@ -145,30 +129,25 @@ protected QueryEvaluationStep prepare(Join node, QueryEvaluationContext context)

node.setAlgorithm("ProtoypeJoinIterator");

QueryEvaluationStep queryEvaluationStep = new QueryEvaluationStep() {

CloseableIteration<TripleID> left;

@Override
public CloseableIteration<BindingSet> evaluate(BindingSet bindings) {
if (!bindings.isEmpty()) {
throw new UnsupportedOperationException("Query bindings are not supported");
}
// we will implement a very simple join on the subject
return bindings -> {
if (!bindings.isEmpty()) {
throw new UnsupportedOperationException("Query bindings are not supported");
}

// we will implement a very simple join on the subject
// we will implement a very simple join on the subject

CloseableIteration<TripleID> statements = endpointTripleSource.prototypeGetStatements(null,
leftSubject != null ? leftSubject.getHDTId() : 0,
leftPredicate != null ? leftPredicate.getHDTId() : 0,
leftObject != null ? leftObject.getHDTId() : 0,
leftContext != null ? leftContext.getHDTId() : 0);
CloseableIteration<TripleID> statements = endpointTripleSource.prototypeGetStatements(null,
leftValues.subject() != null ? leftValues.subject().getHDTId() : 0,
leftValues.predicate() != null ? leftValues.predicate().getHDTId() : 0,
leftValues.object() != null ? leftValues.object().getHDTId() : 0,
leftValues.context() != null ? leftValues.context().getHDTId() : 0);

return new ProtoypeJoinIterator(statements, rightPredicate, rightObject, rightContext,
endpointTripleSource, (StatementPattern) leftArg, (StatementPattern) rightArg);
return new ProtoypeJoinIterator(statements, rightValues.predicate(), rightValues.object(),
rightValues.context(), endpointTripleSource, (StatementPattern) leftArg,
(StatementPattern) rightArg);

}
};
return queryEvaluationStep;

}

Expand All @@ -180,4 +159,15 @@ public CloseableIteration<BindingSet> evaluate(BindingSet bindings) {

return super.prepare(node, context);
}

private static HDTValues getHdtValues(StatementPattern left) {
HDTValue leftSubject = left.getSubjectVar() != null ? (HDTValue) left.getSubjectVar().getValue() : null;
SimpleIRIHDT leftPredicate = left.getPredicateVar() != null ? (SimpleIRIHDT) left.getPredicateVar().getValue()
: null;
HDTValue leftObject = left.getObjectVar() != null ? (HDTValue) left.getObjectVar().getValue() : null;
HDTValue leftContext = left.getContextVar() != null ? (HDTValue) left.getContextVar().getValue() : null;
return new HDTValues(leftSubject, leftPredicate, leftObject, leftContext);
}

private record HDTValues(HDTValue subject, SimpleIRIHDT predicate, HDTValue object, HDTValue context) {}
}

0 comments on commit 57df70a

Please sign in to comment.