diff --git a/arrow/array/string.go b/arrow/array/string.go index 007485766..d0e32f244 100644 --- a/arrow/array/string.go +++ b/arrow/array/string.go @@ -778,7 +778,7 @@ func (b *StringViewBuilder) UnmarshalOne(dec *json.Decoder) error { default: return &json.UnmarshalTypeError{ Value: fmt.Sprint(t), - Type: reflect.TypeOf([]byte{}), + Type: reflect.TypeOf(string("")), Offset: dec.InputOffset(), } } diff --git a/arrow/array/string_test.go b/arrow/array/string_test.go index 0457b8b3c..087da9feb 100644 --- a/arrow/array/string_test.go +++ b/arrow/array/string_test.go @@ -25,6 +25,7 @@ import ( "github.com/apache/arrow-go/v18/arrow/array" "github.com/apache/arrow-go/v18/arrow/bitutil" "github.com/apache/arrow-go/v18/arrow/memory" + "github.com/apache/arrow-go/v18/internal/json" "github.com/stretchr/testify/assert" ) @@ -902,6 +903,24 @@ func TestStringViewBuilder_Empty(t *testing.T) { a.Release() } +func TestStringViewBuilderUnmarshalOneWrongType(t *testing.T) { + mem := memory.NewCheckedAllocator(memory.DefaultAllocator) + defer mem.AssertSize(t, 0) + + bldr := array.NewStringViewBuilder(mem) + defer bldr.Release() + + dec := json.NewDecoder(bytes.NewReader([]byte(`1`))) + err := bldr.UnmarshalOne(dec) + + assert.Error(t, err) + var ute *json.UnmarshalTypeError + assert.ErrorAs(t, err, &ute) + if assert.NotNil(t, ute) { + assert.Equal(t, reflect.TypeOf(""), ute.Type) + } +} + // TestStringReset tests the Reset() method on the String type by creating two different Strings and then // resetting the contents of string2 with the values from string1. func TestStringViewReset(t *testing.T) {