tustvold commented on code in PR #5149:
URL: https://github.com/apache/arrow-rs/pull/5149#discussion_r1409820310
##########
arrow-schema/src/fields.rs:
##########
@@ -99,6 +100,93 @@ 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
+ ///
+ /// Invokes `filter` with each leaf [`FieldRef`], i.e. one containing no
children, and a
+ /// count of the number of previous calls to `filter` - i.e. the leaf's
index.
+ ///
+ /// 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 {
+ fn filter_field<F: FnMut(&FieldRef) -> bool>(
+ f: &FieldRef,
+ filter: &mut F,
+ ) -> Option<FieldRef> {
+ use DataType::*;
+
+ let (k, v) = match f.data_type() {
+ Dictionary(k, v) => (Some(k.clone()), v.as_ref()),
Review Comment:
Added comments in
https://github.com/apache/arrow-rs/pull/5149/commits/8d9795069c8244820b2107c76f46d9d484ee4740
##########
arrow-schema/src/fields.rs:
##########
@@ -99,6 +100,93 @@ 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
+ ///
+ /// Invokes `filter` with each leaf [`FieldRef`], i.e. one containing no
children, and a
+ /// count of the number of previous calls to `filter` - i.e. the leaf's
index.
+ ///
+ /// 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 {
+ fn filter_field<F: FnMut(&FieldRef) -> bool>(
+ f: &FieldRef,
+ filter: &mut F,
+ ) -> Option<FieldRef> {
+ use DataType::*;
+
+ let (k, v) = match f.data_type() {
+ Dictionary(k, v) => (Some(k.clone()), v.as_ref()),
+ d => (None, d),
+ };
+ let d = match v {
Review Comment:
RunEndEncoded support added in
https://github.com/apache/arrow-rs/pull/5149/commits/8d9795069c8244820b2107c76f46d9d484ee4740
--
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]