memory.go 874 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/apache/arrow/go/arrow/array"
  5. "github.com/apache/arrow/go/arrow/memory"
  6. )
  7. func main() {
  8. // create LSB packed bits with the following pattern:
  9. // 01010011 11000101
  10. data := memory.NewBufferBytes([]byte{0xca, 0xa3})
  11. // create LSB packed validity (null) bitmap, where every 4th element is null:
  12. // 11101110 11101110
  13. nullBitmap := memory.NewBufferBytes([]byte{0x77, 0x77})
  14. // Create a boolean array and lazily determine NullN using UnknownNullCount
  15. bools := array.NewBoolean(16, data, nullBitmap, array.UnknownNullCount)
  16. defer bools.Release()
  17. // Show the null count
  18. fmt.Printf("NullN() = %d\n", bools.NullN())
  19. // Enumerate the values.
  20. n := bools.Len()
  21. for i := 0; i < n; i++ {
  22. fmt.Printf("bools[%d] = ", i)
  23. if bools.IsNull(i) {
  24. fmt.Println("(null)")
  25. } else {
  26. fmt.Printf("%t\n", bools.Value(i))
  27. }
  28. }
  29. }