-
Notifications
You must be signed in to change notification settings - Fork 500
fix: normalize dictionary types in Arrow scans #3444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,7 @@ | |
| _ConvertToArrowSchema, | ||
| _determine_partitions, | ||
| _primitive_to_physical, | ||
| _pyarrow_table_ensure_non_dictionary_types, | ||
| _read_deletes, | ||
| _task_to_record_batches, | ||
| _to_requested_schema, | ||
|
|
@@ -1301,6 +1302,47 @@ def test_projection_concat_files(schema_int: Schema, file_int: str) -> None: | |
| assert repr(result_table.schema) == "id: int32" | ||
|
|
||
|
|
||
| def test_arrow_scan_to_table_with_mixed_dictionary_and_plain_strings() -> None: | ||
| schema = Schema(NestedField(1, "foo", StringType(), required=False)) | ||
| scan = ArrowScan( | ||
| table_metadata=TableMetadataV2( | ||
| location="file://a/b/", | ||
| last_column_id=1, | ||
| format_version=2, | ||
| schemas=[schema], | ||
| partition_specs=[PartitionSpec()], | ||
| ), | ||
| io=PyArrowFileIO(), | ||
| projected_schema=schema, | ||
| row_filter=AlwaysTrue(), | ||
| ) | ||
| values = pa.array(["a"], type=pa.string()) | ||
| batches = iter([pa.record_batch([values], names=["foo"]), pa.record_batch([values.dictionary_encode()], names=["foo"])]) | ||
|
|
||
| with patch.object(scan, "to_record_batches", return_value=batches): | ||
| assert scan.to_table([]).to_pydict() == {"foo": ["a", "a"]} | ||
|
|
||
|
|
||
| def test_pyarrow_table_ensure_non_dictionary_types_nested() -> None: | ||
| dictionary_values = pa.array(["a"]).dictionary_encode() | ||
| table = pa.table( | ||
| { | ||
| "struct": pa.StructArray.from_arrays([dictionary_values], names=["value"]), | ||
| "list": pa.ListArray.from_arrays(pa.array([0, 1]), dictionary_values), | ||
| } | ||
| ) | ||
|
|
||
| normalized_table = _pyarrow_table_ensure_non_dictionary_types(table) | ||
|
|
||
| assert normalized_table.schema == pa.schema( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This equality check won’t catch dropped metadata like field IDs. Since field IDs matter for Iceberg projection, can we use |
||
| [ | ||
| pa.field("struct", pa.struct([pa.field("value", pa.string())])), | ||
| pa.field("list", pa.list_(pa.string())), | ||
| ] | ||
| ) | ||
| assert normalized_table.to_pydict() == {"struct": [{"value": "a"}], "list": [["a"]]} | ||
|
|
||
|
|
||
| def test_identity_transform_column_projection(tmp_path: str, catalog: InMemoryCatalog) -> None: | ||
| # Test by adding a non-partitioned data file to a partitioned table, verifying partition value | ||
| # projection from manifest metadata. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to parameterize this test and cover all the container types handled in the new helper: top-level dictionary, struct, list, large_list, fixed_size_list, and map.