tustvold commented on code in PR #5186:
URL: https://github.com/apache/arrow-rs/pull/5186#discussion_r1436917399
##########
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:
The use of `.` as a separator makes me uncomfortable, there have been a lot
of bugs in the past resulting from things incorrectly treating `.` as a nesting
delimiter...
This is something I'll try to address when I iterate on the visitor
--
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]