adamreeve commented on code in PR #55665:
URL: https://github.com/apache/arrow/pull/55665#discussion_r4609280422


##########
python/pyarrow/_dataset.pyx:
##########
@@ -1097,6 +1109,51 @@ cdef class UnionDataset(Dataset):
         return [Dataset.wrap(children[i]) for i in range(children.size())]
 
 
+cdef class FilteredDataset(Dataset):
+    """
+    A Dataset viewing only the rows of a child dataset that match a filter.
+
+    Unlike :meth:`Dataset.filter`, the filter is part of the dataset itself, so
+    it is preserved when this dataset is unioned with datasets that have
+    different filters. Rows for which the filter evaluates to null are dropped.
+
+    Parameters
+    ----------
+    child : Dataset
+        The dataset to filter. Any filter already applied to it with
+        :meth:`Dataset.filter` is combined with ``filter``.
+    filter : Expression
+        A boolean expression referencing fields of the child's schema.
+    """
+
+    cdef:
+        CFilteredDataset* filtered_dataset
+
+    def __init__(self, Dataset child not None, Expression filter not None):
+        current_filter = child._scan_options.get("filter")
+        if current_filter is not None:
+            filter = current_filter & filter
+        self.init(<shared_ptr[CDataset]> GetResultValue(
+            CFilteredDataset.Make(child.wrapped, (<Expression> 
filter).unwrap())))
+
+    cdef void init(self, const shared_ptr[CDataset]& sp):
+        Dataset.init(self, sp)
+        self.filtered_dataset = <CFilteredDataset*> sp.get()
+
+    def __reduce__(self):
+        return FilteredDataset, (self.child, self.filter)
+
+    @property
+    def child(self):
+        """The unfiltered child Dataset."""
+        return Dataset.wrap(self.filtered_dataset.child())
+
+    @property
+    def filter(self):
+        """The filter applied to the child Dataset."""
+        return Expression.wrap(self.filtered_dataset.filter())

Review Comment:
   Fixed in 8d2b1ecae7104d8970df5fb003ce9a4ce9c41a15



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to