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

zeroshade 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 1ddd644  ARROW-14645: [Go] Add ValueOffsets function to array.String
1ddd644 is described below

commit 1ddd644210888a0996754d5f5d517699dcf6c446
Author: Matthew Topol <[email protected]>
AuthorDate: Tue Nov 9 16:58:10 2021 -0500

    ARROW-14645: [Go] Add ValueOffsets function to array.String
    
    Closes #11653 from zeroshade/arrow-14645-valueoffsets
    
    Authored-by: Matthew Topol <[email protected]>
    Signed-off-by: Matthew Topol <[email protected]>
---
 go/arrow/array/string.go      |  6 ++++++
 go/arrow/array/string_test.go | 17 +++++++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/go/arrow/array/string.go b/go/arrow/array/string.go
index c8e16ce..f7e6afc 100644
--- a/go/arrow/array/string.go
+++ b/go/arrow/array/string.go
@@ -65,6 +65,12 @@ func (a *String) ValueOffset(i int) int {
        return int(a.offsets[i+a.array.data.offset])
 }
 
+func (a *String) ValueOffsets() []int32 {
+       beg := a.array.data.offset
+       end := beg + a.array.data.length + 1
+       return a.offsets[beg:end]
+}
+
 func (a *String) ValueBytes() (ret []byte) {
        beg := a.array.data.offset
        end := beg + a.array.data.length
diff --git a/go/arrow/array/string_test.go b/go/arrow/array/string_test.go
index 549fe99..f71eb37 100644
--- a/go/arrow/array/string_test.go
+++ b/go/arrow/array/string_test.go
@@ -18,6 +18,7 @@ package array_test
 
 import (
        "bytes"
+       "reflect"
        "testing"
 
        "github.com/apache/arrow/go/arrow"
@@ -33,7 +34,7 @@ func TestStringArray(t *testing.T) {
        var (
                want    = []string{"hello", "世界", "", "bye"}
                valids  = []bool{true, true, false, true}
-               offsets = []int{0, 5, 11, 11, 14}
+               offsets = []int32{0, 5, 11, 11, 14}
        )
 
        sb := array.NewStringBuilder(mem)
@@ -82,14 +83,18 @@ func TestStringArray(t *testing.T) {
                        }
                }
 
-               if got, want := arr.ValueOffset(i), offsets[i]; got != want {
+               if got, want := arr.ValueOffset(i), int(offsets[i]); got != 
want {
                        t.Fatalf("arr-offset-beg[%d]: got=%d, want=%d", i, got, 
want)
                }
-               if got, want := arr.ValueOffset(i+1), offsets[i+1]; got != want 
{
+               if got, want := arr.ValueOffset(i+1), int(offsets[i+1]); got != 
want {
                        t.Fatalf("arr-offset-end[%d]: got=%d, want=%d", i+1, 
got, want)
                }
        }
 
+       if !reflect.DeepEqual(offsets, arr.ValueOffsets()) {
+               t.Fatalf("ValueOffsets got=%v, want=%v", arr.ValueOffsets(), 
offsets)
+       }
+
        sub := array.MakeFromData(arr.Data())
        defer sub.Release()
 
@@ -129,10 +134,14 @@ func TestStringArray(t *testing.T) {
        }
 
        for i := 0; i < v.Len(); i++ {
-               if got, want := v.ValueOffset(0), offsets[i+slice.Offset()]; 
got != want {
+               if got, want := v.ValueOffset(0), 
int(offsets[i+slice.Offset()]); got != want {
                        t.Fatalf("val-offset-with-offset[%d]: got=%q, want=%q", 
i, got, want)
                }
        }
+
+       if !reflect.DeepEqual(offsets[2:5], v.ValueOffsets()) {
+               t.Fatalf("ValueOffsets got=%v, want=%v", v.ValueOffsets(), 
offsets[2:5])
+       }
 }
 
 func TestStringBuilder_Empty(t *testing.T) {

Reply via email to