Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hmottestad committed Oct 13, 2023
1 parent 221bbcb commit 79e4aee
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public CloseableIteration<BindingSet> evaluate(TupleExpr expr, BindingSet bindin
} else if (expr instanceof SingletonSet) {
result = precompile(expr).evaluate(bindings);
} else if (expr instanceof EmptySet) {
result = new EmptyIteration<>();
result = QueryEvaluationStep.EMPTY_ITERATION;
} else if (expr instanceof ZeroLengthPath) {
result = precompile(expr).evaluate(bindings);
} else if (expr instanceof ArbitraryLengthPath) {
Expand Down Expand Up @@ -624,7 +624,7 @@ protected QueryEvaluationStep prepare(Filter node, QueryEvaluationContext contex
// If we have a failed compilation we always return false.
// Which means empty. so let's short circuit that.
// ves = new QueryValueEvaluationStep.ConstantQueryValueEvaluationStep(BooleanLiteral.FALSE);
return bs -> new EmptyIteration<>();
return bs -> QueryEvaluationStep.EMPTY_ITERATION;
}
return bs -> {
CloseableIteration<BindingSet> evaluate = null;
Expand Down Expand Up @@ -839,7 +839,7 @@ protected QueryEvaluationStep prepare(SingletonSet singletonSet, QueryEvaluation

protected QueryEvaluationStep prepare(EmptySet emptySet, QueryEvaluationContext context)
throws QueryEvaluationException {
return bindings -> new EmptyIteration<>();
return bindings -> QueryEvaluationStep.EMPTY_ITERATION;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public JoinQueryEvaluationStep(EvaluationStrategy strategy, Join join, QueryEval
joinAttributes, context);
join.setAlgorithm(HashJoinIteration.class.getSimpleName());
} else {
eval = bindings -> new JoinIterator(leftPrepared, rightPrepared, bindings);
eval = bindings -> JoinIterator.getInstance(leftPrepared, rightPrepared, bindings);
join.setAlgorithm(JoinIterator.class.getSimpleName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public CloseableIteration<BindingSet> evaluate(BindingSet bindings) {
evaluate = leftQes.evaluate(bindings);
evaluate1 = rightQes.evaluate(bindings);

if (evaluate instanceof EmptyIteration) {
if (evaluate == QueryEvaluationStep.EMPTY_ITERATION) {
return evaluate1;
} else if (evaluate1 instanceof EmptyIteration) {
} else if (evaluate1 == QueryEvaluationStep.EMPTY_ITERATION) {
return evaluate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.eclipse.rdf4j.query.algebra.StatementPattern;
import org.eclipse.rdf4j.query.algebra.Var;
import org.eclipse.rdf4j.query.algebra.evaluation.EvaluationStrategy;
import org.eclipse.rdf4j.query.algebra.evaluation.QueryEvaluationStep;
import org.eclipse.rdf4j.query.algebra.evaluation.QueryValueEvaluationStep;

/**
* Iteration that implements a simplified version of Symmetric Concise Bounded Description (omitting reified
Expand Down Expand Up @@ -208,7 +210,7 @@ protected BindingSet getNextElement() throws QueryEvaluationException {
protected CloseableIteration<BindingSet> createNextIteration(Value subject, Value object)
throws QueryEvaluationException {
if (subject == null && object == null) {
return new EmptyIteration<>();
return QueryEvaluationStep.EMPTY_ITERATION;
}

Var subjVar = new Var(VARNAME_SUBJECT, subject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,33 @@
* @author Jeen Broekstra
*/
public class JoinIterator extends LookAheadIteration<BindingSet> {
public static final EmptyIteration<BindingSet> EMPTY_ITERATION = new EmptyIteration<>();

/*-----------*
* Variables *
*-----------*/

private final CloseableIteration<BindingSet> leftIter;

private CloseableIteration<BindingSet> rightIter;

private final QueryEvaluationStep preparedRight;

/*--------------*
* Constructors *
*--------------*/

public JoinIterator(QueryEvaluationStep leftPrepared,
QueryEvaluationStep rightPrepared, BindingSet bindings) throws QueryEvaluationException {
QueryEvaluationStep preparedRight, BindingSet bindings) throws QueryEvaluationException {
leftIter = leftPrepared.evaluate(bindings);
this.preparedRight = preparedRight;
}

private JoinIterator(CloseableIteration<BindingSet> leftIter, QueryEvaluationStep preparedRight)
throws QueryEvaluationException {
this.leftIter = leftIter;
this.preparedRight = preparedRight;
}

public static CloseableIteration<BindingSet> getInstance(QueryEvaluationStep leftPrepared,
QueryEvaluationStep preparedRight, BindingSet bindings) {
CloseableIteration<BindingSet> leftIter = leftPrepared.evaluate(bindings);
if (leftIter == QueryEvaluationStep.EMPTY_ITERATION) {
return leftIter;
}

this.preparedRight = rightPrepared;
return new JoinIterator(leftIter, preparedRight);
}

/*---------*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import org.eclipse.rdf4j.query.algebra.evaluation.util.QueryEvaluationUtility;

public class LeftJoinIterator extends LookAheadIteration<BindingSet> {
public static final EmptyIteration<BindingSet> EMPTY_ITERATION = new EmptyIteration<>();

/*-----------*
* Variables *
*-----------*/
Expand Down Expand Up @@ -63,7 +61,7 @@ public LeftJoinIterator(EvaluationStrategy strategy, LeftJoin join, BindingSet b
leftIter = strategy.evaluate(join.getLeftArg(), bindings);

// Initialize with empty iteration so that var is never null
rightIter = EMPTY_ITERATION;
rightIter = QueryEvaluationStep.EMPTY_ITERATION;

prepareRightArg = strategy.precompile(join.getRightArg(), context);
join.setAlgorithm(this);
Expand All @@ -83,7 +81,7 @@ public LeftJoinIterator(QueryEvaluationStep left, QueryEvaluationStep right, Que
leftIter = left.evaluate(bindings);

// Initialize with empty iteration so that var is never null
rightIter = EMPTY_ITERATION;
rightIter = QueryEvaluationStep.EMPTY_ITERATION;

prepareRightArg = right;
this.joinCondition = joinCondition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ private void testBindingSetAssignmentJoin(int expectedSize, int n, BindingSet bi
right.setBindingSets(rightb);
}

JoinIterator lrIter = new JoinIterator(evaluator.precompile(left), evaluator.precompile(right), bindings);
var lrIter = JoinIterator.getInstance(evaluator.precompile(left), evaluator.precompile(right), bindings);
Set<BindingSet> lr = Iterations.asSet(lrIter);
assertEquals(expectedSize, lr.size());

JoinIterator rlIter = new JoinIterator(evaluator.precompile(right), evaluator.precompile(left), bindings);
var rlIter = JoinIterator.getInstance(evaluator.precompile(right), evaluator.precompile(left), bindings);
Set<BindingSet> rl = Iterations.asSet(rlIter);
assertEquals(expectedSize, rl.size());

Expand Down

0 comments on commit 79e4aee

Please sign in to comment.