Repository navigation
Core: Decode dictionary arrays before applying Arrow partition transforms - #4340
Anurag-S1ngh wants to merge 2 commits into
Conversation
Fokko
left a comment
There was a problem hiding this comment.
Thanks for working on this @Anurag-S1ngh, left some comments
|
|
||
| if isinstance(array, pa.Array): | ||
| return _cast_if_needed(transform_func(array, *args)) | ||
| return _cast_if_needed(transform_func(_decode_if_dictionary(array), *args)) |
There was a problem hiding this comment.
We don't always have to decode the dictionary, for example, for an identity or void transform, this isn't needed. How about doing this as part of pyarrow_transform?
| table.append(pyarrow_table) | ||
|
|
||
|
|
||
| def test_write_dictionary_encoded_column_with_bucket_partition(catalog: Catalog) -> None: |
There was a problem hiding this comment.
I don't think this is catalog related, let's remove this test
|
|
||
|
|
||
| def test_pyarrow_transform_decodes_dictionary_arrays() -> None: | ||
| transform: Transform[Any, Any] = BucketTransform(num_buckets=8) |
There was a problem hiding this comment.
Can we parameterize the test to go over all the transforms?
Decode only in the transforms that need it instead of the shared Arrow wrapper, drop the catalog behavior test since it is not catalog specific, and parameterize the transform test to cover all transforms.
|
Addressed all three points in cf62de0: the dictionary decode now happens in the individual |
Rationale for this change
Appending a dictionary-encoded Arrow table to a table partitioned by
bucket,truncate,year,month,dayorhourraised:The partition transforms run on Arrow arrays through
_pyiceberg_transform_wrapper, which forwarded the array as-is. The Arrow kernels behind the transforms have no implementation for dictionary types, so any dictionary-encoded column used in a partition transform failed even though Iceberg has no dictionary type and reads such a column as its value type.The wrapper now decodes dictionary arrays with
dictionary_decode()before calling the transform, per chunk for chunked arrays. The result matches what the same values produce without dictionary encoding, so partitions, and therefore partition pruning, stay the same.Are these changes tested?
Yes.
tests/test_transforms.py::test_pyarrow_transform_decodes_dictionary_arrayscovers bothpa.Arrayandpa.ChunkedArrayand asserts the dictionary-encoded input gives the same buckets as the plain input, including a null.tests/catalog/test_catalog_behaviors.py::test_write_dictionary_encoded_column_with_bucket_partitionappends a dictionary-encoded table to a bucket-partitioned table, checks the rows read back and that both partitions were created. It runs against the memory, sql, and sql_without_rowcount catalogs.Both fail on main and pass with the change.
Full unit suite:
4573 passed, 5 skipped.prek run -apasses.Are there any user-facing changes?
Yes. Appending dictionary-encoded columns to a table with a partition transform now works instead of raising
FeatureUnsupported.Closes #3633