kou commented on code in PR #41824:
URL: https://github.com/apache/arrow/pull/41824#discussion_r1625539769


##########
cpp/src/arrow/util/iterator.h:
##########
@@ -105,9 +105,18 @@ class Iterator : public 
util::EqualityComparable<Iterator<T>> {
   Iterator() : ptr_(NULLPTR, [](void*) {}) {}
 
   /// \brief Return the next element of the sequence, 
IterationTraits<T>::End() when the
-  /// iteration is completed. Calling this on a default constructed Iterator
-  /// will result in undefined behavior.
-  Result<T> Next() { return next_(ptr_.get()); }
+  /// iteration is completed.
+  Result<T> Next() {
+    if (ptr_) {
+      auto next_result = next_(ptr_.get());
+      if (next_result.ok() && IsIterationEnd(next_result.ValueUnsafe())) {

Review Comment:
   Could you explain the reason? Performance?
   
   For the #41771 case:
   
   This is the underlying iterator: 
https://github.com/apache/arrow/blob/7f0c4070dd723b2f7e1967d7f7f2cccf6fb256b7/cpp/src/arrow/dataset/scanner.cc#L380-L386
   
   We want to release the IPC reader created at: 
https://github.com/apache/arrow/blob/7bc2452b350867b3ddc9de9ceceeef0e4d722941/cpp/src/arrow/dataset/file_ipc.cc#L144
   
   It's referred by the underlying iterator indirectly via 
`Future`/`std::function`. 
   
   It seems that we can't remove a reference from `Future`/`std::function` 
without deleting `Future`/`std::function` and we can't delete 
`Future`/`std::function` without deleting the underlying iterator.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to