tustvold commented on code in PR #5149:
URL: https://github.com/apache/arrow-rs/pull/5149#discussion_r1409762734
##########
arrow-schema/src/fields.rs:
##########
@@ -99,6 +100,90 @@ impl Fields {
.all(|(a, b)| Arc::ptr_eq(a, b) || a.contains(b))
}
+ /// Performs a depth-first scan of [`Fields`] filtering the [`FieldRef`]
with no children
+ ///
+ /// Returns a new [`Fields`] comprising the [`FieldRef`] for which
`filter` returned `true`
+ ///
+ /// ```
+ /// # use arrow_schema::{DataType, Field, Fields};
+ /// let fields = Fields::from(vec![
+ /// Field::new("a", DataType::Int32, true),
+ /// Field::new("b", DataType::Struct(Fields::from(vec![
+ /// Field::new("c", DataType::Float32, false),
+ /// Field::new("d", DataType::Float64, false),
+ /// ])), false)
+ /// ]);
+ /// let filtered = fields.filter_leaves(|idx, _| idx == 0 || idx == 2);
+ /// let expected = Fields::from(vec![
+ /// Field::new("a", DataType::Int32, true),
+ /// Field::new("b", DataType::Struct(Fields::from(vec![
+ /// Field::new("d", DataType::Float64, false),
+ /// ])), false)
+ /// ]);
+ /// assert_eq!(filtered, expected);
+ /// ```
+ pub fn filter_leaves<F: FnMut(usize, &FieldRef) -> bool>(&self, mut
filter: F) -> Self {
Review Comment:
You would select b by selecting all its children, if you call with
intermediate fields you end up in a position of how much context do you
provide, just the parent, what about the parent's parent - reasoning in terms
of leaves is the only coherent mechanism I can think of
--
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]