Class IntersectionMultiCursor<T>
- java.lang.Object
-
- com.apple.foundationdb.record.provider.foundationdb.cursors.MergeCursor<T,U,com.apple.foundationdb.record.provider.foundationdb.cursors.KeyedMergeCursorState<T>>
-
- com.apple.foundationdb.record.provider.foundationdb.cursors.IntersectionMultiCursor<T>
-
- Type Parameters:
T
- the type of elements returned by the child cursors
- All Implemented Interfaces:
RecordCursor<List<T>>
,AutoCloseable
,Iterator<List<T>>
@API(EXPERIMENTAL) public class IntersectionMultiCursor<T> extends MergeCursor<T,U,com.apple.foundationdb.record.provider.foundationdb.cursors.KeyedMergeCursorState<T>>
A cursor that implements an intersection of matching elements from a set of cursors all of whom are ordered compatibly. This operates like theIntersectionCursor
except that for each set of matching results, this returns a list of all of the elements from all of the child cursors rather than just one.- See Also:
IntersectionCursor
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.apple.foundationdb.record.RecordCursor
RecordCursor.NoNextReason
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected CompletableFuture<List<com.apple.foundationdb.record.provider.foundationdb.cursors.KeyedMergeCursorState<T>>>
computeNextResultStates()
Compute the next result states for the cursor based on the status of the existing states.static <T> IntersectionMultiCursor<T>
create(Function<? super T,? extends List<Object>> comparisonKeyFunction, boolean reverse, List<Function<byte[],RecordCursor<T>>> cursorFunctions, byte[] continuation, FDBStoreTimer timer)
Create an intersection cursor from two or more compatibly-ordered cursors.protected static <T> List<com.apple.foundationdb.record.provider.foundationdb.cursors.KeyedMergeCursorState<T>>
createCursorStates(Function<byte[],RecordCursor<T>> left, Function<byte[],RecordCursor<T>> right, byte[] byteContinuation, Function<? super T,? extends List<Object>> comparisonKeyFunction)
protected static <T> List<com.apple.foundationdb.record.provider.foundationdb.cursors.KeyedMergeCursorState<T>>
createCursorStates(List<Function<byte[],RecordCursor<T>>> cursorFunctions, byte[] byteContinuation, Function<? super T,? extends List<Object>> comparisonKeyFunction)
protected Function<? super T,? extends List<Object>>
getComparisonKeyFunction()
com.apple.foundationdb.record.provider.foundationdb.cursors.IntersectionCursorContinuation
getContinuationObject()
Produce aRecordCursorContinuation
for this cursor.protected List<T>
getNextResult(List<com.apple.foundationdb.record.provider.foundationdb.cursors.KeyedMergeCursorState<T>> cursorStates)
Determine the next result to return based on the results of the child cursors.protected RecordCursor.NoNextReason
mergeNoNextReasons()
Merges all of the cursors and whether they have stopped and returns the "weakest" reason for the result to stop.-
Methods inherited from class com.apple.foundationdb.record.provider.foundationdb.cursors.MergeCursor
accept, checkNextStateTimeout, close, getChildContinuations, getContinuation, getCursorStates, getExecutor, getNoNextReason, getStrongestNoNextReason, getTimer, getWeakestNoNextReason, next, onHasNext, onNext, whenAll, whenAny
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Methods inherited from interface com.apple.foundationdb.record.RecordCursor
asIterator, asList, filter, filterAsync, filterAsyncInstrumented, filterAsyncInstrumented, filterInstrumented, filterInstrumented, first, flatMapPipelined, forEach, forEachAsync, forEachResult, forEachResultAsync, getCount, getNext, hasNext, limitRowsTo, limitTo, map, mapEffect, mapEffect, mapPipelined, orElse, reduce, skip, skipThenLimit
-
-
-
-
Method Detail
-
getNextResult
@Nonnull protected List<T> getNextResult(@Nonnull List<com.apple.foundationdb.record.provider.foundationdb.cursors.KeyedMergeCursorState<T>> cursorStates)
Description copied from class:MergeCursor
Determine the next result to return based on the results of the child cursors. This will be called with the return value ofMergeCursor.computeNextResultStates()
.- Specified by:
getNextResult
in classMergeCursor<T,List<T>,com.apple.foundationdb.record.provider.foundationdb.cursors.KeyedMergeCursorState<T>>
- Parameters:
cursorStates
- the list of cursors to be included in the result- Returns:
- a result somehow combining the results of the input cursors
-
create
@Nonnull public static <T> IntersectionMultiCursor<T> create(@Nonnull Function<? super T,? extends List<Object>> comparisonKeyFunction, boolean reverse, @Nonnull List<Function<byte[],RecordCursor<T>>> cursorFunctions, @Nullable byte[] continuation, @Nullable FDBStoreTimer timer)
Create an intersection cursor from two or more compatibly-ordered cursors. Note that this will throw an error if the list of cursors does not have at least two elements. The returned cursor will return lists of elements, all of which compare equal according to the comparison key function, though they might contain different information outside of what the comparison key function examines. This is useful, for example, if one needs to scan multiple segments of an index and then find all entries that correspond to the same primary key (which can be done by setting a comparison key function that identifies the primary key) and then also apply some filter on all of the entries that come back.Otherwise, this function returns a cursor that is subject to all of the constraints as an
IntersectionCursor
returned by its equivalentcreate()
method.- Type Parameters:
T
- the type of elements returned by this cursor- Parameters:
comparisonKeyFunction
- the function evaluated to compare elements from different cursorsreverse
- whether records are returned in descending or ascending order by the comparison keycursorFunctions
- a list of functions to produceRecordCursor
s from a continuationcontinuation
- any continuation from a previous scantimer
- the timer used to instrument events- Returns:
- a cursor containing all records in all child cursors
-
computeNextResultStates
@Nonnull protected CompletableFuture<List<com.apple.foundationdb.record.provider.foundationdb.cursors.KeyedMergeCursorState<T>>> computeNextResultStates()
Compute the next result states for the cursor based on the status of the existing states. This should return a (not necessarily proper) sublist of this cursor's cursor states. By default, this assumes the cursors return results in a compatible order based on their comparison key and loops until they all have matching values. Extenders of this class may choose an alternative approach depending on the semantics of that cursor.To indicate that the intersection cursor should stop, this function should either return an empty list of states or a list containing at least one state that does not have a next item.
- Specified by:
computeNextResultStates
in classMergeCursor<T,U,com.apple.foundationdb.record.provider.foundationdb.cursors.KeyedMergeCursorState<T>>
- Returns:
- the list of states included in the next result
-
getComparisonKeyFunction
@Nonnull protected Function<? super T,? extends List<Object>> getComparisonKeyFunction()
-
mergeNoNextReasons
@Nonnull protected RecordCursor.NoNextReason mergeNoNextReasons()
Merges all of the cursors and whether they have stopped and returns the "weakest" reason for the result to stop. It will returnRecordCursor.NoNextReason.SOURCE_EXHAUSTED
if any of the cursors are exhausted. If any of the cursors have stopped due to an in-band limit, it will return an in-band limit as well. Finally, if all of the stopped cursors have done so due to hitting an out-of-band limit, it will return an out-of-band limit as well. Note that, in practice, because an intersection cursor will returnfalse
fromonHasNext
if any of its child cursors have stopped, it is likely that there are only a small number (maybe one or two) cursors that have actually stopped when this method is called (e.g., the first cursor to exhaust its source or the first cursor to hit a limit imposed by the element scan limiter).- Specified by:
mergeNoNextReasons
in classMergeCursor<T,U,com.apple.foundationdb.record.provider.foundationdb.cursors.KeyedMergeCursorState<T>>
- Returns:
- the weakest reason for stopping
-
getContinuationObject
@Nonnull public com.apple.foundationdb.record.provider.foundationdb.cursors.IntersectionCursorContinuation getContinuationObject()
Description copied from class:MergeCursor
Produce aRecordCursorContinuation
for this cursor. The super-class itself handles constructing the byte array continuation from this continuation. Most continuations will be based on the continuations of this cursors child cursors. These can be retrieved by callingMergeCursor.getChildContinuations()
. This will only be called afterMergeCursor.computeNextResultStates()
has completed.- Specified by:
getContinuationObject
in classMergeCursor<T,U,com.apple.foundationdb.record.provider.foundationdb.cursors.KeyedMergeCursorState<T>>
- Returns:
- a
RecordCursorContinuation
for this cursor based on the state of its child cursors
-
createCursorStates
@Nonnull protected static <T> List<com.apple.foundationdb.record.provider.foundationdb.cursors.KeyedMergeCursorState<T>> createCursorStates(@Nonnull Function<byte[],RecordCursor<T>> left, @Nonnull Function<byte[],RecordCursor<T>> right, @Nullable byte[] byteContinuation, @Nonnull Function<? super T,? extends List<Object>> comparisonKeyFunction)
-
createCursorStates
@Nonnull protected static <T> List<com.apple.foundationdb.record.provider.foundationdb.cursors.KeyedMergeCursorState<T>> createCursorStates(@Nonnull List<Function<byte[],RecordCursor<T>>> cursorFunctions, @Nullable byte[] byteContinuation, @Nonnull Function<? super T,? extends List<Object>> comparisonKeyFunction)
-
-