Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion go/arrow/array/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
stringArrayMaximumCapacity = math.MaxInt32
)

// A type which represents an immutable sequence of variable-length UTF-8 strings.
// String is a type which represents an immutable sequence of variable-length UTF-8 strings.
type String struct {
array
offsets []int32
Expand All @@ -45,11 +45,18 @@ func NewStringData(data *Data) *String {
return a
}

// Reset resets the String with a different set of Data.
func (a *String) Reset(data *Data) {
a.setData(data)
}

// Value returns the slice at index i. This value should not be mutated.
func (a *String) Value(i int) string {
i = i + a.array.data.offset
return a.values[a.offsets[i]:a.offsets[i+1]]
}

// ValueOffset returns the offset of the value at index i.
func (a *String) ValueOffset(i int) int { return int(a.offsets[i]) }

func (a *String) String() string {
Expand Down Expand Up @@ -104,6 +111,7 @@ type StringBuilder struct {
builder *BinaryBuilder
}

// NewStringBuilder creates a new StringBuilder.
func NewStringBuilder(mem memory.Allocator) *StringBuilder {
b := &StringBuilder{
builder: NewBinaryBuilder(mem, arrow.BinaryTypes.String),
Expand Down Expand Up @@ -134,10 +142,12 @@ func (b *StringBuilder) Cap() int { return b.builder.Cap() }
// NullN returns the number of null values in the array builder.
func (b *StringBuilder) NullN() int { return b.builder.NullN() }

// Append appends a string to the builder.
func (b *StringBuilder) Append(v string) {
b.builder.Append([]byte(v))
}

// AppendNull appends a null to the builder.
func (b *StringBuilder) AppendNull() {
b.builder.AppendNull()
}
Expand All @@ -149,6 +159,7 @@ func (b *StringBuilder) AppendValues(v []string, valid []bool) {
b.builder.AppendStringValues(v, valid)
}

// Value returns the string at index i.
func (b *StringBuilder) Value(i int) string {
return string(b.builder.Value(i))
}
Expand Down