@InterfaceAudience.Public @InterfaceStability.Unstable public final class RemoteIterators extends Object
This aims to make it straightforward to use lambda-expressions to transform the results of an iterator, without losing the statistics in the process, and to chain the operations together.
The closeable operation will be passed through RemoteIterators which wrap other RemoteIterators. This is to support any iterator which can be closed to release held connections, file handles etc. Unless client code is written to assume that RemoteIterator instances may be closed, this is not likely to be broadly used. It is added to make it possible to adopt this feature in a managed way.
One notable feature is that the
foreach(RemoteIterator, ConsumerRaisingIOE)
method will
LOG at debug any IOStatistics provided by the iterator, if such
statistics are provided. There's no attempt at retrieval and logging
if the LOG is not set to debug, so it is a zero cost feature unless
the logger org.apache.hadoop.fs.functional.RemoteIterators
is at DEBUG.
Modifier and Type | Method and Description |
---|---|
static <T> void |
cleanupRemoteIterator(org.apache.hadoop.fs.RemoteIterator<T> source)
Clean up after an iteration.
|
static <S> org.apache.hadoop.fs.RemoteIterator<S> |
closingRemoteIterator(org.apache.hadoop.fs.RemoteIterator<S> iterator,
Closeable toClose)
This adds an extra close operation alongside the passthrough
to any Closeable.close() method supported by the source iterator.
|
static <S> org.apache.hadoop.fs.RemoteIterator<S> |
filteringRemoteIterator(org.apache.hadoop.fs.RemoteIterator<S> iterator,
org.apache.hadoop.util.functional.FunctionRaisingIOE<? super S,Boolean> filter)
Create a RemoteIterator from a RemoteIterator and a filter
function which returns true for every element to be passed
through.
|
static <T> long |
foreach(org.apache.hadoop.fs.RemoteIterator<T> source,
org.apache.hadoop.util.functional.ConsumerRaisingIOE<? super T> consumer)
Apply an operation to all values of a RemoteIterator.
|
static <S,T> org.apache.hadoop.fs.RemoteIterator<T> |
mappingRemoteIterator(org.apache.hadoop.fs.RemoteIterator<S> iterator,
org.apache.hadoop.util.functional.FunctionRaisingIOE<? super S,T> mapper)
Create an iterator from an iterator and a transformation function.
|
static <T> org.apache.hadoop.fs.RemoteIterator<T> |
remoteIteratorFromArray(T[] array)
Create a remote iterator from an array.
|
static <T> org.apache.hadoop.fs.RemoteIterator<T> |
remoteIteratorFromIterable(Iterable<T> iterable)
Create a remote iterator from a java.util.Iterable -e.g.
|
static <T> org.apache.hadoop.fs.RemoteIterator<T> |
remoteIteratorFromIterator(Iterator<T> iterator)
Create a remote iterator from a java.util.Iterator.
|
static <T> org.apache.hadoop.fs.RemoteIterator<T> |
remoteIteratorFromSingleton(T singleton)
Create an iterator from a singleton.
|
static <T> T[] |
toArray(org.apache.hadoop.fs.RemoteIterator<T> source,
T[] a)
Build an array from a RemoteIterator.
|
static <T> List<T> |
toList(org.apache.hadoop.fs.RemoteIterator<T> source)
Build a list from a RemoteIterator.
|
static <S,T> org.apache.hadoop.fs.RemoteIterator<T> |
typeCastingRemoteIterator(org.apache.hadoop.fs.RemoteIterator<S> iterator)
Create a RemoteIterator from a RemoteIterator, casting the
type in the process.
|
public static <T> org.apache.hadoop.fs.RemoteIterator<T> remoteIteratorFromSingleton(@Nullable T singleton)
T
- typesingleton
- instancepublic static <T> org.apache.hadoop.fs.RemoteIterator<T> remoteIteratorFromIterator(Iterator<T> iterator)
T
- typeiterator
- iterator.public static <T> org.apache.hadoop.fs.RemoteIterator<T> remoteIteratorFromIterable(Iterable<T> iterable)
T
- typeiterable
- iterable.public static <T> org.apache.hadoop.fs.RemoteIterator<T> remoteIteratorFromArray(T[] array)
T
- typearray
- array.public static <S,T> org.apache.hadoop.fs.RemoteIterator<T> mappingRemoteIterator(org.apache.hadoop.fs.RemoteIterator<S> iterator, org.apache.hadoop.util.functional.FunctionRaisingIOE<? super S,T> mapper)
S
- source typeT
- result typeiterator
- sourcemapper
- transformationpublic static <S,T> org.apache.hadoop.fs.RemoteIterator<T> typeCastingRemoteIterator(org.apache.hadoop.fs.RemoteIterator<S> iterator)
S
- source typeT
- result typeiterator
- sourcepublic static <S> org.apache.hadoop.fs.RemoteIterator<S> filteringRemoteIterator(org.apache.hadoop.fs.RemoteIterator<S> iterator, org.apache.hadoop.util.functional.FunctionRaisingIOE<? super S,Boolean> filter)
Elements are filtered in the hasNext() method; if not used
the filtering will be done on demand in the next()
call.
S
- typeiterator
- sourcefilter
- filterpublic static <S> org.apache.hadoop.fs.RemoteIterator<S> closingRemoteIterator(org.apache.hadoop.fs.RemoteIterator<S> iterator, Closeable toClose)
S
- source type.iterator
- sourcetoClose
- extra object to close.public static <T> List<T> toList(org.apache.hadoop.fs.RemoteIterator<T> source) throws IOException
T
- typesource
- source iteratorIOException
- if the source RemoteIterator raises it.public static <T> T[] toArray(org.apache.hadoop.fs.RemoteIterator<T> source, T[] a) throws IOException
T
- typesource
- source iteratora
- destination array; if too small a new array
of the same type is createdIOException
- if the source RemoteIterator raises it.public static <T> long foreach(org.apache.hadoop.fs.RemoteIterator<T> source, org.apache.hadoop.util.functional.ConsumerRaisingIOE<? super T> consumer) throws IOException
The number of entries processed is returned, as it is useful to know this, especially during tests or when reporting values to users.
This does not close the iterator afterwards.T
- type of sourcesource
- iterator sourceconsumer
- consumer of the values.IOException
- if the source RemoteIterator or the consumer raise one.public static <T> void cleanupRemoteIterator(org.apache.hadoop.fs.RemoteIterator<T> source)
T
- type of sourcesource
- iterator sourceCopyright © 2023 Apache Software Foundation. All rights reserved.