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

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


The following commit(s) were added to refs/heads/main by this push:
     new 213cadbbc0 GH-38458: [Go] Add ValueLen to BinaryLike interface (#39242)
213cadbbc0 is described below

commit 213cadbbc080399b372291f93aaaa05fe0e67de1
Author: Matt Topol <[email protected]>
AuthorDate: Wed Jan 3 11:29:15 2024 -0500

    GH-38458: [Go] Add ValueLen to BinaryLike interface (#39242)
    
    
    
    ### Rationale for this change
    Adding `ValueLen` to the `BinaryLike` interface for easy convenience of 
determining the length of an individual value for a Binary/String like array.
    
    ### Are these changes tested?
    yes
    
    * Closes: #38458
    
    Authored-by: Matt Topol <[email protected]>
    Signed-off-by: Matt Topol <[email protected]>
---
 go/arrow/array/binary.go |  9 +++++++++
 go/arrow/array/string.go | 17 +++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/go/arrow/array/binary.go b/go/arrow/array/binary.go
index c226297da0..9e26de7a6d 100644
--- a/go/arrow/array/binary.go
+++ b/go/arrow/array/binary.go
@@ -30,6 +30,7 @@ import (
 
 type BinaryLike interface {
        arrow.Array
+       ValueLen(int) int
        ValueBytes() []byte
        ValueOffset64(int) int64
 }
@@ -367,6 +368,11 @@ func (a *BinaryView) Value(i int) []byte {
        return buf.Bytes()[start : start+int32(s.Len())]
 }
 
+func (a *BinaryView) ValueLen(i int) int {
+       s := a.ValueHeader(i)
+       return s.Len()
+}
+
 // ValueString returns the value at index i as a string instead of
 // a byte slice, without copying the underlying data.
 func (a *BinaryView) ValueString(i int) string {
@@ -441,4 +447,7 @@ var (
        _ arrow.Array = (*Binary)(nil)
        _ arrow.Array = (*LargeBinary)(nil)
        _ arrow.Array = (*BinaryView)(nil)
+
+       _ BinaryLike = (*Binary)(nil)
+       _ BinaryLike = (*LargeBinary)(nil)
 )
diff --git a/go/arrow/array/string.go b/go/arrow/array/string.go
index 90a4628f0d..c8517ba305 100644
--- a/go/arrow/array/string.go
+++ b/go/arrow/array/string.go
@@ -31,6 +31,7 @@ import (
 type StringLike interface {
        arrow.Array
        Value(int) string
+       ValueLen(int) int
 }
 
 // String represents an immutable sequence of variable-length UTF-8 strings.
@@ -225,6 +226,14 @@ func (a *LargeString) ValueOffset64(i int) int64 {
        return a.ValueOffset(i)
 }
 
+func (a *LargeString) ValueLen(i int) int {
+       if i < 0 || i >= a.array.data.length {
+               panic("arrow/array: index out of range")
+       }
+       beg := a.array.data.offset + i
+       return int(a.offsets[beg+1] - a.offsets[beg])
+}
+
 func (a *LargeString) ValueOffsets() []int64 {
        beg := a.array.data.offset
        end := beg + a.array.data.length + 1
@@ -364,6 +373,11 @@ func (a *StringView) Value(i int) string {
        return *(*string)(unsafe.Pointer(&value))
 }
 
+func (a *StringView) ValueLen(i int) int {
+       s := a.ValueHeader(i)
+       return s.Len()
+}
+
 func (a *StringView) String() string {
        var o strings.Builder
        o.WriteString("[")
@@ -698,4 +712,7 @@ var (
        _ StringLikeBuilder = (*StringBuilder)(nil)
        _ StringLikeBuilder = (*LargeStringBuilder)(nil)
        _ StringLikeBuilder = (*StringViewBuilder)(nil)
+       _ StringLike        = (*String)(nil)
+       _ StringLike        = (*LargeString)(nil)
+       _ StringLike        = (*StringView)(nil)
 )

Reply via email to