Stream CsvDataTableStore.getRows from disk lazily instead of buffering the whole table#7858
Open
krlittle wants to merge 1 commit into
Open
Stream CsvDataTableStore.getRows from disk lazily instead of buffering the whole table#7858krlittle wants to merge 1 commit into
krlittle wants to merge 1 commit into
Conversation
…g the whole table
2 tasks
sambsnyd
approved these changes
Jun 1, 2026
| * Rows are produced one at a time, so a whole table's rows are never held in | ||
| * memory at once. | ||
| */ | ||
| private Stream<Object> streamRows(Path path, @Nullable RowMetadata meta, int prefixCount, int suffixCount) { |
Member
There was a problem hiding this comment.
Since CsvDataTableStore is used directly in the CLI you'll have to do a release which includes this before this will work at runtime. Recipe modules built with this running on un-updated CLI may encounter NoSuchMethodException here... unless you've verified that isn't true, you might want to guard invocation of this method with reflection until CLI with this method have been released for a little while
natedanner
reviewed
Jun 1, 2026
Contributor
There was a problem hiding this comment.
Lazy streaming looks right and the happy path is fine (both RecipeRun callers collect(), fully draining). Two things worth addressing:
- The returned stream now holds an open file handle until it's drained/closed.
flatMapcloses an inner stream only once drained, and the outer stream'sclose()doesn't reach a still-open inner stream — so a short-circuiting caller (findFirst/limit) leaks a handle even with try-with-resources.InMemoryDataTableStorereturns a detached stream, so callers can't assume either way. Worth documenting onDataTableStore.getRowsthat the stream must be fully consumed/closed. - No tests for the new semantics; existing ones all fully drain, so a short-circuit leak wouldn't be caught.
2 tasks
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.
What's changed?
CsvDataTableStore.getRows(...)read every matching CSV file fully into aList<Object>and returned that list's stream, so reading back a large data table held all of its rows in memory at once. It now selects the matching file(s) by their@name/@groupcomment header and parses each file lazily, one row at a time via the Univocity parser, behind a closeableStream. Rows are produced on demand, so a whole table is never materialized in memory.The change is intended to be behavior-preserving:
@namematching, and typed-row (vs rawString[]) results;getRowscall, so a mid-run read still finalizes the file — only row parsing is deferred;IOExceptionis swallowed.What's your motivation?
Recipes that read their own data tables back — e.g. to export or aggregate them — can produce very large tables (one row per method/class across a large repository). Buffering the entire table into a
Listbefore the consumer sees a single row makes peak memory scale with table size; streaming bounds the store side to one row at a time.Checklist