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 66bebe4  ARROW-5314: [Go] Fix bug for FixedSizeBinary with offset
66bebe4 is described below

commit 66bebe4a71f21cb1acacd313aa0da9dbd09e3bb5
Author: alexandreyc <alexandre.crays...@gmail.com>
AuthorDate: Fri May 17 17:45:17 2019 +0200

    ARROW-5314: [Go] Fix bug for FixedSizeBinary with offset
    
    Same thing as #4307 but for `FixedSizeBinary`
    
    Author: alexandreyc <alexandre.crays...@gmail.com>
    
    Closes #4334 from alexandreyc/master and squashes the following commits:
    
    c9e84771 <alexandreyc> Fix bug for FixedSizeBinary with offset
---
 go/arrow/array/fixedsize_binary.go      |  1 +
 go/arrow/array/fixedsize_binary_test.go | 48 ++++++++++++++++++++++++++++++---
 2 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/go/arrow/array/fixedsize_binary.go 
b/go/arrow/array/fixedsize_binary.go
index 78925bc..db24a86 100644
--- a/go/arrow/array/fixedsize_binary.go
+++ b/go/arrow/array/fixedsize_binary.go
@@ -40,6 +40,7 @@ func NewFixedSizeBinaryData(data *Data) *FixedSizeBinary {
 
 // Value returns the fixed-size slice at index i. This value should not be 
mutated.
 func (a *FixedSizeBinary) Value(i int) []byte {
+       i += a.array.data.offset
        return a.valueBytes[a.valueOffsets[i]:a.valueOffsets[i+1]]
 }
 
diff --git a/go/arrow/array/fixedsize_binary_test.go 
b/go/arrow/array/fixedsize_binary_test.go
index b7f3d3f..fdb0fbf 100644
--- a/go/arrow/array/fixedsize_binary_test.go
+++ b/go/arrow/array/fixedsize_binary_test.go
@@ -14,7 +14,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package array
+package array_test
 
 import (
        "testing"
@@ -22,6 +22,7 @@ import (
        "github.com/stretchr/testify/assert"
 
        "github.com/apache/arrow/go/arrow"
+       "github.com/apache/arrow/go/arrow/array"
        "github.com/apache/arrow/go/arrow/memory"
 )
 
@@ -30,7 +31,7 @@ func TestFixedSizeBinary(t *testing.T) {
        defer mem.AssertSize(t, 0)
 
        dtype := arrow.FixedSizeBinaryType{ByteWidth: 7}
-       b := NewFixedSizeBinaryBuilder(mem, &dtype)
+       b := array.NewFixedSizeBinaryBuilder(mem, &dtype)
 
        values := [][]byte{
                []byte("7654321"),
@@ -53,7 +54,7 @@ func TestFixedSizeBinary(t *testing.T) {
 
        // Test builder reset and NewArray API.
        b.AppendValues(values, valid)
-       a = b.NewArray().(*FixedSizeBinary)
+       a = b.NewArray().(*array.FixedSizeBinary)
        assert.Equal(t, 3, a.Len())
        assert.Equal(t, 1, a.NullN())
        assert.Equal(t, []byte("7654321"), a.Value(0))
@@ -63,3 +64,44 @@ func TestFixedSizeBinary(t *testing.T) {
 
        b.Release()
 }
+
+func TestFixedSizeBinarySlice(t *testing.T) {
+       mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
+       defer mem.AssertSize(t, 0)
+
+       dtype := &arrow.FixedSizeBinaryType{ByteWidth: 4}
+       b := array.NewFixedSizeBinaryBuilder(mem, dtype)
+       defer b.Release()
+
+       var data = [][]byte{
+               []byte("ABCD"),
+               []byte("1234"),
+               nil,
+               []byte("AZER"),
+       }
+       b.AppendValues(data[:2], nil)
+       b.AppendNull()
+       b.Append(data[3])
+
+       arr := b.NewFixedSizeBinaryArray()
+       defer arr.Release()
+
+       slice := array.NewSliceData(arr.Data(), 2, 4)
+       defer slice.Release()
+
+       sub1 := array.MakeFromData(slice)
+       defer sub1.Release()
+
+       v, ok := sub1.(*array.FixedSizeBinary)
+       if !ok {
+               t.Fatalf("could not type-assert to array.String")
+       }
+
+       if got, want := v.String(), `[(null) "AZER"]`; got != want {
+               t.Fatalf("got=%q, want=%q", got, want)
+       }
+
+       if got, want := v.NullN(), 1; got != want {
+               t.Fatalf("got=%q, want=%q", got, want)
+       }
+}

Reply via email to