fix(fast-path): use count_rows() instead of collect() in _can_use_fast_path#45
Open
FANNG1 wants to merge 1 commit into
Open
fix(fast-path): use count_rows() instead of collect() in _can_use_fast_path#45FANNG1 wants to merge 1 commit into
FANNG1 wants to merge 1 commit into
Conversation
…t_path collect() populates df._result_cache with one-shot Python objects (e.g. BlobFile from take_blobs()). A subsequent groupby().map_groups() re-uses the same df object, receiving the same exhausted objects from the cache; downstream UDFs that call blob.read() get b'' and produce null/wrong output. count_rows() does not set _result_cache, so the pipeline re-executes fresh. Fixes daft-engine#42
0e7a835 to
43da0eb
Compare
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.
Fixes #42
Problem
_can_use_fast_pathusedlen(df.collect())to count rows.collect()populatesdf._result_cachewith the materialised results. When the pipeline includestake_blobs(), those cached results includeBlobFileinstances — one-shot streams whose.read()returnsb""after the first call.The fast-path merge subsequently calls
df.groupby("fragment_id").map_groups(...). Because_result_cacheis already set, Daft returns the same exhaustedBlobFileobjects instead of re-materialising from Lance. Downstream UDFs that callblob.read()receive empty bytes and produce null or incorrect output.Fix
Replace
len(df.collect())withdf.count_rows().count_rows()does not set_result_cache, so the pipeline re-executes fresh when the merge runs.Test
TestRegressions::test_fast_path_check_does_not_set_result_cache— verifies that_can_use_fast_pathleavesdf._result_cacheunset after it returns, confirmingcount_rows()(notcollect()) is used internally.