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-go.git
The following commit(s) were added to refs/heads/main by this push:
new 00e949e3 fix: clarify StringViewBuilder.UnmarshalOne expected type
(#897)
00e949e3 is described below
commit 00e949e3f57498fdf88b36bc9c54e5b2c8580279
Author: Minh Vu <[email protected]>
AuthorDate: Thu Jul 9 20:58:27 2026 +0200
fix: clarify StringViewBuilder.UnmarshalOne expected type (#897)
## Summary
### Problem
`StringViewBuilder.UnmarshalOne` reports a `json.UnmarshalTypeError`
with an expected type of `[]byte{}` for unsupported token types.
### Change
- Update `StringViewBuilder.UnmarshalOne` to report `reflect.TypeOf("")`
when an unsupported JSON token is encountered.
- Add regression test `TestStringViewBuilderUnmarshalOneWrongType` in
`arrow/array/string_test.go`.
### Impact
- Aligns error diagnostics with `StringBuilder` behavior.
- Makes JSON import debugging clearer for users expecting string inputs.
### Testing
- Added a focused regression test that asserts the reported expected
type is `string` for unsupported JSON token input.
- No full test run in this PR (single-path, message-type assertion).
---
arrow/array/string.go | 2 +-
arrow/array/string_test.go | 19 +++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/arrow/array/string.go b/arrow/array/string.go
index 559a216c..7c2ab074 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 0457b8b3..087da9fe 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) {