Skip to content

Commit

Permalink
GH-5121: code simplifications in bind join implementation
Browse files Browse the repository at this point in the history
- use for-each loop for iterating bindingset
- use IntHashSet
- use Literal#intValue instead of Integer#parseInt
  • Loading branch information
aschwarte10 committed Sep 29, 2024
1 parent 2a7075a commit 01bc075
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
*******************************************************************************/
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.collections.impl.set.mutable.primitive.IntHashSet;
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.common.iteration.LookAheadIteration;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.query.Binding;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.QueryEvaluationException;
Expand All @@ -42,7 +41,7 @@ public class BindLeftJoinIteration extends LookAheadIteration<BindingSet> {
protected final CloseableIteration<BindingSet> iter;
protected final List<BindingSet> bindings;

protected Set<Integer> seenBindingIndexes = new HashSet<>();
protected IntHashSet seenBindingIndexes = new IntHashSet();
protected final ListIterator<BindingSet> bindingsIterator;

public BindLeftJoinIteration(CloseableIteration<BindingSet> iter,
Expand All @@ -57,8 +56,7 @@ protected BindingSet getNextElement() {

if (iter.hasNext()) {
var bIn = iter.next();
int bIndex = Integer.parseInt(
bIn.getBinding(BoundJoinVALUESConversionIteration.INDEX_BINDING_NAME).getValue().stringValue());
int bIndex = ((Literal) bIn.getValue(BoundJoinVALUESConversionIteration.INDEX_BINDING_NAME)).intValue();
seenBindingIndexes.add(bIndex);
return convert(bIn, bIndex);
}
Expand All @@ -82,9 +80,7 @@ protected void handleClose() {

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();
for (Binding b : bIn) {
if (b.getName().equals(BoundJoinVALUESConversionIteration.INDEX_BINDING_NAME)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
*******************************************************************************/
package org.eclipse.rdf4j.federated.evaluation.iterator;

import java.util.Iterator;
import java.util.List;

import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.common.iteration.ConvertingIteration;
import org.eclipse.rdf4j.federated.evaluation.SparqlFederationEvalStrategy;
import org.eclipse.rdf4j.federated.util.QueryStringUtil;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.query.Binding;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.QueryEvaluationException;
Expand Down Expand Up @@ -53,10 +53,8 @@ public BoundJoinVALUESConversionIteration(CloseableIteration<BindingSet> iter,
@Override
protected BindingSet convert(BindingSet bIn) throws QueryEvaluationException {
QueryBindingSet res = new QueryBindingSet();
int bIndex = Integer.parseInt(bIn.getBinding(INDEX_BINDING_NAME).getValue().stringValue());
Iterator<Binding> bIter = bIn.iterator();
while (bIter.hasNext()) {
Binding b = bIter.next();
int bIndex = ((Literal) bIn.getValue(BoundJoinVALUESConversionIteration.INDEX_BINDING_NAME)).intValue();
for (Binding b : bIn) {
if (b.getName().equals(INDEX_BINDING_NAME)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.Set;

import org.eclipse.rdf4j.common.iteration.Iterations;
import org.eclipse.rdf4j.federated.monitoring.MonitoringUtil;
import org.eclipse.rdf4j.model.util.Values;
import org.eclipse.rdf4j.model.vocabulary.FOAF;
import org.eclipse.rdf4j.model.vocabulary.OWL;
Expand Down Expand Up @@ -213,8 +212,6 @@ public void testBoundLeftJoin_stmt_nonExclusive_boundCheck(boolean bindLeftJoinO

Assertions.assertEquals(30, bindings.size());

MonitoringUtil.printMonitoringInformation(federationContext());

for (int i = 1; i <= 30; i++) {
var p = Values.iri("http://ex.com/p" + i);
var otherP = Values.iri("http://other.com/p" + i);
Expand Down

0 comments on commit 01bc075

Please sign in to comment.