You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If this is the preferred Iterator interface, then I would suggest refactoring one or two of our ad hoc iterator classes in the codebase to use arrow::Iterator<T> as a path to resolving this issue. Thoughts?
Ben Kietzman / @bkietz:
Why not just use the Range concept? We already have arrow::util::LazyRange which provides the functionality you want, I think. If you prefer the Iterator interface as you have written it then we should include an adapter so that range for loops are easy
Wes McKinney / @wesm:
Let's wait until StatusOr lands and evaluate options. It might be nice to have Next return StatusOr<T>. Ultimately this is about having an abstract base type like std::unique_ptr<Iterator<T>> to return from functions that deal in streams
T must be of pointer type (or support assignment/comparison of nullptr). Iterator completion is signaled by assigning T\* out to nullptr.
Due to previous point, the iterator may never yield nullptr as a valid value.
The interface forces consuming a value to know if it's empty, i.e. there's no Done()/HasNext(). This can lead to odd consumption.
I question the user of Status as a return code, maybe we should have a specialized FailableIterator<T> : Iterator<Result<T>> for the same effect.
The first and second point could be tackled by returning Option<T> (Result wouldn't work because we can't use Status::OK() as a sentinel-completion value). The third is annoying for streaming iterators (when there's no way to know completion without side effect), since the iterator itself must consume on Done() call and cache the result. I think I prefer putting the onus on the iterator implementor than the user of the interface.
Antoine Pitrou / @pitrou:
We could also take a page from Python and have a special Status::StopIteration to signal completion.
I also think it's essential to be able to return errors - either via Status or Result<T>.
As for signaling completion without consuming a value, well, the problem is that not all iterators may support that. Is there a use case where this matters?
Micah Kornfield / @emkornfield:
My only comment on this is might pay to sketch out what iteration looks like in each case.
Using StopIteration and Result I think you get something like:
while (RETURN_IF_NOT_STOPPED_ERROR(v, iter.next()) {
doSomethingWith(v)
}
Not sure if the macros to make that nice are even vaible.
"As for signaling completion without consuming a value, well, the problem is that not all iterators may support that. Is there a use case where this matters?"
I think in many cases this can be solved with a "peek" style iterator?
Activity
asfimport commentedon Jun 5, 2019
Liya Fan / @liyafan82:
@wesm, thanks for the good point.
What is the standard way to know if there is a next element in the iterator?
asfimport commentedon Jun 13, 2019
Wes McKinney / @wesm:
I added a prototype for this here, see the comment on the Next method
https://github.com/apache/arrow/blob/master/cpp/src/arrow/util/iterator.h
I notice that I missed the virtual destructor.
If this is the preferred Iterator interface, then I would suggest refactoring one or two of our ad hoc iterator classes in the codebase to use
arrow::Iterator<T>as a path to resolving this issue. Thoughts?asfimport commentedon Jun 14, 2019
Ben Kietzman / @bkietz:
Why not just use the
Rangeconcept? We already have arrow::util::LazyRange which provides the functionality you want, I think. If you prefer theIteratorinterface as you have written it then we should include an adapter so that range for loops are easyasfimport commentedon Jun 14, 2019
Wes McKinney / @wesm:
Let's wait until
StatusOrlands and evaluate options. It might be nice to haveNextreturnStatusOr<T>. Ultimately this is about having an abstract base type likestd::unique_ptr<Iterator<T>>to return from functions that deal in streamsasfimport commentedon Jun 19, 2019
Liya Fan / @liyafan82:
I still have not figured out how to check the end of the iterator by the Next method:
If it is through the return value, this could be inefficient - Status is a class, and there can be object copy when returning an Status object.
If it is through the method parameter, I think the parameter type should be T*& or T** ?
asfimport commentedon Jun 19, 2019
Ben Kietzman / @bkietz:
3. A separate out parameter of type
bool*asfimport commentedon Aug 22, 2019
Wes McKinney / @wesm:
@pitrou @bkietz @fsaintjacques is the
Iterator<T>in the codebase now satisfactory?asfimport commentedon Aug 23, 2019
Francois Saint-Jacques / @fsaintjacques:
My take after implementing MapIterator, FlattenIterator and using it heavily in the dataset code.
Tmust be of pointer type (or support assignment/comparison of nullptr). Iterator completion is signaled by assigningT\* outto nullptr.Due to previous point, the iterator may never yield nullptr as a valid value.
The interface forces consuming a value to know if it's empty, i.e. there's no Done()/HasNext(). This can lead to odd consumption.
I question the user of Status as a return code, maybe we should have a specialized
FailableIterator<T> : Iterator<Result<T>>for the same effect.The first and second point could be tackled by returning
Option<T>(Result wouldn't work because we can't use Status::OK() as a sentinel-completion value). The third is annoying for streaming iterators (when there's no way to know completion without side effect), since the iterator itself must consume on Done() call and cache the result. I think I prefer putting the onus on the iterator implementor than the user of the interface.asfimport commentedon Aug 26, 2019
Francois Saint-Jacques / @fsaintjacques:
ping for input: @pitrou @bkietz [~emkornfield@gmail.com]
asfimport commentedon Aug 26, 2019
Antoine Pitrou / @pitrou:
We could also take a page from Python and have a special
Status::StopIterationto signal completion.I also think it's essential to be able to return errors - either via
StatusorResult<T>.As for signaling completion without consuming a value, well, the problem is that not all iterators may support that. Is there a use case where this matters?
asfimport commentedon Aug 28, 2019
Micah Kornfield / @emkornfield:
My only comment on this is might pay to sketch out what iteration looks like in each case.
Using StopIteration and Result I think you get something like:
while (RETURN_IF_NOT_STOPPED_ERROR(v, iter.next()) {
doSomethingWith(v)
}
Not sure if the macros to make that nice are even vaible.
"As for signaling completion without consuming a value, well, the problem is that not all iterators may support that. Is there a use case where this matters?"
I think in many cases this can be solved with a "peek" style iterator?
asfimport commentedon Aug 28, 2019
Ben Kietzman / @bkietz:
I think the existing interface is sufficient for our current use cases.
WRT easier iteration, we currently have
Iterator<T>::Visit:asfimport commentedon Sep 6, 2019
Wes McKinney / @wesm:
Moved out of 0.15.0 as it seems like there is more thinking to do on this
asfimport commentedon Dec 4, 2019
Antoine Pitrou / @pitrou:
Is there something left to do here? It seems the
Iterator<T>interface and itsVisitmethod are sufficient.