-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-5121: implementation of left bind join operator
This change provides the implementation and activation for the left bind join operator. The algorithm is as follows: - execute left bind join using regular bound join query - process result iteration similar to BoundJoinVALUESConversionIteration - remember seen set of bindings (using index) and add original bindings to those, i.e. put to result return all non-seen bindings directly from the input Note that the terminology in literature has changed to "bind joins". Hence, for new classes and methods I try to follow that. Change is covered with some unit tests
- Loading branch information
1 parent
3cc78db
commit 40b03a5
Showing
6 changed files
with
527 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
.../src/main/java/org/eclipse/rdf4j/federated/evaluation/iterator/BindLeftJoinIteration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Eclipse RDF4J contributors. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Distribution License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*******************************************************************************/ | ||
package org.eclipse.rdf4j.federated.evaluation.iterator; | ||
|
||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.ListIterator; | ||
import java.util.Set; | ||
|
||
import org.eclipse.rdf4j.common.iteration.CloseableIteration; | ||
import org.eclipse.rdf4j.common.iteration.LookAheadIteration; | ||
import org.eclipse.rdf4j.query.Binding; | ||
import org.eclipse.rdf4j.query.BindingSet; | ||
import org.eclipse.rdf4j.query.QueryEvaluationException; | ||
import org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet; | ||
|
||
/** | ||
* A {@link LookAheadIteration} for processing bind left join results (i.e., result of joining OPTIONAL clauses) | ||
* | ||
* Algorithm: | ||
* | ||
* <ul> | ||
* <li>execute left bind join using regular bound join query</li> | ||
* <li>process result iteration similar to {@link BoundJoinVALUESConversionIteration}</li> | ||
* <li>remember seen set of bindings (using index) and add original bindings to those, i.e. put to result return all | ||
* non-seen bindings directly from the input</li> | ||
* | ||
* | ||
* @author Andreas Schwarte | ||
*/ | ||
public class BindLeftJoinIteration extends LookAheadIteration<BindingSet> { | ||
|
||
protected final CloseableIteration<BindingSet> iter; | ||
protected final List<BindingSet> bindings; | ||
|
||
protected Set<Integer> seenBindingIndexes = new HashSet<>(); | ||
protected final ListIterator<BindingSet> bindingsIterator; | ||
|
||
public BindLeftJoinIteration(CloseableIteration<BindingSet> iter, | ||
List<BindingSet> bindings) { | ||
this.iter = iter; | ||
this.bindings = bindings; | ||
this.bindingsIterator = bindings.listIterator(); | ||
} | ||
|
||
@Override | ||
protected BindingSet getNextElement() { | ||
|
||
if (iter.hasNext()) { | ||
var bIn = iter.next(); | ||
int bIndex = Integer.parseInt( | ||
bIn.getBinding(BoundJoinVALUESConversionIteration.INDEX_BINDING_NAME).getValue().stringValue()); | ||
seenBindingIndexes.add(bIndex); | ||
return convert(bIn, bIndex); | ||
} | ||
|
||
while (bindingsIterator.hasNext()) { | ||
if (seenBindingIndexes.contains(bindingsIterator.nextIndex())) { | ||
// the binding was already processed as part of the optional | ||
bindingsIterator.next(); | ||
continue; | ||
} | ||
return bindingsIterator.next(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
protected void handleClose() { | ||
iter.close(); | ||
} | ||
|
||
protected BindingSet convert(BindingSet bIn, int bIndex) throws QueryEvaluationException { | ||
QueryBindingSet res = new QueryBindingSet(); | ||
Iterator<Binding> bIter = bIn.iterator(); | ||
while (bIter.hasNext()) { | ||
Binding b = bIter.next(); | ||
if (b.getName().equals(BoundJoinVALUESConversionIteration.INDEX_BINDING_NAME)) { | ||
continue; | ||
} | ||
res.addBinding(b); | ||
} | ||
for (Binding bs : bindings.get(bIndex)) { | ||
res.setBinding(bs); | ||
} | ||
return res; | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
...c/main/java/org/eclipse/rdf4j/federated/evaluation/join/ControlledWorkerBindLeftJoin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Eclipse RDF4J contributors. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Distribution License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*******************************************************************************/ | ||
package org.eclipse.rdf4j.federated.evaluation.join; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.rdf4j.common.iteration.CloseableIteration; | ||
import org.eclipse.rdf4j.federated.algebra.StatementTupleExpr; | ||
import org.eclipse.rdf4j.federated.evaluation.FederationEvalStrategy; | ||
import org.eclipse.rdf4j.federated.evaluation.concurrent.ControlledWorkerScheduler; | ||
import org.eclipse.rdf4j.federated.evaluation.concurrent.ParallelExecutor; | ||
import org.eclipse.rdf4j.federated.evaluation.concurrent.ParallelTask; | ||
import org.eclipse.rdf4j.federated.structures.QueryInfo; | ||
import org.eclipse.rdf4j.query.BindingSet; | ||
import org.eclipse.rdf4j.query.QueryEvaluationException; | ||
import org.eclipse.rdf4j.query.algebra.TupleExpr; | ||
|
||
/** | ||
* Bind join implementation for left joins (i.e., OPTIOAL clauses) | ||
* | ||
* @author Andreas Schwarte | ||
*/ | ||
public class ControlledWorkerBindLeftJoin extends ControlledWorkerBindJoinBase { | ||
|
||
public ControlledWorkerBindLeftJoin(ControlledWorkerScheduler<BindingSet> scheduler, | ||
FederationEvalStrategy strategy, CloseableIteration<BindingSet> leftIter, TupleExpr rightArg, | ||
BindingSet bindings, QueryInfo queryInfo) throws QueryEvaluationException { | ||
super(scheduler, strategy, leftIter, rightArg, bindings, queryInfo); | ||
} | ||
|
||
@Override | ||
protected TaskCreator determineTaskCreator(TupleExpr expr, BindingSet bs) { | ||
final TaskCreator taskCreator; | ||
if (expr instanceof StatementTupleExpr) { | ||
StatementTupleExpr stmt = (StatementTupleExpr) expr; | ||
taskCreator = new LeftBoundJoinTaskCreator(strategy, stmt); | ||
|
||
} else { | ||
throw new RuntimeException("Expr is of unexpected type: " + expr.getClass().getCanonicalName() | ||
+ ". Please report this problem."); | ||
} | ||
return taskCreator; | ||
} | ||
|
||
static protected class LeftBoundJoinTaskCreator implements TaskCreator { | ||
protected final FederationEvalStrategy _strategy; | ||
protected final StatementTupleExpr _expr; | ||
|
||
public LeftBoundJoinTaskCreator( | ||
FederationEvalStrategy strategy, StatementTupleExpr expr) { | ||
super(); | ||
_strategy = strategy; | ||
_expr = expr; | ||
} | ||
|
||
@Override | ||
public ParallelTask<BindingSet> getTask(ParallelExecutor<BindingSet> control, List<BindingSet> bindings) { | ||
return new ParallelBindLeftJoinTask(control, _strategy, _expr, bindings); | ||
} | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...n/src/main/java/org/eclipse/rdf4j/federated/evaluation/join/ParallelBindLeftJoinTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Eclipse RDF4J contributors. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Distribution License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*******************************************************************************/ | ||
package org.eclipse.rdf4j.federated.evaluation.join; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.rdf4j.common.iteration.CloseableIteration; | ||
import org.eclipse.rdf4j.federated.algebra.StatementTupleExpr; | ||
import org.eclipse.rdf4j.federated.evaluation.FederationEvalStrategy; | ||
import org.eclipse.rdf4j.federated.evaluation.concurrent.ParallelExecutor; | ||
import org.eclipse.rdf4j.federated.evaluation.concurrent.ParallelTaskBase; | ||
import org.eclipse.rdf4j.query.BindingSet; | ||
|
||
/** | ||
* A {@link ParallelTaskBase} for executing bind left joins. | ||
* | ||
* @author Andreas Schwarte | ||
* @see FederationEvalStrategy#evaluateLeftBoundJoinStatementPattern(StatementTupleExpr, List) | ||
*/ | ||
public class ParallelBindLeftJoinTask extends ParallelTaskBase<BindingSet> { | ||
|
||
protected final FederationEvalStrategy strategy; | ||
protected final StatementTupleExpr rightArg; | ||
protected final List<BindingSet> bindings; | ||
protected final ParallelExecutor<BindingSet> joinControl; | ||
|
||
public ParallelBindLeftJoinTask(ParallelExecutor<BindingSet> joinControl, FederationEvalStrategy strategy, | ||
StatementTupleExpr expr, List<BindingSet> bindings) { | ||
this.strategy = strategy; | ||
this.rightArg = expr; | ||
this.bindings = bindings; | ||
this.joinControl = joinControl; | ||
} | ||
|
||
@Override | ||
public ParallelExecutor<BindingSet> getControl() { | ||
return joinControl; | ||
} | ||
|
||
@Override | ||
protected CloseableIteration<BindingSet> performTaskInternal() throws Exception { | ||
return strategy.evaluateLeftBoundJoinStatementPattern(rightArg, bindings); | ||
} | ||
|
||
} |
Oops, something went wrong.