Repository navigation
Enable batched read pushdown (SupportsBatchedReadRandomAccessDataSource) on grain.python.ArrayRecordDataSource. - #1412
Open
copybara-service[bot] wants to merge 1 commit into
Open
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
copybara-service
Bot
force-pushed
the
test_993324537
branch
2 times, most recently
from
October 5, 2026 04:06
bbd0b32 to
51adec8
Compare
…rce`) on `grain.python.ArrayRecordDataSource`. When `SourceMapDataset` wraps a data source, it checks `isinstance(source, SupportsBatchedReadRandomAccessDataSource)` and, if true, overrides `_getitems` to forward batched index lookups (`source._getitems(indices)`) when `BatchMapDataset` reads a batch of records. Previously: 1. `SupportsBatchedReadRandomAccessDataSource` was not decorated with `@typing.runtime_checkable`, and `grain.python.ArrayRecordDataSource` did not implement `_getitems`. 2. As a result, `MapDataset.source(ArrayRecordDataSource(...)).batch(B)` fell back to per-element `__getitem__` calls in `SourceMapDataset._getitems`, borrowing and returning a shard reader on each individual record rather than holding the pooled reader across the batch. This change: - Decorates `SupportsBatchedReadRandomAccessDataSource` with `@typing.runtime_checkable`. - Implements `_getitems` on `grain.python.ArrayRecordDataSource` (delegating to `super().__getitems__` in `array_record.ArrayRecordDataSource`) so batched reads group record indices by shard and hold the borrowed per-shard reader across the entire batch. - Adds unit tests verifying `isinstance(source, SupportsBatchedReadRandomAccessDataSource)` and `source._getitems(...)` on `grain.python.ArrayRecordDataSource`. PiperOrigin-RevId: 993324537
copybara-service
Bot
force-pushed
the
test_993324537
branch
from
October 6, 2026 03:15
51adec8 to
05c5ff3
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enable batched read pushdown (
SupportsBatchedReadRandomAccessDataSource) ongrain.python.ArrayRecordDataSource.When
SourceMapDatasetwraps a data source, it checksisinstance(source, SupportsBatchedReadRandomAccessDataSource)and, if true, overrides_getitemsto forward batched index lookups (source._getitems(indices)) whenBatchMapDatasetreads a batch of records.Previously:
SupportsBatchedReadRandomAccessDataSourcewas not decorated with@typing.runtime_checkable, andgrain.python.ArrayRecordDataSourcedid not implement_getitems.MapDataset.source(ArrayRecordDataSource(...)).batch(B)fell back to per-element__getitem__calls inSourceMapDataset._getitems, borrowing and returning a shard reader on each individual record rather than holding the pooled reader across the batch.This change:
SupportsBatchedReadRandomAccessDataSourcewith@typing.runtime_checkable._getitemsongrain.python.ArrayRecordDataSource(delegating tosuper().__getitems__inarray_record.ArrayRecordDataSource) so batched reads group record indices by shard and hold the borrowed per-shard reader across the entire batch.isinstance(source, SupportsBatchedReadRandomAccessDataSource)andsource._getitems(...)ongrain.python.ArrayRecordDataSource.