From 01bc075a8b07eac9056390e060a84e77437da0c1 Mon Sep 17 00:00:00 2001 From: Andreas Schwarte Date: Sun, 29 Sep 2024 13:26:14 +0200 Subject: [PATCH] GH-5121: code simplifications in bind join implementation - use for-each loop for iterating bindingset - use IntHashSet - use Literal#intValue instead of Integer#parseInt --- .../evaluation/iterator/BindLeftJoinIteration.java | 14 +++++--------- .../BoundJoinVALUESConversionIteration.java | 8 +++----- .../eclipse/rdf4j/federated/BindLeftJoinTests.java | 3 --- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/tools/federation/src/main/java/org/eclipse/rdf4j/federated/evaluation/iterator/BindLeftJoinIteration.java b/tools/federation/src/main/java/org/eclipse/rdf4j/federated/evaluation/iterator/BindLeftJoinIteration.java index 4b220db24b7..5b0b61f544a 100644 --- a/tools/federation/src/main/java/org/eclipse/rdf4j/federated/evaluation/iterator/BindLeftJoinIteration.java +++ b/tools/federation/src/main/java/org/eclipse/rdf4j/federated/evaluation/iterator/BindLeftJoinIteration.java @@ -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; @@ -42,7 +41,7 @@ public class BindLeftJoinIteration extends LookAheadIteration { protected final CloseableIteration iter; protected final List bindings; - protected Set seenBindingIndexes = new HashSet<>(); + protected IntHashSet seenBindingIndexes = new IntHashSet(); protected final ListIterator bindingsIterator; public BindLeftJoinIteration(CloseableIteration iter, @@ -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); } @@ -82,9 +80,7 @@ protected void handleClose() { protected BindingSet convert(BindingSet bIn, int bIndex) throws QueryEvaluationException { QueryBindingSet res = new QueryBindingSet(); - Iterator bIter = bIn.iterator(); - while (bIter.hasNext()) { - Binding b = bIter.next(); + for (Binding b : bIn) { if (b.getName().equals(BoundJoinVALUESConversionIteration.INDEX_BINDING_NAME)) { continue; } diff --git a/tools/federation/src/main/java/org/eclipse/rdf4j/federated/evaluation/iterator/BoundJoinVALUESConversionIteration.java b/tools/federation/src/main/java/org/eclipse/rdf4j/federated/evaluation/iterator/BoundJoinVALUESConversionIteration.java index c734fe6fea9..9bc71b87dbd 100644 --- a/tools/federation/src/main/java/org/eclipse/rdf4j/federated/evaluation/iterator/BoundJoinVALUESConversionIteration.java +++ b/tools/federation/src/main/java/org/eclipse/rdf4j/federated/evaluation/iterator/BoundJoinVALUESConversionIteration.java @@ -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; @@ -53,10 +53,8 @@ public BoundJoinVALUESConversionIteration(CloseableIteration 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 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; } diff --git a/tools/federation/src/test/java/org/eclipse/rdf4j/federated/BindLeftJoinTests.java b/tools/federation/src/test/java/org/eclipse/rdf4j/federated/BindLeftJoinTests.java index d7a60a7112c..19d3d0386e7 100644 --- a/tools/federation/src/test/java/org/eclipse/rdf4j/federated/BindLeftJoinTests.java +++ b/tools/federation/src/test/java/org/eclipse/rdf4j/federated/BindLeftJoinTests.java @@ -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; @@ -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);