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 4988d015 fix(arrow/csv): preserve braces in list values (#1499)
4988d015 is described below
commit 4988d015a4115f661d1671d886ee38a2df5cc001
Author: peterolkhov <[email protected]>
AuthorDate: Tue Nov 10 12:44:29 2026 -0500
fix(arrow/csv): preserve braces in list values (#1499)
### Rationale for this change
CSV list parsing trims all leading and trailing braces, including braces
that belong to child values. A list containing `"{hello}"` reads back as
`"hello"`, `"{}"` becomes an empty list, and nested singleton lists can
fail to parse.
### What changes are included in this PR?
Remove exactly one validated outer brace pair in both list parsers. Add
writer-to-reader equality tests for all five list variants,
brace-bearing strings, CSV quoting, nested lists, empty lists and null
lists.
### Are these changes tested?
The new regression fails before the fix and passes after it. All CSV
tests/examples pass normally and with `-race -short -tags assert,test`
and `assert,test,noasm`. CSV-scoped golangci-lint 2.13.2 reports zero
issues; configured gofmt/goimports checks pass.
The full Arrow/Parquet suites and pre-commit checks have not been run
locally. CI still needs to cover those checks.
### Are there any user-facing changes?
CSV written by this package preserves braces in list strings and
wrappers around nested singleton lists when read back. Inputs that
depended on silently removing extra braces around scalar numeric values
may now fail parsing.
AI assistance: prepared with OpenAI Codex.
---
arrow/csv/reader.go | 4 ++--
arrow/csv/reader_test.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/arrow/csv/reader.go b/arrow/csv/reader.go
index 59052ee4..dab0df65 100644
--- a/arrow/csv/reader.go
+++ b/arrow/csv/reader.go
@@ -853,7 +853,7 @@ func (r *Reader) parseListLike(field array.ListLikeBuilder,
str string) {
field.AppendNull()
return
}
- str = strings.Trim(str, "{}")
+ str = str[1 : len(str)-1]
if len(str) == 0 {
// we don't want to create the csv reader if we already know the
// string is empty
@@ -892,7 +892,7 @@ func (r *Reader) parseFixedSizeList(field
*array.FixedSizeListBuilder, str strin
field.AppendNull()
return
}
- str = strings.Trim(str, "{}")
+ str = str[1 : len(str)-1]
if len(str) == 0 {
// we don't want to create the csv reader if we already know the
// string is empty
diff --git a/arrow/csv/reader_test.go b/arrow/csv/reader_test.go
index f276a103..7c866852 100644
--- a/arrow/csv/reader_test.go
+++ b/arrow/csv/reader_test.go
@@ -219,6 +219,53 @@ func TestCSVReadInvalidFields(t *testing.T) {
}
}
+func TestCSVListRoundTrip(t *testing.T) {
+ tests := []struct {
+ name string
+ elem arrow.DataType
+ size int32
+ data string
+ }{
+ {name: "strings", elem: arrow.BinaryTypes.String, size: 1,
+ data: `[["{hello}"], ["{hello"], ["hello}"], ["{}"],
["{{}}"], ["hello"], ["a,b"], ["say \"hello\""], ["{a,b}"], null]`},
+ {name: "nested", elem:
arrow.ListOf(arrow.PrimitiveTypes.Int64), size: 1,
+ data: `[[[1]], [[]], [[1,2]], null]`},
+ {name: "empty", elem: arrow.BinaryTypes.String, size: 0, data:
`[[], null]`},
+ }
+ for _, tc := range tests {
+ for _, typ := range []arrow.DataType{
+ arrow.ListOf(tc.elem),
+ arrow.LargeListOf(tc.elem),
+ arrow.FixedSizeListOf(tc.size, tc.elem),
+ arrow.ListViewOf(tc.elem),
+ arrow.LargeListViewOf(tc.elem),
+ } {
+ t.Run(tc.name+"/"+typ.Name(), func(t *testing.T) {
+ mem :=
memory.NewCheckedAllocator(memory.DefaultAllocator)
+ defer mem.AssertSize(t, 0)
+ input, _, err := array.FromJSON(mem, typ,
strings.NewReader(tc.data))
+ require.NoError(t, err)
+ defer input.Release()
+ schema := arrow.NewSchema([]arrow.Field{{Name:
"value", Type: typ}}, nil)
+ record := array.NewRecordBatch(schema,
[]arrow.Array{input}, int64(input.Len()))
+ defer record.Release()
+
+ var buf bytes.Buffer
+ w := csv.NewWriter(&buf, schema,
csv.WithNullWriter("null"))
+ require.NoError(t, w.Write(record))
+ require.NoError(t, w.Flush())
+ r := csv.NewReader(&buf, schema,
csv.WithAllocator(mem), csv.WithChunk(-1), csv.WithNullReader(true, "null"))
+ defer r.Release()
+ require.True(t, r.Next())
+ require.NoError(t, r.Err())
+ assert.True(t, array.Equal(input,
r.RecordBatch().Column(0)), "expected %s, got %s", input,
r.RecordBatch().Column(0))
+ assert.False(t, r.Next())
+ assert.NoError(t, r.Err())
+ })
+ }
+ }
+}
+
func TestFixedSizeBinaryParseErrorAppendsNull(t *testing.T) {
schema := arrow.NewSchema(
[]arrow.Field{