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 28c68128ba GH-35326: [Go] Fix `*array.List` and `*array.LargeList`
`ValueOffsets` implementation (#35327)
28c68128ba is described below
commit 28c68128ba7fb9702ce9f02529f3d1de61ffeac1
Author: candiduslynx <[email protected]>
AuthorDate: Tue Apr 25 18:31:31 2023 +0300
GH-35326: [Go] Fix `*array.List` and `*array.LargeList` `ValueOffsets`
implementation (#35327)
This fix also is connected to #35325 (as adds `*array.FixedSizeList` to the
same bunch).
### Rationale for this change
### What changes are included in this PR?
### Are these changes tested?
### Are there any user-facing changes?
* Closes: #35326
* Closes: #35325
Authored-by: candiduslynx <[email protected]>
Signed-off-by: Matt Topol <[email protected]>
---
go/arrow/array/fixed_size_list.go | 18 +++++++++++-------
go/arrow/array/list.go | 18 ++++++++++--------
go/arrow/array/map.go | 4 +++-
go/arrow/cdata/cdata_exports.go | 7 -------
4 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/go/arrow/array/fixed_size_list.go
b/go/arrow/array/fixed_size_list.go
index c0c8676cd9..a2c0b38d65 100644
--- a/go/arrow/array/fixed_size_list.go
+++ b/go/arrow/array/fixed_size_list.go
@@ -36,6 +36,8 @@ type FixedSizeList struct {
values arrow.Array
}
+var _ ListLike = (*FixedSizeList)(nil)
+
// NewFixedSizeListData returns a new List array value, from data.
func NewFixedSizeListData(data arrow.ArrayData) *FixedSizeList {
a := &FixedSizeList{}
@@ -72,12 +74,8 @@ func (a *FixedSizeList) String() string {
}
func (a *FixedSizeList) newListValue(i int) arrow.Array {
- n := int64(a.n)
- off := int64(a.array.data.offset)
- beg := (off + int64(i)) * n
- end := (off + int64(i+1)) * n
- sli := NewSlice(a.values, beg, end)
- return sli
+ beg, end := a.ValueOffsets(i)
+ return NewSlice(a.values, beg, end)
}
func (a *FixedSizeList) setData(data *Data) {
@@ -108,6 +106,13 @@ func arrayEqualFixedSizeList(left, right *FixedSizeList)
bool {
// Len returns the number of elements in the array.
func (a *FixedSizeList) Len() int { return a.array.Len() }
+func (a *FixedSizeList) ValueOffsets(i int) (start, end int64) {
+ n := int64(a.n)
+ off := int64(a.array.data.offset)
+ start, end = (off+int64(i))*n, (off+int64(i+1))*n
+ return
+}
+
func (a *FixedSizeList) Retain() {
a.array.Retain()
a.values.Retain()
@@ -284,7 +289,6 @@ func (b *FixedSizeListBuilder) newData() (data *Data) {
return
}
-
func (b *FixedSizeListBuilder) AppendValueFromString(s string) error {
dec := json.NewDecoder(strings.NewReader(s))
return b.UnmarshalOne(dec)
diff --git a/go/arrow/array/list.go b/go/arrow/array/list.go
index 374ed28189..e44dfc248a 100644
--- a/go/arrow/array/list.go
+++ b/go/arrow/array/list.go
@@ -42,6 +42,8 @@ type List struct {
offsets []int32
}
+var _ ListLike = (*List)(nil)
+
// NewListData returns a new List array value, from data.
func NewListData(data arrow.ArrayData) *List {
a := &List{}
@@ -79,9 +81,7 @@ func (a *List) String() string {
}
func (a *List) newListValue(i int) arrow.Array {
- j := i + a.array.data.offset
- beg := int64(a.offsets[j])
- end := int64(a.offsets[j+1])
+ beg, end := a.ValueOffsets(i)
return NewSlice(a.values, beg, end)
}
@@ -161,7 +161,8 @@ func (a *List) Release() {
func (a *List) ValueOffsets(i int) (start, end int64) {
debug.Assert(i >= 0 && i < a.array.data.length, "index out of range")
- start, end = int64(a.offsets[i+a.data.offset]),
int64(a.offsets[i+a.data.offset+1])
+ j := i + a.array.data.offset
+ start, end = int64(a.offsets[j]), int64(a.offsets[j+1])
return
}
@@ -172,6 +173,8 @@ type LargeList struct {
offsets []int64
}
+var _ ListLike = (*LargeList)(nil)
+
// NewLargeListData returns a new LargeList array value, from data.
func NewLargeListData(data arrow.ArrayData) *LargeList {
a := new(LargeList)
@@ -208,9 +211,7 @@ func (a *LargeList) String() string {
}
func (a *LargeList) newListValue(i int) arrow.Array {
- j := i + a.array.data.offset
- beg := int64(a.offsets[j])
- end := int64(a.offsets[j+1])
+ beg, end := a.ValueOffsets(i)
return NewSlice(a.values, beg, end)
}
@@ -280,7 +281,8 @@ func (a *LargeList) Offsets() []int64 { return a.offsets }
func (a *LargeList) ValueOffsets(i int) (start, end int64) {
debug.Assert(i >= 0 && i < a.array.data.length, "index out of range")
- start, end = a.offsets[i], a.offsets[i+1]
+ j := i + a.array.data.offset
+ start, end = a.offsets[j], a.offsets[j+1]
return
}
diff --git a/go/arrow/array/map.go b/go/arrow/array/map.go
index c28a3f9d66..12fc5325f4 100644
--- a/go/arrow/array/map.go
+++ b/go/arrow/array/map.go
@@ -32,6 +32,8 @@ type Map struct {
keys, items arrow.Array
}
+var _ ListLike = (*Map)(nil)
+
// NewMapData returns a new Map array value, from data
func NewMapData(data arrow.ArrayData) *Map {
a := &Map{List: &List{}}
@@ -301,7 +303,7 @@ func (b *MapBuilder) ValueBuilder() Builder {
}
func (b *MapBuilder) AppendValueFromString(s string) error {
- return arrow.ErrNotImplemented
+ return arrow.ErrNotImplemented
}
func (b *MapBuilder) UnmarshalOne(dec *json.Decoder) error {
diff --git a/go/arrow/cdata/cdata_exports.go b/go/arrow/cdata/cdata_exports.go
index 86a8080053..8a9ee2e866 100644
--- a/go/arrow/cdata/cdata_exports.go
+++ b/go/arrow/cdata/cdata_exports.go
@@ -416,13 +416,6 @@ func exportArray(arr arrow.Array, out *CArrowArray,
outSchema *CArrowSchema) {
exportArray(arr.ListValues(), &children[0], nil)
childPtrs[0] = &children[0]
out.children = (**CArrowArray)(unsafe.Pointer(&childPtrs[0]))
- case *array.FixedSizeList:
- out.n_children = 1
- childPtrs := allocateArrowArrayPtrArr(1)
- children := allocateArrowArrayArr(1)
- exportArray(arr.ListValues(), &children[0], nil)
- childPtrs[0] = &children[0]
- out.children = (**CArrowArray)(unsafe.Pointer(&childPtrs[0]))
case *array.Struct:
out.n_children = C.int64_t(arr.NumField())
childPtrs := allocateArrowArrayPtrArr(arr.NumField())