zeroshade commented on code in PR #1611:
URL: https://github.com/apache/arrow-go/pull/1611#discussion_r4620024464
##########
arrow/scalar/scalar.go:
##########
@@ -1043,6 +1045,86 @@ func MakeArrayFromScalar(sc Scalar, length int, mem
memory.Allocator) (arrow.Arr
data.Release()
}()
return array.MakeFromData(data), nil
+ case *SparseUnion:
+ if err := s.Validate(); err != nil {
+ return nil, err
+ }
+ dt := s.DataType().(*arrow.SparseUnionType)
+ childID := dt.ChildIDs()[s.TypeCode]
+
+ children := make([]arrow.ArrayData, dt.NumFields())
+ for i, f := range dt.Fields() {
+ var child arrow.Array
+ if i == childID && s.Valid {
+ var err error
+ if child, err = MakeArrayFromScalar(s.Value[i],
length, mem); err != nil {
+ return nil, err
+ }
+ } else {
+ child = MakeArrayOfNull(f.Type, length, mem)
+ }
+ defer child.Release()
+ children[i] = child.Data()
+ }
+
+ typeCodes := createBuffer([]byte{byte(s.TypeCode)})
+ defer typeCodes.Release()
+ data := array.NewData(dt, length, []*memory.Buffer{nil,
typeCodes}, children, 0, 0)
+ defer data.Release()
+ return array.MakeFromData(data), nil
+ case *DenseUnion:
+ if err := s.Validate(); err != nil {
Review Comment:
A dense union scalar with `Valid == false` and a nil `Value` gives an
all-null array on main, because the null shortcut returned before looking at
it. Here it reaches `Validate`, which calls `s.Value.DataType()` and panics
with a nil pointer dereference:
```go
s := scalar.NewDenseUnionScalar(scalar.NewInt32Scalar(1), 5, dt)
s.Valid = false
s.Value = nil
scalar.MakeArrayFromScalar(s, 3, mem) // panics
```
The description mentions this, but since `MakeArrayFromScalar` returns an
error, could it return one here? A nil check in `DenseUnion.Validate` and
`ValidateFull` would do it. A nil entry in `SparseUnion.Value` looks like it
reaches the same kind of dereference, though I did not run that case. A test
case in `TestMakeArrayFromInvalidNestedScalar` would keep it that way.
--
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]