Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,16 @@ public interface IndexReportingIterator {

String getIndexName();

default long getSourceRowsScannedActual() {
return -1;
}

default long getSourceRowsMatchedActual() {
return -1;
}

default long getSourceRowsFilteredActual() {
return -1;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
// Some portions generated by Codex

package org.eclipse.rdf4j.common.iteration;

Expand All @@ -16,12 +17,13 @@
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.function.ToLongFunction;

/**
* An Iteration that returns the bag union of the results of a number of Iterations. 'Bag union' means that the
* UnionIteration does not filter duplicate objects.
*/
public class UnionIteration<E> extends LookAheadIteration<E> {
public class UnionIteration<E> extends LookAheadIteration<E> implements IndexReportingIterator {

/*-----------*
* Variables *
Expand All @@ -31,6 +33,8 @@ public class UnionIteration<E> extends LookAheadIteration<E> {

private CloseableIteration<? extends E> currentIter;

private final List<IndexReportingIterator> indexReporters;

/*--------------*
* Constructors *
*--------------*/
Expand All @@ -51,7 +55,16 @@ public UnionIteration(CloseableIteration<? extends E>... args) {
* @param args The Iterations containing the elements to iterate over.
*/
public UnionIteration(Iterable<? extends CloseableIteration<? extends E>> args) {
argIter = args.iterator();
List<CloseableIteration<? extends E>> iterations = new ArrayList<>();
List<IndexReportingIterator> reporters = new ArrayList<>();
for (CloseableIteration<? extends E> arg : args) {
iterations.add(arg);
if (arg instanceof IndexReportingIterator) {
reporters.add((IndexReportingIterator) arg);
}
}
argIter = iterations.iterator();
indexReporters = reporters;

// Initialize with empty iteration
currentIter = new EmptyIteration<>();
Expand Down Expand Up @@ -112,4 +125,43 @@ protected void handleClose() {
}

}

@Override
public String getIndexName() {
for (IndexReportingIterator indexReporter : indexReporters) {
String indexName = indexReporter.getIndexName();
if (indexName != null && !indexName.isEmpty()) {
return indexName;
}
}
return "";
}

@Override
public long getSourceRowsScannedActual() {
return aggregateMetric(IndexReportingIterator::getSourceRowsScannedActual);
}

@Override
public long getSourceRowsMatchedActual() {
return aggregateMetric(IndexReportingIterator::getSourceRowsMatchedActual);
}

@Override
public long getSourceRowsFilteredActual() {
return aggregateMetric(IndexReportingIterator::getSourceRowsFilteredActual);
}

private long aggregateMetric(ToLongFunction<IndexReportingIterator> metricSupplier) {
long total = 0L;
boolean found = false;
for (IndexReportingIterator indexReporter : indexReporters) {
long value = metricSupplier.applyAsLong(indexReporter);
if (value >= 0L) {
total += value;
found = true;
}
}
return found ? total : -1L;
}
}
5 changes: 3 additions & 2 deletions core/query/src/main/java/org/eclipse/rdf4j/query/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ enum QueryType {
*
* @param level The explanation level that should be used to create the explanation. Choose between: Unoptimized (as
* parsed without optimizations) , Optimized (as is actually going to be used), Executed (as was
* executed/evaluated, including some real performance metrics), Timed (as was executed/evaluated
* including all real performance metrics). Executed and Timed level can potentially be slow.
* executed/evaluated with actual result sizes), Telemetry (as was executed/evaluated, including
* runtime telemetry metrics), Timed (as was executed/evaluated including timing for each plan node).
* Executed, Telemetry and Timed levels can potentially be slow.
* @return The explanation that we generated, which can be viewed in a human readable format with toString(), as
* JSON or as a simplified query plan object structure.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum Level {
Unoptimized, // simple parsed
Optimized, // parsed and optimized, which includes cost estimated
Executed, // plan as it was executed, which includes resultSizeActual
Telemetry, // plan as it was executed with runtime telemetry metrics (without node timing)
Timed, // plan as it was executed, including resultSizeActual and where each node has been timed
}

Expand Down
Loading
Loading