You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "felipecrv (via GitHub)" <gi...@apache.org> on 2023/08/31 09:54:58 UTC

[GitHub] [arrow] felipecrv commented on a diff in pull request #37468: GH-35344: [Go][Format] Implementation of the LIST_VIEW and LARGE_LIST_VIEW array formats

felipecrv commented on code in PR #37468:
URL: https://github.com/apache/arrow/pull/37468#discussion_r1311389331


##########
go/arrow/array/list.go:
##########
@@ -618,19 +631,661 @@ func (b *baseListBuilder) UnmarshalJSON(data []byte) error {
 	return b.Unmarshal(dec)
 }
 
+// ListView represents an immutable sequence of array values defined by an
+// offset into a child array and a length.
+type ListView struct {
+	array
+	values  arrow.Array
+	offsets []int32
+	sizes   []int32
+}
+
+var _ VarLenListLike = (*ListView)(nil)
+
+func NewListViewData(data arrow.ArrayData) *ListView {
+	a := &ListView{}
+	a.refCount = 1
+	a.setData(data.(*Data))
+	return a
+}
+
+func (a *ListView) ListValues() arrow.Array { return a.values }
+
+func (a *ListView) ValueStr(i int) string {
+	if !a.IsValid(i) {
+		return NullValueStr
+	}
+	return string(a.GetOneForMarshal(i).(json.RawMessage))
+}
+
+func (a *ListView) String() string {
+	o := new(strings.Builder)
+	o.WriteString("[")
+	for i := 0; i < a.Len(); i++ {
+		if i > 0 {
+			o.WriteString(" ")
+		}
+		if !a.IsValid(i) {
+			o.WriteString(NullValueStr)
+			continue
+		}
+		sub := a.newListValue(i)
+		fmt.Fprintf(o, "%v", sub)
+		sub.Release()
+	}
+	o.WriteString("]")
+	return o.String()
+}
+
+func (a *ListView) newListValue(i int) arrow.Array {
+	beg, end := a.ValueOffsets(i)
+	return NewSlice(a.values, beg, end)
+}
+
+func (a *ListView) setData(data *Data) {
+	a.array.setData(data)
+	offsets := data.buffers[1]

Review Comment:
   With `debug.Assert`? Isn't `[i]` access already checked in Go at runtime?



##########
go/arrow/array/list.go:
##########
@@ -422,6 +431,10 @@ func (b *baseListBuilder) Append(v bool) {
 	b.appendNextOffset()
 }
 
+func (b *baseListBuilder) AppendWithSize(v bool, list_size int) {

Review Comment:
   Fixing.



##########
go/arrow/array/list.go:
##########
@@ -618,19 +631,661 @@ func (b *baseListBuilder) UnmarshalJSON(data []byte) error {
 	return b.Unmarshal(dec)
 }
 
+// ListView represents an immutable sequence of array values defined by an
+// offset into a child array and a length.
+type ListView struct {
+	array
+	values  arrow.Array
+	offsets []int32
+	sizes   []int32
+}
+
+var _ VarLenListLike = (*ListView)(nil)
+
+func NewListViewData(data arrow.ArrayData) *ListView {
+	a := &ListView{}
+	a.refCount = 1
+	a.setData(data.(*Data))
+	return a
+}
+
+func (a *ListView) ListValues() arrow.Array { return a.values }
+
+func (a *ListView) ValueStr(i int) string {
+	if !a.IsValid(i) {
+		return NullValueStr
+	}
+	return string(a.GetOneForMarshal(i).(json.RawMessage))
+}
+
+func (a *ListView) String() string {
+	o := new(strings.Builder)
+	o.WriteString("[")
+	for i := 0; i < a.Len(); i++ {
+		if i > 0 {
+			o.WriteString(" ")
+		}
+		if !a.IsValid(i) {
+			o.WriteString(NullValueStr)
+			continue
+		}
+		sub := a.newListValue(i)
+		fmt.Fprintf(o, "%v", sub)
+		sub.Release()
+	}
+	o.WriteString("]")
+	return o.String()
+}
+
+func (a *ListView) newListValue(i int) arrow.Array {
+	beg, end := a.ValueOffsets(i)
+	return NewSlice(a.values, beg, end)
+}
+
+func (a *ListView) setData(data *Data) {
+	a.array.setData(data)
+	offsets := data.buffers[1]

Review Comment:
   With `debug.Assert`? Isn't `[i]` access already checked in Go at runtime?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org