Class UnorderedUnionCursor<T>
- java.lang.Object
-
- com.apple.foundationdb.record.provider.foundationdb.cursors.UnorderedUnionCursor<T>
-
- Type Parameters:
T
- the type of elements returned by the cursor
- All Implemented Interfaces:
RecordCursor<T>
,AutoCloseable
,Iterator<T>
@API(EXPERIMENTAL) public class UnorderedUnionCursor<T> extends Object
A cursor that returns the results of two or more cursors that may return elements in any order. This cursor makes no guarantees as to the order of elements it returns, and it may return the same element more than once as it does not make any attempt to de-duplicate elements that appear in multiple of its source cursors. It attempts to return elements from its children "as they come", which means that it might be the case that identical cursors of this type may return results in two different orders even if all of its child cursors all return the same results if different children happen to be faster in one run than the other (due to, for example, non-determinism in sending messages across the network).If there are limits applied to the children of this cursor, this cursor will continue to emit elements as long as there remains at least one child cursor who has not yet returned its last result. (For example, if this cursor has two children and one of them completes faster than the other due to hitting some limit, then the union cursor will continue returning results from the other cursor.) This differs from the behavior of the ordered
UnionCursor
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.apple.foundationdb.record.RecordCursor
RecordCursor.NoNextReason
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
UnorderedUnionCursor(List<com.apple.foundationdb.record.provider.foundationdb.cursors.MergeCursorState<T>> cursorStates, FDBStoreTimer timer)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
accept(RecordCursorVisitor visitor)
Accept a visit from hierarchical visitor, which implementsRecordCursorVisitor
.void
close()
static <T> UnorderedUnionCursor<T>
create(List<Function<byte[],RecordCursor<T>>> cursorFunctions, byte[] continuation, FDBStoreTimer timer)
Create a union cursor from two or more cursors.byte[]
getContinuation()
Deprecated.Executor
getExecutor()
RecordCursor.NoNextReason
getNoNextReason()
Deprecated.FDBStoreTimer
getTimer()
Get theFDBStoreTimer
used to instrument events of this cursor.protected RecordCursor.NoNextReason
mergeNoNextReasons()
Merges all of the cursors and whether they have stopped and returns the "strongest" reason for the result to stop.U
next()
Deprecated.CompletableFuture<Boolean>
onHasNext()
Deprecated.CompletableFuture<RecordCursorResult<U>>
onNext()
Asynchronously return the next result from this cursor.-
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
-
-
-
-
Constructor Detail
-
UnorderedUnionCursor
protected UnorderedUnionCursor(@Nonnull List<com.apple.foundationdb.record.provider.foundationdb.cursors.MergeCursorState<T>> cursorStates, @Nullable FDBStoreTimer timer)
-
-
Method Detail
-
create
@Nonnull public static <T> UnorderedUnionCursor<T> create(@Nonnull List<Function<byte[],RecordCursor<T>>> cursorFunctions, @Nullable byte[] continuation, @Nullable FDBStoreTimer timer)
Create a union cursor from two or more cursors. Unlike the otherUnionCursor
, this does not require that the child cursors return values in any particular order. The trade-off, however, is that this cursor will not attempt to remove any duplicates from its children. It will return results from its children as they become available.- Type Parameters:
T
- the type of elements returned by this cursor- Parameters:
cursorFunctions
- 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 any records from any child cursor
-
mergeNoNextReasons
@Nonnull protected RecordCursor.NoNextReason mergeNoNextReasons()
Merges all of the cursors and whether they have stopped and returns the "strongest" reason for the result to stop. It will return an out-of-band reason if any of the children stopped for an out-of-band reason, and it will only returnSOURCE_EXHAUSTED
if all of the cursors are exhausted.- Returns:
- the strongest reason for stopping
-
onNext
@Nonnull public CompletableFuture<RecordCursorResult<U>> onNext()
Description copied from interface:RecordCursor
Asynchronously return the next result from this cursor. When complete, the future will contain aRecordCursorResult
, which represents exactly one of the following:-
The next object of type
T
produced by the cursor. In addition to the next record, this result includes aRecordCursorContinuation
that can be used to continue the cursor after the last record returned. The returned continuation is guaranteed not to be an "end continuation" representing the end of the cursor: specifically,RecordCursorContinuation.isEnd()
is alwaysfalse
on the returned continuation. -
The fact that the cursor is stopped and cannot produce another record and a
RecordCursor.NoNextReason
that explains why no record could be produced. The result include a continuation that can be used to continue the cursor after the last record returned. If the result'sNoNextReason
is anything other thanRecordCursor.NoNextReason.SOURCE_EXHAUSTED
, the returned continuation must not be an end continuation. Conversely, if the result'sNoNextReason
isSOURCE_EXHAUSTED
, then the returned continuation must be an an "end continuation".
RecordCursorContinuation
can be serialized to an opaque byte array usingRecordCursorContinuation.toBytes()
. This can be passed back into a new cursor of the same type, with all other parameters remaining the same.- Specified by:
onNext
in interfaceRecordCursor<T>
- Returns:
- a future for the next result from this cursor representing either the next record or an indication of why the cursor stopped
- See Also:
RecordCursorResult
,RecordCursorContinuation
-
The next object of type
-
onHasNext
@Nonnull @Deprecated public CompletableFuture<Boolean> onHasNext()
Deprecated.Description copied from interface:RecordCursor
Asynchronously check whether there are more records available from the cursor.- Specified by:
onHasNext
in interfaceRecordCursor<T>
- Returns:
- a future that when complete will hold
true
ifRecordCursor.next()
would return a record. - See Also:
AsyncIterator.onHasNext()
-
next
@Nullable @Deprecated public U next()
Deprecated.Description copied from interface:RecordCursor
Return the next value.
-
getContinuation
@Nullable @Deprecated public byte[] getContinuation()
Deprecated.Description copied from interface:RecordCursor
Get a byte string that can be used to continue a query after the last record returned.- Specified by:
getContinuation
in interfaceRecordCursor<T>
- Returns:
- opaque byte array denoting where the cursor should pick up. This can be passed back into a new
cursor of the same type, with all other parameters remaining the same.
Returns
null
if the underlying source is completely exhausted, independent of any limit passed to the cursor creator. Since such creators generally acceptnull
to mean no continuation, that is, start from the beginning, one must check fornull
fromgetContinuation
to keep from starting over. Result is not always defined if called beforeonHasNext
or beforenext
afteronHasNext
has returnedtrue
. That is, a continuation is only guaranteed when called "between" records from awhile (hasNext) next
loop or after its end.
-
getNoNextReason
@Nonnull @Deprecated public RecordCursor.NoNextReason getNoNextReason()
Deprecated.Description copied from interface:RecordCursor
Get the reason that the cursor has reached the end and returnedfalse
forRecordCursor.hasNext()
. IfhasNext
was not called or returnedtrue
last time, the result is undefined and may be an exception.- Specified by:
getNoNextReason
in interfaceRecordCursor<T>
- Returns:
- the reason that the cursor stopped
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceRecordCursor<T>
-
getExecutor
@Nonnull public Executor getExecutor()
- Specified by:
getExecutor
in interfaceRecordCursor<T>
-
getTimer
@Nullable public FDBStoreTimer getTimer()
Get theFDBStoreTimer
used to instrument events of this cursor.- Returns:
- the timer used to instrument this cursor
-
accept
public boolean accept(@Nonnull RecordCursorVisitor visitor)
Description copied from interface:RecordCursor
Accept a visit from hierarchical visitor, which implementsRecordCursorVisitor
. By contract, implementations of this method must return the value ofvisitor.visitLeave(this)
, which determines whether or not subsequent siblings of this cursor should be visited.- Specified by:
accept
in interfaceRecordCursor<T>
- Parameters:
visitor
- a hierarchical visitor- Returns:
true
if the subsequent siblings of thecursor
should be visited, andfalse
otherwise
-
-