feat: add dictionary_columns parameter to Table.scan() for memory-efficient reads#3461
Open
GayathriSrividya wants to merge 1 commit into
Open
Conversation
…icient reads
Columns that contain large or frequently repeated strings (e.g. JSON
blobs, low-cardinality categoricals) can exhaust memory when PyArrow
loads them as plain string arrays. PyArrow's Parquet reader supports
reading such columns as dictionary-encoded arrays, which deduplicates
values and can dramatically reduce memory usage.
Add a dictionary_columns: tuple[str, ...] parameter to Table.scan()
(and the underlying TableScan / ArrowScan classes) that is forwarded
to _get_file_format() as PyArrow's dictionary_columns kwarg. Only
applies to Parquet files; silently ignored for ORC.
Usage:
table.scan(dictionary_columns=("payload",)).to_arrow()
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Closes #3170
Rationale
Columns that contain large or frequently repeated string values (e.g. JSON blobs, low-cardinality categoricals) can exhaust memory when PyArrow loads them as plain string arrays. PyArrow's Parquet reader natively supports dictionary-encoded reads via its
dictionary_columnskwarg, which deduplicates values and can dramatically reduce peak memory usage.This was previously discussed in #3168 and a prior implementation (#3234) was closed as stale.
Changes
dictionary_columns: tuple[str, ...] = ()toTable.scan(),TableScan.__init__, andStagedTable.scan().DataScan.to_arrow()andto_arrow_batch_reader()→ArrowScan.__init__→_task_to_record_batches→_get_file_format().task.file.file_format == FileFormat.PARQUET; silently ignored for ORC (which does not support this kwarg).Usage
Verification
test_dictionary_columns_produces_dict_encoded_output— confirms the requested column is dict-encoded, non-requested columns are plain, and values are identical.make lint✓pytest tests/table/ tests/io/test_pyarrow.py✓