wombatu-kun commented on code in PR #17118:
URL: https://github.com/apache/iceberg/pull/17118#discussion_r3533110207
##########
api/src/main/java/org/apache/iceberg/io/CloseableIterable.java:
##########
@@ -175,18 +199,7 @@ protected boolean shouldKeep(E item) {
*/
static <T> CloseableIterable<T> count(Counter counter, CloseableIterable<T>
iterable) {
Preconditions.checkArgument(null != counter, "Invalid counter: null");
- Preconditions.checkArgument(null != iterable, "Invalid iterable: null");
- return new CloseableIterable<T>() {
- @Override
- public CloseableIterator<T> iterator() {
- return CloseableIterator.count(counter, iterable.iterator());
- }
-
- @Override
- public void close() throws IOException {
- iterable.close();
- }
- };
+ return filter(iterable, item -> true, item -> counter.increment(), item ->
{});
Review Comment:
count now delegates to the FilterIterator-based filter, which increments
during hasNext()/advance() rather than on next() like CloseableIterator.count.
The javadoc still says the counter is incremented on each Iterator#next() call,
so peeking via hasNext() without a following next() over-counts. Update the
javadoc, or keep count on CloseableIterator.count.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]