Skip to content

feat(parquet): add dictionary row-group pruning - #1112

Open
zhjwpku wants to merge 8 commits into
apache:mainfrom
zhjwpku:feat/parquet-dictionary-row-group-filter
Open

zhjwpku wants to merge 8 commits into
apache:mainfrom
zhjwpku:feat/parquet-dictionary-row-group-filter

Conversation

@zhjwpku

@zhjwpku zhjwpku commented Nov 11, 2026

Copy link
Copy Markdown
Member

Use column dictionaries to prune row groups after footer-statistics filtering. Support comparison, set, prefix and NaN predicates, and cache decoded dictionaries within each row group.

Keep row groups when encoding metadata cannot rule out plain fallback or field IDs and types cannot be resolved safely. Preserve file-relative row positions and row IDs after pruning.

Share physical-value conversion with Parquet metrics and add tests for predicate handling, type promotion, mixed encoding, splits and invalid dictionary pages.


Result<bool> In(const std::shared_ptr<Bound>& expr,
const BoundSetPredicate::LiteralSet& values) override {
return AnyMatch(expr, [&](const Literal& item) { return values.contains(item); });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will return false for NaN.

@zhjwpku zhjwpku Nov 12, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Literal uses a custom comparison, so contains can match the same NaN literal in the set, I'm not sure if this is your concern.

Result<bool> StartsWith(const std::shared_ptr<Bound>& expr,
const Literal& value) override {
return AnyMatch(expr, [&](const Literal& item) {
return std::get<std::string>(item.value())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can thrown uncaught if the variant is not a string.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binder already checks that the term is a string and converts the prefix literal to the same type. ParquetMetricsRowGroupFilter also relies on this and uses std::getstd::string for StartsWith and NotStartsWith.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a second check, it seems users can still manually create an invalid BoundPredicate and bypass Binder's checks. But this is rare, we can address this for both filters in a follow-up if needed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a case where this PR changes what Open does. With a fully dictionary-encoded string column and no footer bounds, the stats filter keeps the group. If a caller supplies an already-bound StartsWith predicate with a non-string prefix, the new dictionary path throws std::bad_variant_access. Could we validate the operands for both prefix operations and return InvalidExpression? This case would also make a focused regression test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Both StartsWith and NotStartsWith now check the term and prefix types. It returns InvalidExpression for invalid operands.

@zhjwpku
zhjwpku force-pushed the feat/parquet-dictionary-row-group-filter branch from d1de99e to a81101f Compare November 12, 2026 10:47
ICEBERG_ARROW_ASSIGN_OR_RETURN(auto file_size, input_->GetSize());
if (!column->has_dictionary_page() || start < 4 || end <= start ||
end > file_size) {
return Invalid("Invalid Parquet dictionary offsets [{}, {}) for field {}", start,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we tolerate dictionary offset errors? It should only affect pruning.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, changed to return nullptr, I/O errors and dictionary parsing/decoding failures still propagate.

@zhjwpku
zhjwpku force-pushed the feat/parquet-dictionary-row-group-filter branch from 022cfac to 6aa69fe Compare November 22, 2026 16:20
auto encoding = page.encoding() == ::parquet::Encoding::PLAIN_DICTIONARY
? ::parquet::Encoding::PLAIN
: page.encoding();
auto decoder = ::parquet::MakeTypedDecoder<DType>(encoding, &column);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please accept only PLAIN and legacy PLAIN_DICTIONARY here and decode both as PLAIN. The generic decoder also accepts data-page encodings such as BYTE_STREAM_SPLIT. Pruning could then silently skip a group whose dictionary page Arrow's column reader would reject.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to suggested.

// Unusable offsets cannot prove that the predicate cannot match.
return nullptr;
}
ICEBERG_ARROW_ASSIGN_OR_RETURN(auto data, input_->ReadAt(start, end - start));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check that the dictionary range fits within the column chunk before calling ReadAt. A data-page offset in a later chunk still passes the file-size check, and this call allocates and reads the entire gap. If the range cannot be validated, keep the group.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the chunk size check before ReadAt. Test now covers a data page offset that is inside the file but past the current chunk. The filter keeps the group without reading the dictionary.

try {
DictionaryVisitor visitor(manifest, *row_group, field_id_to_column_idx_, input,
properties, metadata.writer_version());
return Visit<bool>(bound_, visitor);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could dictionary evaluation short-circuit AND and OR? Once the left side rules out an AND or retains an OR, visiting the right side can issue a second column read and even fail Open. A two-column test using the recording stream could assert that only the first dictionary is read.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion, dictionary evaluation now short-circuits AND and OR, added a test accordingly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just rebased and switched to the newly added VisitEvaluator.

Result<bool> AnyMatch(const std::shared_ptr<Bound>& expr, Predicate predicate,
bool nulls_match = false) {
auto ref = std::dynamic_pointer_cast<BoundReference>(expr);
ICEBERG_ASSIGN_OR_RAISE(auto dictionary, GetDictionary(ref));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For predicates where nulls match, could we check the resolved column's null count before fetching its dictionary? If the count is positive or unknown, we already have to keep the group and can skip the read and decode.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the null count check before the dictionary read.

Use column dictionaries to prune row groups after footer-statistics
filtering. Support comparison, set, prefix and NaN predicates, and cache
decoded dictionaries within each row group.

Keep row groups when encoding metadata cannot rule out plain fallback
or field IDs and types cannot be resolved safely. Preserve file-relative
row positions and row IDs after pruning.

Share physical-value conversion with Parquet metrics and add tests for
predicate handling, type promotion, mixed encoding, splits and invalid
dictionary pages.
Read the byte range between dictionary_page_offset and data_page_offset
instead of loading the full column chunk during planning. Validate the
range and keep using Arrow for page decompression. Skip dictionary pruning
for encrypted columns so the normal reader handles them.

Treat unreadable optional statistics as possible nulls instead of failing
the scan. Keep errors for missing or truncated dictionary pages, and explain
why rewritten null branches remain inclusive.

Add regression tests for planning read ranges with multi-megabyte data
pages, invalid offsets, unreadable statistics, signed zeros, and compressed
V1/V2 pages. The complete Parquet suite passes all 213 tests, and pre-commit
passes.
Use metadata-only projection to keep output-column prefetch out of the dictionary I/O assertion. Add float/double IN and NOT IN coverage with NaN literals.
Validate prefix predicate operands, dictionary page encodings, and column chunk boundaries before pruning. Short-circuit boolean predicates and consult null counts before reading dictionaries for negative predicates.
@zhjwpku
zhjwpku force-pushed the feat/parquet-dictionary-row-group-filter branch from 5652078 to 7d617ae Compare November 29, 2026 02:33

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants