github.com/apache/arrow/go/v16@v16.1.0/arrow/array/null_test.go (about) 1 // Licensed to the Apache Software Foundation (ASF) under one 2 // or more contributor license agreements. See the NOTICE file 3 // distributed with this work for additional information 4 // regarding copyright ownership. The ASF licenses this file 5 // to you under the Apache License, Version 2.0 (the 6 // "License"); you may not use this file except in compliance 7 // with the License. You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 package array_test 18 19 import ( 20 "testing" 21 22 "github.com/apache/arrow/go/v16/arrow" 23 "github.com/apache/arrow/go/v16/arrow/array" 24 "github.com/apache/arrow/go/v16/arrow/memory" 25 "github.com/stretchr/testify/assert" 26 ) 27 28 func TestNullArray(t *testing.T) { 29 pool := memory.NewCheckedAllocator(memory.NewGoAllocator()) 30 defer pool.AssertSize(t, 0) 31 32 b := array.NewNullBuilder(pool) 33 defer b.Release() 34 35 b.AppendNull() 36 b.AppendNulls(2) 37 b.AppendEmptyValue() 38 b.AppendEmptyValues(2) 39 40 arr1 := b.NewArray().(*array.Null) 41 defer arr1.Release() 42 43 if got, want := arr1.Len(), 6; got != want { 44 t.Fatalf("invalid null array length: got=%d, want=%d", got, want) 45 } 46 47 if got, want := arr1.NullN(), 6; got != want { 48 t.Fatalf("invalid number of nulls: got=%d, want=%d", got, want) 49 } 50 51 if got, want := arr1.DataType(), arrow.Null; got != want { 52 t.Fatalf("invalid null data type: got=%v, want=%v", got, want) 53 } 54 55 arr1.Retain() 56 arr1.Release() 57 58 if arr1.Data() == nil { 59 t.Fatalf("invalid null data") 60 } 61 62 arr2 := b.NewNullArray() 63 defer arr2.Release() 64 65 if got, want := arr2.Len(), 0; got != want { 66 t.Fatalf("invalid null array length: got=%d, want=%d", got, want) 67 } 68 69 arr3 := array.NewNull(10) 70 defer arr3.Release() 71 72 if got, want := arr3.Len(), 10; got != want { 73 t.Fatalf("invalid null array length: got=%d, want=%d", got, want) 74 } 75 76 if got, want := arr3.NullN(), 10; got != want { 77 t.Fatalf("invalid number of nulls: got=%d, want=%d", got, want) 78 } 79 80 } 81 82 func TestNullStringRoundTrip(t *testing.T) { 83 // 1. create array 84 mem := memory.NewCheckedAllocator(memory.NewGoAllocator()) 85 defer mem.AssertSize(t, 0) 86 87 b := array.NewNullBuilder(mem) 88 defer b.Release() 89 90 b.AppendNull() 91 b.AppendNulls(2) 92 b.AppendEmptyValue() 93 b.AppendEmptyValues(2) 94 95 arr := b.NewArray().(*array.Null) 96 defer arr.Release() 97 98 // 2. create array via AppendValueFromString 99 b1 := array.NewNullBuilder(mem) 100 defer b1.Release() 101 102 for i := 0; i < arr.Len(); i++ { 103 assert.NoError(t, b1.AppendValueFromString(arr.ValueStr(i))) 104 } 105 106 arr1 := b1.NewArray().(*array.Null) 107 defer arr1.Release() 108 109 assert.True(t, array.Equal(arr, arr1)) 110 }