Skip to content

Added capability to fetch dictionary values - #9011

Closed
DarkWanderer wants to merge 3 commits into
apache:mainfrom
DarkWanderer:get-dictionary
Closed

DarkWanderer wants to merge 3 commits into
apache:mainfrom
DarkWanderer:get-dictionary

Conversation

@DarkWanderer

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Some databases, one example being Grafana Tempo, utilize column dictionaries as makeshift column indexes, to improve filtering speed ad-hoc. Checking if low-cardinality value is present in dictionary allows to effectively pre-filter data by skipping whole row group. This PR adds this capability

What changes are included in this PR?

Add public get_row_group_column_dictionary function to ParquetRecordBatchStreamBuilder

Are these changes tested?

Tests have been added

Are there any user-facing changes?

Public API extension for ParquetRecordBatchStreamBuilder

@github-actions github-actions Bot added the parquet parquet crate label Dec 17, 2025
@DarkWanderer
DarkWanderer marked this pull request as draft December 17, 2025 17:17
@tustvold

tustvold commented Dec 17, 2025 •

Copy link
Copy Markdown
Contributor

Unfortunately dictionary encoding is best effort, and writers will fallback to different encodings if the dictionary gets too large. The result is you need to know if all the pages are dictionary encoded in order to be able to make this optimisation - iirc this information is not encoded anywhere but the page header itself...

Putting this aside there are likely some challenges around typing with this approach.

IMO bloom filters are the recommended way to handle this sort of thing, dictionaries are more of an encoding optimisation.

Edit: I could see a world where users could opt-in to have ArrowFilter passed the dictionary in a pre-pass, and for this to then allow the reader to skip decoding dictionary encoded pages if there are no matches, but unless I'm remembering incorrectly this wouldn't allow skipping the IO...

@DarkWanderer

Copy link
Copy Markdown
Contributor Author

Edit: I could see a world where users could opt-in to have ArrowFilter passed the dictionary in a pre-pass, and for this to then allow the reader to skip decoding dictionary encoded pages if there are no matches, but unless I'm remembering incorrectly this wouldn't allow skipping the IO...

That is exactly what I am hoping for - to perform a multiple-range fetch of a few MB from object_store to filter down row groups to only ones I need, which saves me multiple gigabytes of actual S3 read.

@etseidl

etseidl commented Dec 18, 2025

Copy link
Copy Markdown
Contributor

Unfortunately dictionary encoding is best effort, and writers will fallback to different encodings if the dictionary gets too large. The result is you need to know if all the pages are dictionary encoded in order to be able to make this optimisation - iirc this information is not encoded anywhere but the page header itself...

This is why the page encoding stats exist in the column metadata. This will tell you if all pages in a given chunk are dictionary encoded. (See

/// Returns the page encoding statistics reduced to a bitmask, or `None` if statistics are
/// not available (or they were left in their original form).
///
/// The [`PageEncodingStats`] struct was added to the Parquet specification specifically to
/// enable fast determination of whether all pages in a column chunk are dictionary encoded
/// (see <https://github.com/apache/parquet-format/pull/16>).
/// Decoding the full page encoding statistics, however, can be very costly, and is not
/// necessary to support the aforementioned use case. As an alternative, this crate can
/// instead distill the list of `PageEncodingStats` down to a bitmask of just the encodings
/// used for data pages
/// (see [`ParquetMetaDataOptions::set_encoding_stats_as_mask`]).
/// To test for an all-dictionary-encoded chunk one could use this bitmask in the following way:
)

That said, I'm not nuts about duplicating the logic to decode the dictionary page, and just for the async reader. If we're going down this path, then I think all readers should have access. Perhaps this could be in ArrowReaderBuilder or even ParquetMetaData 🤷

@DarkWanderer

DarkWanderer commented Dec 19, 2025 •

Copy link
Copy Markdown
Contributor Author

This is why the page encoding stats exist in the column metadata. This will tell you if all pages in a given chunk are dictionary encoded.

Thanks for confirming, that was my intuition as well

That said, I'm not nuts about duplicating the logic to decode the dictionary page, and just for the async reader. If we're going down this path, then I think all readers should have access. Perhaps this could be in ArrowReaderBuilder or even ParquetMetaData

I would note that there is already a disparity in available APIs. Specifically, SerializedFileReader gives access to RowGroupReader, which in turn gives raw access to PageReader - this capability is missing in ParquetRecordBatchStreamBuilder. Also, method get_row_group_column_bloom_filter is already exposed in ParquetRecordBatchStreamBuilder, that was my motivation for placing get_row_group_column_dictionary near it.

I hear your argument about consistent API and code duplication however, will think of a better place to insert it.

@github-actions

Copy link
Copy Markdown

Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days.

@github-actions github-actions Bot added the Stale Used by workflow to mark PRs that will be auto-closed label Jun 25, 2026
@github-actions github-actions Bot closed this Jul 4, 2026
DarkWanderer added a commit to DarkWanderer/arrow-rs that referenced this pull request Jul 23, 2026
Reimplements the dictionary-page decode API (originally apache#9011) against
current main: `ParquetMetaDataReader::read_column_dictionary` (sync)
and `read_column_dictionary_async` (async), plus a
`ParquetRecordBatchStreamBuilder::get_row_group_column_dictionary`
convenience method, to decode a BYTE_ARRAY column chunk's dictionary
page on its own, independent of the row-by-row array reader.

This lets callers treat a fully dictionary-encoded column chunk's
dictionary as an exact row-group membership index for pruning
purposes, without materializing the whole column.

See apache#9010.
etseidl added a commit that referenced this pull request Sep 25, 2026
# Which issue does this PR close?

- Closes #9010.
- Supersedes #9011 (closed as stale)

# Rationale for this change

This change provides low-level API necessary for enabling
dictionary-based pruning in DataFusion:
apache/datafusion#23851

# What changes are included in this PR?

- `parquet::file::metadata::dictionary::decode_dictionary_page`: decodes
a BYTE_ARRAY dictionary page (Thrift header parse, decompress, PLAIN
decode) into a `Utf8`/`Binary` Arrow array.
- `ParquetMetaDataReader::read_column_dictionary` (sync) and
`read_column_dictionary_async` (async) to fetch and decode a given row
group/column's dictionary page from a `ParquetMetaData`, returning
`Ok(None)` if the chunk has no dictionary page.
- `ParquetRecordBatchStreamBuilder::get_row_group_column_dictionary`
convenience method mirroring `get_row_group_column_bloom_filter`.

# Are these changes tested?

Yes: a round-trip unit test for a dictionary-encoded string column, a
non-BYTE_ARRAY rejection test, and sync + async reader tests that decode
a real dictionary page written through `ArrowWriter`.

# Are there any user-facing changes?

Yes, three new public APIs (see above). No changes to
existing API.

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
Co-authored-by: Ed Seidl <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parquet parquet crate Stale Used by workflow to mark PRs that will be auto-closed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable access to column dictionaries in async reader

3 participants