zeroshade commented on code in PR #135:
URL: https://github.com/apache/arrow-go/pull/135#discussion_r1773676714


##########
arrow/array/struct.go:
##########
@@ -43,6 +43,31 @@ func NewStructArray(cols []arrow.Array, names []string) 
(*Struct, error) {
        return NewStructArrayWithNulls(cols, names, nil, 0, 0)
 }
 
+// NewStructArrayWithFields builds a new Struct Array using the passed columns
+// and provided fields. As opposed to NewStructArray, this allows you to 
provide
+// the full fields to utilize for the struct column instead of just the names.
+func NewStructArrayWithFields(cols []arrow.Array, fields []arrow.Field) 
(*Struct, error) {
+       if len(cols) != len(fields) {
+               return nil, fmt.Errorf("%w: mismatching number of fields and 
child arrays", arrow.ErrInvalid)
+       }
+       if len(cols) == 0 {
+               return nil, fmt.Errorf("%w: can't infer struct array length 
with 0 child arrays", arrow.ErrInvalid)
+       }
+
+       length := cols[0].Len()
+       children := make([]arrow.ArrayData, len(cols))
+       for i, c := range cols {
+               if length != c.Len() {
+                       return nil, fmt.Errorf("%w: mismatching child array 
lengths", arrow.ErrInvalid)
+               }
+               children[i] = c.Data()
+       }
+
+       data := NewData(arrow.StructOf(fields...), length, 
[]*memory.Buffer{nil}, children, 0, 0)
+       defer data.Release()
+       return NewStructData(data), nil

Review Comment:
   good point, i've added the check



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