This is an automated email from the ASF dual-hosted git repository.

sbinet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new ae57178  ARROW-4973: [Go] implement ArraySliceEqual
ae57178 is described below

commit ae571787a744c208ded0f4cf42e0c756a73fbaa0
Author: Sebastien Binet <bi...@cern.ch>
AuthorDate: Thu Jun 13 21:52:54 2019 +0200

    ARROW-4973: [Go] implement ArraySliceEqual
    
    Author: Sebastien Binet <bi...@cern.ch>
    
    Closes #4549 from sbinet/issue-4973 and squashes the following commits:
    
    972ea19bd <Sebastien Binet> ARROW-4973:  implement ArraySliceEqual
---
 go/arrow/array/compare.go      | 10 ++++++++++
 go/arrow/array/compare_test.go | 29 +++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/go/arrow/array/compare.go b/go/arrow/array/compare.go
index 570e9a4..60e21fb 100644
--- a/go/arrow/array/compare.go
+++ b/go/arrow/array/compare.go
@@ -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():
diff --git a/go/arrow/array/compare_test.go b/go/arrow/array/compare_test.go
index 012611f..33a5c92 100644
--- a/go/arrow/array/compare_test.go
+++ b/go/arrow/array/compare_test.go
@@ -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)

Reply via email to