Skip to content

Transforms: Support dictionary-encoded PyArrow arrays in partition transforms (#3633) - #3841

Open
hedger9487 wants to merge 1 commit into
apache:mainfrom
hedger9487:fix/dictionary-encoded-pyarrow-transforms-3633
Open

Transforms: Support dictionary-encoded PyArrow arrays in partition transforms (#3633)#3841
hedger9487 wants to merge 1 commit into
apache:mainfrom
hedger9487:fix/dictionary-encoded-pyarrow-transforms-3633

Conversation

@hedger9487

Copy link
Copy Markdown

Description

Fixes #3633.

When PyArrow tables containing dictionary-encoded columns (pa.DictionaryArray) are passed to Iceberg partition transforms (such as BucketTransform, TruncateTransform, or time transforms), _pyiceberg_transform_wrapper forwards the DictionaryArray directly to pyiceberg_core.transform, raising ValueError: Feature Unsupported => Unsupported data type for bucket transform: Dictionary(Int64, Utf8).

This PR updates _pyiceberg_transform_wrapper to normalize dictionary-encoded arrays via arr.dictionary_decode() before invoking transform_func, allowing all partition transforms to transparently handle dictionary-encoded PyArrow arrays and chunked arrays.

Testing

  • Added test_pyarrow_transforms_dictionary_encoded in tests/test_transforms.py covering DictionaryArray and ChunkedArray on BucketTransform and TruncateTransform.
  • All 284 transform tests pass locally.

Copilot AI lite review requested due to automatic review settings August 24, 2026 20:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates PyIceberg’s PyArrow partition transform wrapper to transparently handle dictionary-encoded (pa.DictionaryArray) inputs by decoding them before invoking pyiceberg_core.transform, preventing “Unsupported data type … Dictionary(…, …)” errors and enabling transforms to work with read_dictionary-produced columns.

Changes:

  • Normalize dictionary-encoded PyArrow arrays via dictionary_decode() inside _pyiceberg_transform_wrapper (including for ChunkedArray chunks).
  • Add a regression test exercising BucketTransform and TruncateTransform on dictionary-encoded arrays and chunked dictionary arrays.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pyiceberg/transforms.py Decode dictionary-encoded PyArrow arrays before passing them to pyiceberg_core transform functions.
tests/test_transforms.py Add coverage for dictionary-encoded and chunked dictionary-encoded inputs for key partition transforms.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/test_transforms.py
Comment on lines +1716 to +1727
dict_arr = pa.DictionaryArray.from_arrays(pa.array([0, 1, 0, None]), pa.array(["foo", "bar"]))
raw_arr = pa.array(["foo", "bar", "foo", None])
bucket_transform = BucketTransform(num_buckets=10)
expected_bucket = bucket_transform.pyarrow_transform(StringType())(raw_arr)
assert bucket_transform.pyarrow_transform(StringType())(dict_arr) == expected_bucket

chunked_dict = pa.chunked_array([dict_arr, dict_arr])
expected_chunked = pa.chunked_array([expected_bucket, expected_bucket])
assert bucket_transform.pyarrow_transform(StringType())(chunked_dict) == expected_chunked

truncate_transform = TruncateTransform(width=3)
dict_truncate_arr = pa.DictionaryArray.from_arrays(pa.array([0, 1, 0]), pa.array(["developer", "iceberg"]))
Comment thread tests/test_transforms.py
Comment on lines +1715 to +1720
def test_pyarrow_transforms_dictionary_encoded() -> None:
dict_arr = pa.DictionaryArray.from_arrays(pa.array([0, 1, 0, None]), pa.array(["foo", "bar"]))
raw_arr = pa.array(["foo", "bar", "foo", None])
bucket_transform = BucketTransform(num_buckets=10)
expected_bucket = bucket_transform.pyarrow_transform(StringType())(raw_arr)
assert bucket_transform.pyarrow_transform(StringType())(dict_arr) == expected_bucket
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.

BucketTransform fails on dictionary-encoded pyArrow arrays

2 participants