Repository navigation
perf(pyarrow): group delete positions in a single pass - #4591
Anurag-S1ngh wants to merge 3 commits into
Conversation
_read_deletes filtered the whole delete table once per distinct file path, so a delete file with many paths was quadratic. Group by file_path instead and build the result from the grouped rows.
rahulsmahadev
left a comment
There was a problem hiding this comment.
Thanks @Anurag-S1ngh! Against main, 28 delete-file layouts and 32 end-to-end scans (Parquet and ORC, pyarrow 18.1 and 25) give the same positions, and 2M positions over 1,000 paths in one Parquet file drop from 3 s to 0.05 s.
I'd recommend a fast path for a delete file with a single path, which Spark writes by default (write.delete.granularity=file): there the group-by takes about 0.19 s for 10M positions vs 0.1 s on main. Returning table.column("pos") when table.column("file_path").unique() has one value restored 0.1 s in a scratch copy.
A couple of smaller suggestions:
- This matches #3989 by ArulJerald, which the stale bot closed nine hours before this PR; maybe link it and add them as co-author.
- A test suggestion is inline.
|
Added the single-path fast path: when The test now writes multiple row groups with The approach comes from #3989 by @ArulJerald, which I credited in the description. I can add them as a co-author if they want. |
Closes #3983
Based on the approach in #3989 by @ArulJerald.
Rationale for this change
_read_deletesfiltered the full delete table once per distinctfile_path, so the cost was O(rows x distinct paths). Both the Parquet and ORC branches now group positions byfile_pathin one pass with Arrow's group-by and build the result from the grouped rows.Are these changes tested?
Added a test that writes a delete file with 100 distinct paths in both Parquet and ORC and checks the grouped positions. The
deletetests intests/io/test_pyarrow.pypass.Are there any user-facing changes?
No. The returned mapping is unchanged.