zeroshade commented on code in PR #13806:
URL: https://github.com/apache/arrow/pull/13806#discussion_r939218404


##########
go/arrow/ipc/writer.go:
##########
@@ -574,6 +577,100 @@ func (w *recordEncoder) visit(p *Payload, arr 
arrow.Array) error {
                }
                w.depth++
 
+       case *arrow.SparseUnionType:
+               offset, length := arr.Data().Offset(), arr.Len()
+               arr := arr.(*array.SparseUnion)
+               typeCodes := getTruncatedBuffer(int64(offset), int64(length), 
int32(unsafe.Sizeof(arrow.UnionTypeCode(0))), arr.TypeCodes())
+               p.body = append(p.body, typeCodes)
+
+               w.depth--
+               for i := 0; i < arr.NumFields(); i++ {
+                       err := w.visit(p, arr.Field(i))
+                       if err != nil {
+                               return fmt.Errorf("could not visit field %d of 
sparse union array: %w", i, err)
+                       }
+               }
+               w.depth++
+       case *arrow.DenseUnionType:
+               offset, length := arr.Data().Offset(), arr.Len()
+               arr := arr.(*array.DenseUnion)
+               typeCodes := getTruncatedBuffer(int64(offset), int64(length), 
int32(unsafe.Sizeof(arrow.UnionTypeCode(0))), arr.TypeCodes())
+               p.body = append(p.body, typeCodes)
+
+               w.depth--
+               dt := arr.UnionType()
+
+               // union type codes are not necessarily 0-indexed
+               maxCode := dt.MaxTypeCode()
+
+               // allocate an array of child offsets. Set all to -1 to 
indicate we
+               // haven't observed a first occurrence of a particular child yet
+               offsets := make([]int32, maxCode+1)
+               lengths := make([]int32, maxCode+1)
+               offsets[0], lengths[0] = -1, 0
+               for i := 1; i < len(offsets); i *= 2 {
+                       copy(offsets[i:], offsets[:i])
+                       copy(lengths[i:], lengths[:i])
+               }
+
+               var valueOffsets *memory.Buffer
+               if offset != 0 {
+                       // this case sucks. Because the offsets are different 
for each
+                       // child array, when we have a sliced array, we need to 
re-base
+                       // the value offsets for each array! ew.
+

Review Comment:
   created new function `rebaseDenseUnionValueOffsets`



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