This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git


The following commit(s) were added to refs/heads/main by this push:
     new 46d7835be Read a list or map column referenced by a null filter (#4400)
46d7835be is described below

commit 46d7835be0ecd101a7de324165fddb1f2d8e1e33
Author: Gedalia Kliger <[email protected]>
AuthorDate: Tue Nov 17 21:02:23 2026 +0000

    Read a list or map column referenced by a null filter (#4400)
    
    * Read a list or map column referenced by a null filter
    
    A scan filter that tests a list or map column for null added the column's 
own
    field ID to the projected IDs, and prune_columns rejects a list or map 
selected
    by its own ID. Project the column's nested fields instead.
    
    * Test null filters on list and map columns through a scan
---
 pyiceberg/io/pyarrow.py                 |  8 +++++++-
 tests/catalog/test_catalog_behaviors.py | 19 +++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/pyiceberg/io/pyarrow.py b/pyiceberg/io/pyarrow.py
index 53db9cd6b..5961da883 100644
--- a/pyiceberg/io/pyarrow.py
+++ b/pyiceberg/io/pyarrow.py
@@ -1952,11 +1952,17 @@ class ArrowScan:
     @property
     def _projected_field_ids(self) -> set[int]:
         """Set of field IDs that should be projected from the data files."""
+        schema = self._table_metadata.schema()
+        filter_field_ids = extract_field_ids(self._bound_row_filter)
+        # A list or map cannot be projected by its own ID, so a filter on one 
reads its nested fields instead
+        nested_field_ids = prune_columns(
+            schema, {id for id in filter_field_ids if 
isinstance(schema.find_type(id), (MapType, ListType))}
+        ).field_ids
         return {
             id
             for id in self._projected_schema.field_ids
             if not isinstance(self._projected_schema.find_type(id), (MapType, 
ListType))
-        }.union(extract_field_ids(self._bound_row_filter))
+        }.union(id for id in filter_field_ids | nested_field_ids if not 
isinstance(schema.find_type(id), (MapType, ListType)))
 
     def to_table(self, tasks: Iterable[FileScanTask]) -> pa.Table:
         """Scan the Iceberg table and return a pa.Table.
diff --git a/tests/catalog/test_catalog_behaviors.py 
b/tests/catalog/test_catalog_behaviors.py
index cd817512b..4b8fea113 100644
--- a/tests/catalog/test_catalog_behaviors.py
+++ b/tests/catalog/test_catalog_behaviors.py
@@ -1429,6 +1429,25 @@ def 
test_scan_integer_column_with_decimal_literal(catalog: Catalog) -> None:
         tbl.scan(row_filter="x > 2.6").to_arrow()
 
 
+def test_scan_null_filter_on_list_and_map_columns(catalog: Catalog) -> None:
+    catalog.create_namespace("default")
+    data = pa.table(
+        {
+            "id": pa.array([1, 2, 3], pa.int32()),
+            "tags": pa.array([["a"], [], None], pa.list_(pa.string())),
+            "props": pa.array([[("k", 1)], [], None], pa.map_(pa.string(), 
pa.int32())),
+            "points": pa.array([[{"x": 1}], [], None], 
pa.list_(pa.struct([("x", pa.int32())]))),
+        }
+    )
+    tbl = 
catalog.create_table(f"default.scan_null_filter_list_map_{catalog.name}", 
schema=data.schema)
+    tbl.append(data)
+
+    for column in ("tags", "props", "points"):
+        assert tbl.scan(row_filter=f"{column} is 
null").to_arrow()["id"].to_pylist() == [3], column
+        assert sorted(tbl.scan(row_filter=f"{column} is not 
null").to_arrow()["id"].to_pylist()) == [1, 2], column
+        assert tbl.scan(row_filter=f"{column} is null", 
selected_fields=("id",)).to_arrow().to_pydict() == {"id": [3]}, column
+
+
 def test_scan_negated_comparison_matches_file_pruning_for_nan(catalog: 
Catalog) -> None:
     catalog.create_namespace("default")
     identifier = f"default.scan_negated_comparison_nan_{catalog.name}"

Reply via email to