tustvold commented on code in PR #5186:
URL: https://github.com/apache/arrow-rs/pull/5186#discussion_r1437189297


##########
arrow-schema/src/field.rs:
##########
@@ -328,20 +328,80 @@ impl Field {
     /// within `self` contained within this field (including `self`)
     pub(crate) fn fields(&self) -> Vec<&Field> {
         let mut collected_fields = vec![self];
-        collected_fields.append(&mut Field::_fields(&self.data_type));
+        collected_fields.append(&mut Field::_fields(&self.data_type, true));
 
         collected_fields
     }
 
-    fn _fields(dt: &DataType) -> Vec<&Field> {
+    /// Returns a [`Vec`] direct children [`Field`]s
+    /// within `self`
+    pub(crate) fn nested_fields(&self) -> Vec<&Field> {
+        Field::_fields(&self.data_type, false)
+    }
+
+    /// Return self and direct children field names of the [`Field`]
+    ///
+    /// ```
+    /// # use arrow_schema::*;
+    /// let field = Field::new("nested",
+    ///        DataType::Struct(
+    ///            Fields::from(
+    ///                vec![
+    ///                    Field::new("inner",
+    ///                    DataType::Struct(
+    ///                        Fields::from(
+    ///                            vec![
+    ///                                Field::new("a", DataType::Int32, true)
+    ///                                ])), true)])), true
+    ///                );
+    ///
+    /// assert_eq!(field.children_names(), vec!["nested", "nested.inner", 
"nested.inner.a"]);
+    /// ```
+    pub fn children_names(&self) -> Vec<String> {
+        fn nested_field_names_inner(f: &Field, parent_name: String, buffer: 
&mut Vec<String>) {
+            let current_name = format!("{}{}", parent_name, f.name());
+
+            // Push the concatenated name to the result vector
+            buffer.push(current_name.clone());
+
+            // Recursively concatenate child names
+            for child in f.nested_fields() {
+                nested_field_names_inner(child, format!("{}.", current_name), 
buffer);

Review Comment:
   My vague thought was something similar to how we display parquet schema, 
where it might be something like
   
   ```
   struct batch {
      optional int64 column1
       optional struct nested {
           required float64 f64
       }
   }
   ```
   
   But implemented as some `FieldVisitor` abstraction so people can easily do 
something different should they wish to.
   
   I want to take some time to get my thoughts on this together, and will then 
get back to you



-- 
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