Skip to content

Commit

Permalink
ARROW-4973: [Go] implement ArraySliceEqual
Browse files Browse the repository at this point in the history
Author: Sebastien Binet <[email protected]>

Closes apache#4549 from sbinet/issue-4973 and squashes the following commits:

972ea19 <Sebastien Binet> ARROW-4973:  implement ArraySliceEqual
  • Loading branch information
sbinet committed Jun 13, 2019
1 parent f068424 commit ae57178
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions go/arrow/array/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ func ArrayEqual(left, right Interface) bool {
}
}

// ArraySliceEqual reports whether slices left[lbeg:lend] and right[rbeg:rend] are equal.
func ArraySliceEqual(left Interface, lbeg, lend int64, right Interface, rbeg, rend int64) bool {
l := NewSlice(left, lbeg, lend)
defer l.Release()
r := NewSlice(right, rbeg, rend)
defer r.Release()

return ArrayEqual(l, r)
}

func baseArrayEqual(left, right Interface) bool {
switch {
case left.Len() != right.Len():
Expand Down
29 changes: 29 additions & 0 deletions go/arrow/array/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@ func TestArrayEqual(t *testing.T) {
}
}

func TestArraySliceEqual(t *testing.T) {
for name, recs := range arrdata.Records {
t.Run(name, func(t *testing.T) {
rec := recs[0]
schema := rec.Schema()
for i, col := range rec.Columns() {
t.Run(schema.Field(i).Name, func(t *testing.T) {
arr := col
if !array.ArraySliceEqual(
arr, 0, int64(arr.Len()),
arr, 0, int64(arr.Len()),
) {
t.Fatalf("identical slices should compare equal:\narray=%v", arr)
}
sub1 := array.NewSlice(arr, 1, int64(arr.Len()))
defer sub1.Release()

sub2 := array.NewSlice(arr, 0, int64(arr.Len()-1))
defer sub2.Release()

if array.ArraySliceEqual(sub1, 0, int64(sub1.Len()), sub2, 0, int64(sub2.Len())) {
t.Fatalf("non-identical slices should not compare equal:\nsub1=%v\nsub2=%v\narrf=%v\n", sub1, sub2, arr)
}
})
}
})
}
}

func TestArrayEqualBaseArray(t *testing.T) {
mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
defer mem.AssertSize(t, 0)
Expand Down

0 comments on commit ae57178

Please sign in to comment.