Repository navigation
Unify partition key dictionaries before grouping - #4542
Open
rahulsmahadev wants to merge 1 commit into
Open
rahulsmahadev wants to merge 1 commit into
rahulsmahadev wants to merge 1 commit into
Conversation
Each chunk of a dictionary column can carry its own dictionary, e.g. after pa.concat_tables of pandas categoricals, and group_by cannot combine them, so an append identity-partitioned on such a column failed with "Unifying differing dictionaries". Combine the chunks of the partition key columns before grouping, which unifies their dictionaries; unify_dictionaries() would reject a shared dictionary that fills its index type, which appends today. Co-authored-by: Isaac <no-reply@databricks.com>
Contributor
Author
|
@Anurag-S1ngh, this follows up on your #4340 for identity partitions: identity needs no decode, but |
This branch has not been deployed
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: each chunk of a dictionary column can have its own dictionary, e.g. after
pa.concat_tablesof tables with pandas categoricals. Appending to a table identity-partitioned on that column fails, becausegroup_byin_determine_partitionscannot combine the dictionaries (apache/arrow#14955):Whether the chunks share a dictionary is an encoding detail, and the same rows append fine when they do.
Fix: combine the chunks of the partition key columns before
group_by, which unifies their dictionaries. The data columns are not touched, so the written files keep their dictionary type.#4340 decodes dictionaries inside the bucket, truncate and time transforms; identity needs no decode, only unified dictionaries for the grouping.
Combining different dictionaries still fails when their union exceeds 127 entries with int8 indices; index widening needs a separate change.
upsertgroups its join columns the same way (has_duplicate_rowsinupsert_util.py) and still fails on such input (#3835); that is a separate change too. As with other dictionary appends today, scanning a table that mixes these files with plain string files needs the open #4342 (#3260).Java computes the partition key from each row's values (
SparkWritecallsPartitionKey.partitionbefore the fanout or clustered writer), so dictionaries never reach the grouping; this PR fixes the matching grouping step in_determine_partitions.Are these changes tested?
Yes, added
test_append_dictionary_chunks_to_partitioned_table(with a null key) andtest_determine_partitions_with_nested_dictionary_chunks(partition source in a struct) totests/io/test_pyarrow.py. Both fail on main with the error above and pass with this change, also on pyarrow 18.1.test_determine_partitions_with_shared_dictionary_at_index_limitpasses on main and keeps a shared dictionary that fills its int8 indices working (unify_dictionaries()would reject it).Are there any user-facing changes?
Yes, these appends work now instead of raising.
Please add the
changeloglabel.This pull request and its description were written by Isaac.