Repository navigation
perf(pyarrow): group delete positions in a single pass - #4591
Anurag-S1ngh wants to merge 1 commit 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.
| ) | ||
| delete_file_path = tmp_path / ("deletes.parquet" if file_format == FileFormat.PARQUET else "deletes.orc") | ||
| if file_format == FileFormat.PARQUET: | ||
| pq.write_table(table, delete_file_path) |
There was a problem hiding this comment.
This writes a single row group, so the test still passes without unify_dictionaries(), which a file with several row groups needs (ArrowNotImplementedError: Unifying differing dictionaries). Several row groups would cover it:
| pq.write_table(table, delete_file_path) | |
| pq.write_table(table, delete_file_path, row_group_size=3) |
Closes #3983
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.