Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go/arrow/array/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ func init() {
arrow.STRING: func(data *Data) Interface { return NewStringData(data) },
arrow.BINARY: func(data *Data) Interface { return NewBinaryData(data) },
arrow.FIXED_SIZE_BINARY: func(data *Data) Interface { return NewFixedSizeBinaryData(data) },
arrow.DATE32: unsupportedArrayType,
arrow.DATE64: unsupportedArrayType,
arrow.DATE32: func(data *Data) Interface { return NewDate32Data(data) },
arrow.DATE64: func(data *Data) Interface { return NewDate64Data(data) },
arrow.TIMESTAMP: func(data *Data) Interface { return NewTimestampData(data) },
arrow.TIME32: func(data *Data) Interface { return NewTime32Data(data) },
arrow.TIME64: func(data *Data) Interface { return NewTime64Data(data) },
Expand Down
90 changes: 90 additions & 0 deletions go/arrow/array/numeric.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

220 changes: 220 additions & 0 deletions go/arrow/array/numeric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,223 @@ func TestTime64SliceDataWithNull(t *testing.T) {
t.Fatalf("got=%v, want=%v", got, want)
}
}

func TestNewDate32Data(t *testing.T) {
exp := []arrow.Date32{1, 2, 4, 8, 16}

dtype := &arrow.Date32Type{}
ad := array.NewData(
dtype, len(exp),
[]*memory.Buffer{nil, memory.NewBufferBytes(arrow.Date32Traits.CastToBytes(exp))},
nil, 0, 0,
)
fa := array.NewDate32Data(ad)

assert.Equal(t, len(exp), fa.Len(), "unexpected Len()")
assert.Equal(t, exp, fa.Date32Values(), "unexpected Date32Values()")
}

func TestDate32SliceData(t *testing.T) {
pool := memory.NewCheckedAllocator(memory.NewGoAllocator())
defer pool.AssertSize(t, 0)

const (
beg = 2
end = 4
)

var (
vs = []arrow.Date32{1, 2, 3, 4, 5}
sub = vs[beg:end]
)

b := array.NewDate32Builder(pool)
defer b.Release()

for _, v := range vs {
b.Append(v)
}

arr := b.NewArray().(*array.Date32)
defer arr.Release()

if got, want := arr.Len(), len(vs); got != want {
t.Fatalf("got=%d, want=%d", got, want)
}

if got, want := arr.Date32Values(), vs; !reflect.DeepEqual(got, want) {
t.Fatalf("got=%v, want=%v", got, want)
}

slice := array.NewSlice(arr, beg, end).(*array.Date32)
defer slice.Release()

if got, want := slice.Len(), len(sub); got != want {
t.Fatalf("got=%d, want=%d", got, want)
}

if got, want := slice.Date32Values(), sub; !reflect.DeepEqual(got, want) {
t.Fatalf("got=%v, want=%v", got, want)
}
}

func TestDate32SliceDataWithNull(t *testing.T) {
pool := memory.NewCheckedAllocator(memory.NewGoAllocator())
defer pool.AssertSize(t, 0)

const (
beg = 2
end = 5
)

var (
valids = []bool{true, true, true, false, true, true}
vs = []arrow.Date32{1, 2, 3, 0, 4, 5}
sub = vs[beg:end]
)

b := array.NewDate32Builder(pool)
defer b.Release()

b.AppendValues(vs, valids)

arr := b.NewArray().(*array.Date32)
defer arr.Release()

if got, want := arr.Len(), len(valids); got != want {
t.Fatalf("got=%d, want=%d", got, want)
}

if got, want := arr.NullN(), 1; got != want {
t.Fatalf("got=%d, want=%d", got, want)
}

if got, want := arr.Date32Values(), vs; !reflect.DeepEqual(got, want) {
t.Fatalf("got=%v, want=%v", got, want)
}

slice := array.NewSlice(arr, beg, end).(*array.Date32)
defer slice.Release()

if got, want := slice.NullN(), 1; got != want {
t.Errorf("got=%d, want=%d", got, want)
}

if got, want := slice.Len(), len(sub); got != want {
t.Fatalf("got=%d, want=%d", got, want)
}

if got, want := slice.Date32Values(), sub; !reflect.DeepEqual(got, want) {
t.Fatalf("got=%v, want=%v", got, want)
}
}

func TestNewDate64Data(t *testing.T) {
exp := []arrow.Date64{1, 2, 4, 8, 16}

dtype := &arrow.Date64Type{}
ad := array.NewData(
dtype, len(exp),
[]*memory.Buffer{nil, memory.NewBufferBytes(arrow.Date64Traits.CastToBytes(exp))},
nil, 0, 0,
)
fa := array.NewDate64Data(ad)

assert.Equal(t, len(exp), fa.Len(), "unexpected Len()")
assert.Equal(t, exp, fa.Date64Values(), "unexpected Date64Values()")
}

func TestDate64SliceData(t *testing.T) {
pool := memory.NewCheckedAllocator(memory.NewGoAllocator())
defer pool.AssertSize(t, 0)

const (
beg = 2
end = 4
)

var (
vs = []arrow.Date64{1, 2, 3, 4, 5}
sub = vs[beg:end]
)

b := array.NewDate64Builder(pool)
defer b.Release()

for _, v := range vs {
b.Append(v)
}

arr := b.NewArray().(*array.Date64)
defer arr.Release()

if got, want := arr.Len(), len(vs); got != want {
t.Fatalf("got=%d, want=%d", got, want)
}

if got, want := arr.Date64Values(), vs; !reflect.DeepEqual(got, want) {
t.Fatalf("got=%v, want=%v", got, want)
}

slice := array.NewSlice(arr, beg, end).(*array.Date64)
defer slice.Release()

if got, want := slice.Len(), len(sub); got != want {
t.Fatalf("got=%d, want=%d", got, want)
}

if got, want := slice.Date64Values(), sub; !reflect.DeepEqual(got, want) {
t.Fatalf("got=%v, want=%v", got, want)
}
}

func TestDate64SliceDataWithNull(t *testing.T) {
pool := memory.NewCheckedAllocator(memory.NewGoAllocator())
defer pool.AssertSize(t, 0)

const (
beg = 2
end = 5
)

var (
valids = []bool{true, true, true, false, true, true}
vs = []arrow.Date64{1, 2, 3, 0, 4, 5}
sub = vs[beg:end]
)

b := array.NewDate64Builder(pool)
defer b.Release()

b.AppendValues(vs, valids)

arr := b.NewArray().(*array.Date64)
defer arr.Release()

if got, want := arr.Len(), len(valids); got != want {
t.Fatalf("got=%d, want=%d", got, want)
}

if got, want := arr.NullN(), 1; got != want {
t.Fatalf("got=%d, want=%d", got, want)
}

if got, want := arr.Date64Values(), vs; !reflect.DeepEqual(got, want) {
t.Fatalf("got=%v, want=%v", got, want)
}

slice := array.NewSlice(arr, beg, end).(*array.Date64)
defer slice.Release()

if got, want := slice.NullN(), 1; got != want {
t.Errorf("got=%d, want=%d", got, want)
}

if got, want := slice.Len(), len(sub); got != want {
t.Fatalf("got=%d, want=%d", got, want)
}

if got, want := slice.Date64Values(), sub; !reflect.DeepEqual(got, want) {
t.Fatalf("got=%v, want=%v", got, want)
}
}
Loading