Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions data/arrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ func initializeFrameField(field arrow.Field, idx int, nullable []bool, sdkField
break
}
sdkField.vector = newStringVector(0)
case arrow.STRING_VIEW:
if nullable[idx] {
sdkField.vector = newNullableStringVector(0)
break
}
sdkField.vector = newStringVector(0)
case arrow.INT8:
if nullable[idx] {
sdkField.vector = newNullableInt8Vector(0)
Expand Down Expand Up @@ -508,6 +514,21 @@ func parseColumn(col arrow.Array, i int, nullable []bool, frame *Frame) error {
}
frame.Fields[i].vector.Append(v.Value(rIdx))
}
case arrow.STRING_VIEW:
v := array.NewStringViewData(col.Data())
for rIdx := 0; rIdx < col.Len(); rIdx++ {
if nullable[i] {
if v.IsNull(rIdx) {
var ns *string
frame.Fields[i].vector.Append(ns)
continue
}
rv := v.Value(rIdx)
frame.Fields[i].vector.Append(&rv)
continue
}
frame.Fields[i].vector.Append(v.Value(rIdx))
}
case arrow.INT8:
v := array.NewInt8Data(col.Data())
for rIdx := 0; rIdx < col.Len(); rIdx++ {
Expand Down
39 changes: 39 additions & 0 deletions data/arrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import (
"testing"
"time"

"github.com/apache/arrow-go/v18/arrow"
"github.com/apache/arrow-go/v18/arrow/array"
"github.com/apache/arrow-go/v18/arrow/ipc"
"github.com/apache/arrow-go/v18/arrow/memory"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -440,3 +443,39 @@ func TestFromRecord(t *testing.T) {
t.Errorf("Result mismatch (-want +got):\n%s", diff)
}
}

func TestFromRecordStringView(t *testing.T) {
pool := memory.NewGoAllocator()
require.NotNil(t, pool)
schema := arrow.NewSchema([]arrow.Field{
arrow.Field{Name: "sv", Type: &arrow.StringViewType{}, Nullable: false},
arrow.Field{Name: "svn", Type: &arrow.StringViewType{}, Nullable: true},
}, nil)
require.NotNil(t, schema)
b := array.NewRecordBuilder(pool, schema)
defer b.Release()

testStrings := []string{"foo", "", "", "🦥", "bar"}
notNull := []bool{true, true, false, true, true}
b.Field(0).(*array.StringViewBuilder).AppendValues(testStrings, nil)
b.Field(1).(*array.StringViewBuilder).AppendValues(testStrings, notNull)
record := b.NewRecord()
defer record.Release()

got, err := data.FromArrowRecord(record)
require.NoError(t, err)

want := data.NewFrame("",
data.NewField("sv", data.Labels{}, testStrings),
data.NewField("svn", data.Labels{}, []*string{
stringPtr("foo"),
stringPtr(""),
nil,
stringPtr("🦥"),
stringPtr("bar"),
}),
)
if diff := cmp.Diff(want, got, data.FrameTestCompareOptions()...); diff != "" {
t.Errorf("Result mismatch (-want +got):\n%s", diff)
}
}