| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package main
- import (
- "fmt"
- "github.com/apache/arrow/go/arrow"
- "github.com/apache/arrow/go/arrow/array"
- "github.com/apache/arrow/go/arrow/memory"
- )
- func main() {
- pool := memory.NewGoAllocator()
- lb := array.NewListBuilder(pool, arrow.PrimitiveTypes.Int64)
- defer lb.Release()
- vb := lb.ValueBuilder().(*array.Int64Builder)
- defer vb.Release()
- vb.Reserve(10)
- lb.Append(true)
- vb.Append(0)
- vb.Append(1)
- vb.Append(2)
- lb.AppendNull()
- lb.Append(true)
- vb.Append(3)
- lb.Append(true)
- vb.Append(4)
- vb.Append(5)
- lb.Append(true)
- vb.Append(6)
- vb.Append(7)
- vb.Append(8)
- lb.AppendNull()
- lb.Append(true)
- vb.Append(9)
- arr := lb.NewArray().(*array.List)
- defer arr.Release()
- fmt.Printf("NullN() = %d\n", arr.NullN())
- fmt.Printf("Len() = %d\n", arr.Len())
- fmt.Printf("Offsets() = %v\n", arr.Offsets())
- offsets := arr.Offsets()[1:]
- varr := arr.ListValues().(*array.Int64)
- pos := 0
- for i := 0; i < arr.Len(); i++ {
- if !arr.IsValid(i) {
- fmt.Printf("List[%d] = (null)\n", i)
- continue
- }
- fmt.Printf("List[%d] = [", i)
- for j := pos; j < int(offsets[i]); j++ {
- if j != pos {
- fmt.Printf(", ")
- }
- fmt.Printf("%v", varr.Value(j))
- }
- pos = int(offsets[i])
- fmt.Printf("]\n")
- }
- fmt.Printf("List = %v\n", arr)
- }
|