Repository navigation
Fix StartsWith filters on dictionary-encoded columns - #4605
Merged
Merged
Conversation
pc.starts_with has no kernel for dictionary arrays, so LIKE 'ap%' raised in scans, deletes and overwrites when a string column was read as a dictionary (dictionary_columns, or a file written from a pandas categorical). Read the field of StartsWith and NotStartsWith as the Arrow type of its Iceberg type (large_string or large_binary), which decodes dictionaries and keeps binary prefixes. Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Fokko
approved these changes
Dec 3, 2026
Fokko
left a comment
Contributor
There was a problem hiding this comment.
Nice fix, verified the dictionary-encoded string, binary and struct cases pass with the cast. Thanks @rahulsmahadev 🚀
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.
Rationale for this change
Bug:
StartsWithandNotStartsWith(LIKE 'ap%') raise when a string column is read as an Arrow dictionary.pc.starts_withhas no dictionary kernel (no Arrow string kernel has one yet, apache/arrow#40430), while the comparison andis_inkernels decode dictionaries, so=,<andINwork on the same column:The same happens without
dictionary_columnsfor a file written from a pandas categorical or a PolarsEnumcolumn (appended, or added withadd_files), indeleteandoverwritewith such a filter, and for struct fields (addr.city LIKE 'ap%').Fix:
_ConvertToArrowExpressionreads the field ofstarts_withas the Arrow type of its Iceberg type,large_stringorlarge_binary(from_ConvertToArrowSchema, as for the literals of the other predicates). Only the predicate input is decoded, like #4340 for the partition transforms (with a cast, because an Arrow expression cannot calldictionary_decode), so scans still return dictionary columns and binary prefixes (#3501) stay bytes. Alarge_stringcolumn is not copied; astringcolumn only gets wider offsets.Java prunes files and row groups on bounds and dictionaries, then checks rows on decoded values:
Evaluatorin the generic reader, and the engine on the values the vectorized reader decodes (DictionaryStringAccessor). PyIceberg runs that row check in Arrow, in scans and in the rewrite ofdelete; this PR fixes that part.starts_withprefix (only row groups that hold a single value or only nulls), with or without this change; Java'sParquetMetricsRowGroupFilterandParquetDictionaryRowGroupFilterprune on the prefix.#4342 (for #3260) decodes unrequested top-level dictionaries after the read, so it does not reach the scan filter,
dictionary_columnsor struct fields.Are these changes tested?
Yes:
test_starts_with_dictionary_encoded_to_pyarrow(string and binary columns, plain and dictionary arrays) andtest_row_filter_starts_with_on_dictionary_encoded_strings(dictionary_columns, a dictionary file with a struct field,delete) fail on main with the error above and pass with this change; the twostarts_withrepr tests now expect the cast.Are there any user-facing changes?
Prefix filters, deletes and overwrites work on dictionary-encoded columns, and
expression_to_pyarrowcasts thestarts_withfield tolarge_stringorlarge_binary. Please add thechangeloglabel.This pull request and its description were written by Isaac.