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


##########
go/arrow/array/list.go:
##########
@@ -146,28 +146,177 @@ func (a *List) Release() {
        a.values.Release()
 }
 
-type ListBuilder struct {
+// LargeList represents an immutable sequence of array values.
+type LargeList struct {
+       array
+       values  arrow.Array
+       offsets []int64
+}
+
+// NewLargeListData returns a new LargeList array value, from data.
+func NewLargeListData(data arrow.ArrayData) *LargeList {
+       a := &LargeList{}
+       a.refCount = 1
+       a.setData(data.(*Data))
+       return a
+}
+
+func (a *LargeList) ListValues() arrow.Array { return a.values }
+
+func (a *LargeList) String() string {
+       o := new(strings.Builder)
+       o.WriteString("[")
+       for i := 0; i < a.Len(); i++ {
+               if i > 0 {
+                       o.WriteString(" ")
+               }
+               if !a.IsValid(i) {
+                       o.WriteString("(null)")
+                       continue
+               }
+               sub := a.newListValue(i)
+               fmt.Fprintf(o, "%v", sub)
+               sub.Release()
+       }
+       o.WriteString("]")
+       return o.String()
+}
+
+func (a *LargeList) newListValue(i int) arrow.Array {
+       j := i + a.array.data.offset
+       beg := int64(a.offsets[j])
+       end := int64(a.offsets[j+1])
+       return NewSlice(a.values, beg, end)
+}
+
+func (a *LargeList) setData(data *Data) {
+       a.array.setData(data)
+       vals := data.buffers[1]
+       if vals != nil {
+               a.offsets = arrow.Int64Traits.CastFromBytes(vals.Bytes())
+       }
+       a.values = MakeFromData(data.childData[0])
+}
+
+func (a *LargeList) getOneForMarshal(i int) interface{} {
+       if a.IsNull(i) {
+               return nil
+       }
+
+       slice := a.newListValue(i)
+       defer slice.Release()
+       v, err := json.Marshal(slice)
+       if err != nil {
+               panic(err)
+       }
+       return json.RawMessage(v)
+}
+
+func (a *LargeList) MarshalJSON() ([]byte, error) {
+       var buf bytes.Buffer
+       enc := json.NewEncoder(&buf)
+
+       buf.WriteByte('[')
+       for i := 0; i < a.Len(); i++ {
+               if i != 0 {
+                       buf.WriteByte(',')
+               }
+               if err := enc.Encode(a.getOneForMarshal(i)); err != nil {
+                       return nil, err
+               }
+       }
+       buf.WriteByte(']')
+       return buf.Bytes(), nil
+}
+
+func arrayEqualLargeList(left, right *LargeList) bool {
+       for i := 0; i < left.Len(); i++ {
+               if left.IsNull(i) {
+                       continue
+               }
+               o := func() bool {
+                       l := left.newListValue(i)
+                       defer l.Release()
+                       r := right.newListValue(i)
+                       defer r.Release()
+                       return Equal(l, r)
+               }()
+               if !o {
+                       return false
+               }
+       }
+       return true
+}
+
+// Len returns the number of elements in the array.
+func (a *LargeList) Len() int { return a.array.Len() }
+
+func (a *LargeList) Offsets() []int64 { return a.offsets }
+
+func (a *LargeList) Retain() {
+       a.array.Retain()
+       a.values.Retain()
+}
+
+func (a *LargeList) Release() {
+       a.array.Release()
+       a.values.Release()
+}
+
+type listBuilder struct {
        builder
 
        etype   arrow.DataType // data type of the list's elements.
        values  Builder        // value builder for the list's elements.
-       offsets *Int32Builder
+       offsets Builder
+
+       dt              arrow.DataType

Review Comment:
   `dt` is the actual List Type, there's a separate `etype` member which is the 
`element` type of the list. 
   
   The offset type (int32 vs int64) doesn't need to matter for the base 
`listbuilder` object and is hidden behind the `Builder` interface, casted when 
necessary to either an `Int32Builder` or `Int64Builder` as appropriate. I'll 
add a comment.



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