You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by sb...@apache.org on 2019/05/31 07:21:12 UTC
[arrow] branch master updated: ARROW-5387: [Go] properly handle
sub-slice of List
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 17e85bf ARROW-5387: [Go] properly handle sub-slice of List
17e85bf is described below
commit 17e85bf63a29129fadeb8939cdcd18c8935dd0da
Author: Sebastien Binet <bi...@cern.ch>
AuthorDate: Fri May 31 09:20:52 2019 +0200
ARROW-5387: [Go] properly handle sub-slice of List
Author: Sebastien Binet <bi...@cern.ch>
Closes #4360 from sbinet/issue-5387 and squashes the following commits:
bbc8a837 <Sebastien Binet> ARROW-5387: properly handle sub-slice of List
---
go/arrow/array/list.go | 5 ++--
go/arrow/array/list_test.go | 62 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+), 2 deletions(-)
diff --git a/go/arrow/array/list.go b/go/arrow/array/list.go
index 9b74641..1b91176 100644
--- a/go/arrow/array/list.go
+++ b/go/arrow/array/list.go
@@ -55,8 +55,9 @@ func (a *List) String() string {
o.WriteString("(null)")
continue
}
- beg := int64(a.offsets[i])
- end := int64(a.offsets[i+1])
+ j := i + a.array.data.offset
+ beg := int64(a.offsets[j])
+ end := int64(a.offsets[j+1])
sub := NewSlice(a.values, beg, end)
fmt.Fprintf(o, "%v", sub)
sub.Release()
diff --git a/go/arrow/array/list_test.go b/go/arrow/array/list_test.go
index 0853776..b328cf4 100644
--- a/go/arrow/array/list_test.go
+++ b/go/arrow/array/list_test.go
@@ -149,3 +149,65 @@ func TestListArrayBulkAppend(t *testing.T) {
t.Fatalf("got=%v, want=%v", got, want)
}
}
+
+func TestListArraySlice(t *testing.T) {
+ pool := memory.NewCheckedAllocator(memory.NewGoAllocator())
+ defer pool.AssertSize(t, 0)
+
+ var (
+ vs = []int32{0, 1, 2, 3, 4, 5, 6}
+ lengths = []int{3, 0, 4}
+ isValid = []bool{true, false, true}
+ offsets = []int32{0, 3, 3, 7}
+ )
+
+ lb := array.NewListBuilder(pool, arrow.PrimitiveTypes.Int32)
+ defer lb.Release()
+ vb := lb.ValueBuilder().(*array.Int32Builder)
+ vb.Reserve(len(vs))
+
+ lb.AppendValues(offsets, isValid)
+ for _, v := range vs {
+ vb.Append(v)
+ }
+
+ arr := lb.NewArray().(*array.List)
+ defer arr.Release()
+
+ if got, want := arr.DataType().ID(), arrow.LIST; got != want {
+ t.Fatalf("got=%v, want=%v", got, want)
+ }
+
+ if got, want := arr.Len(), len(isValid); got != want {
+ t.Fatalf("got=%d, want=%d", got, want)
+ }
+
+ for i := range lengths {
+ if got, want := arr.IsValid(i), isValid[i]; got != want {
+ t.Fatalf("got[%d]=%v, want[%d]=%v", i, got, i, want)
+ }
+ if got, want := arr.IsNull(i), lengths[i] == 0; got != want {
+ t.Fatalf("got[%d]=%v, want[%d]=%v", i, got, i, want)
+ }
+ }
+
+ if got, want := arr.Offsets(), offsets; !reflect.DeepEqual(got, want) {
+ t.Fatalf("got=%v, want=%v", got, want)
+ }
+
+ varr := arr.ListValues().(*array.Int32)
+ if got, want := varr.Int32Values(), vs; !reflect.DeepEqual(got, want) {
+ t.Fatalf("got=%v, want=%v", got, want)
+ }
+
+ if got, want := arr.String(), `[[0 1 2] (null) [3 4 5 6]]`; got != want {
+ t.Fatalf("got=%q, want=%q", got, want)
+ }
+
+ sub := array.NewSlice(arr, 1, 3).(*array.List)
+ defer sub.Release()
+
+ if got, want := sub.String(), `[(null) [3 4 5 6]]`; got != want {
+ t.Fatalf("got=%q, want=%q", got, want)
+ }
+}