@@ -46,6 +46,13 @@ func NewStructArray(cols []arrow.Array, names []string) (*Struct, error) {
4646// and provided fields. As opposed to NewStructArray, this allows you to provide
4747// the full fields to utilize for the struct column instead of just the names.
4848func NewStructArrayWithFields (cols []arrow.Array , fields []arrow.Field ) (* Struct , error ) {
49+ return NewStructArrayWithFieldsAndNulls (cols , fields , nil , 0 , 0 )
50+ }
51+
52+ // NewStructArrayWithFieldsAndNulls is like NewStructArrayWithFields as a convenience function,
53+ // but also takes in a null bitmap, the number of nulls, and an optional offset
54+ // to use for creating the Struct Array.
55+ func NewStructArrayWithFieldsAndNulls (cols []arrow.Array , fields []arrow.Field , nullBitmap * memory.Buffer , nullCount int , offset int ) (* Struct , error ) {
4956 if len (cols ) != len (fields ) {
5057 return nil , fmt .Errorf ("%w: mismatching number of fields and child arrays" , arrow .ErrInvalid )
5158 }
@@ -63,15 +70,18 @@ func NewStructArrayWithFields(cols []arrow.Array, fields []arrow.Field) (*Struct
6370 return nil , fmt .Errorf ("%w: mismatching data type for child #%d, field says '%s', got '%s'" ,
6471 arrow .ErrInvalid , i , fields [i ].Type , c .DataType ())
6572 }
66- if ! fields [i ].Nullable && c .NullN () > 0 {
67- return nil , fmt .Errorf ("%w: field says not-nullable, child #%d has nulls" ,
68- arrow .ErrInvalid , i )
69- }
7073
7174 children [i ] = c .Data ()
7275 }
7376
74- data := NewData (arrow .StructOf (fields ... ), length , []* memory.Buffer {nil }, children , 0 , 0 )
77+ if nullBitmap == nil {
78+ if nullCount > 0 {
79+ return nil , fmt .Errorf ("%w: null count is greater than 0 but null bitmap is nil" , arrow .ErrInvalid )
80+ }
81+ nullCount = 0
82+ }
83+
84+ data := NewData (arrow .StructOf (fields ... ), length - offset , []* memory.Buffer {nullBitmap }, children , nullCount , offset )
7585 defer data .Release ()
7686 return NewStructData (data ), nil
7787}
0 commit comments