paleolimbot commented on code in PR #1046:
URL: https://github.com/apache/arrow-nanoarrow/pull/1046#discussion_r4774580236
##########
python/src/nanoarrow/iterator.py:
##########
@@ -284,6 +285,30 @@ def _list_iter(self, offset, length):
for start, end in zip(starts, ends):
yield list(islice(child_iter, end - start))
+ def _run_end_encoded_iter(self, offset, length):
+ if length == 0:
+ return
+
+ offset += self._array_view.offset
+ stop = offset + length
+ run_ends = iter(self._children[0])
+ values = self._children[1]
+ for run_index, run_end in enumerate(run_ends):
+ if run_end <= offset:
+ continue
+
+ # Start at the first overlapping run without converting skipped
values.
+ value_iter = values._iter_chunk(
+ run_index, len(values._array_view) - run_index
+ )
Review Comment:
There are two issues here:
- The first chunk should be resolved using a binary search instead of
iterating over all the chunks. This makes sliced REE arrays resolve much faster
(no need to iterate over all of the first chunks that will never be used)
- The values iterator should be limited to the number of elements from the
matching chunk actually used. The current code stops iterating but it's
slightly more correct to pass a smaller length to the iterator.
Codex suggested something like this:
```python
first = bisect_right(ends, start)
past_last = bisect_left(ends, stop) + 1
value_iter = values._iter_chunk(first, past_last - first)
```
--
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]