Skip to content

fix(array/record): bldr stop ignore unexpected EOF - #1341

Merged
zeroshade merged 1 commit into
apache:mainfrom
Willem-J-an:main
Oct 5, 2026
Merged

zeroshade merged 1 commit into
apache:mainfrom
Willem-J-an:main

Conversation

@Willem-J-an

Copy link
Copy Markdown
Contributor

Rationale for this change

array/json_reader unmarshals records, but treats EOF as an end of the stream and swallows it. This leads to ignoring unexpected errors where the JSON was not valid: {"a": 2

What changes are included in this PR?

If a new record has started being processed, EOF is converted to UnexpectedEOF, so it will not be swallowed.

Are these changes tested?

Added a testcase.

Are there any user-facing changes?

No

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Reverting record.go to main makes the new test fail. On this branch, JSONReader returns the rows read so far plus unexpected EOF for a truncated top-level or nested record. Trailing whitespace still ends cleanly with no error.

Nits (optional):

  • Remove the blank line right after func (b *RecordBuilder) unmarshalOne( opens.
  • Title scope: fix(arrow/array): return io.ErrUnexpectedEOF for truncated JSON records.

Comment thread arrow/array/record.go
if delim, ok := t.(json.Delim); !ok || delim != '{' {
return fmt.Errorf("record should start with '{', not %s", t)
}
defer func() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: JSONReader.readNext now depends on the difference between io.EOF (no record started) and io.ErrUnexpectedEOF (input ended inside one). Worth stating in the UnmarshalOne doc. Also, this replaces any error that wraps io.EOF with a bare sentinel, so if a wrapped error ever reaches here, its message is lost.

Comment thread arrow/array/util_test.go
src := strings.NewReader(`{"a": 9`)
dec := json.NewDecoder(src)

assert.ErrorIs(t, bldr.UnmarshalOne(dec), io.ErrUnexpectedEOF)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the bug users hit is in JSONReader. Consider adding a NewJSONReader case on {"a":1}\n{"a":2 that asserts 1 row comes back and Err() is io.ErrUnexpectedEOF.

@zeroshade
zeroshade merged commit 572fafb into apache:main Oct 5, 2026
23 checks passed
zeroshade added a commit that referenced this pull request Oct 27, 2026
…#1428)

### Rationale for this change

The Dependabot bump of `github.com/goccy/go-json` to v0.11.2 (#1357)
fails CI. go-json 0.11 is stricter and follows `encoding/json`'s
behaviour for the Go version it is built with, which exposed three tests
that depended on lenient parsing or on backend-specific error details:

- `arrow/compute` `TestIsInDecimal`: the expected array literal is
`[true, false true]` (missing comma); go-json 0.10 accepted it.
- `arrow/array` `TestIntegerArrsJSON` and
`TestRecordBuilderUnmarshalOneReturnUnexpectedEOF`: under Go 1.27's v2
JSON semantics, truncated input is reported as a syntax error
("unexpected end of JSON input") instead of `io.ErrUnexpectedEOF`.
- `parquet/variant` `TestBuilderJSONErrors`: the error message depends
on which tokenizer call first notices the malformed input.

The last two already fail on `main` with the standard-library backend
(`-tags arrow_json_stdlib`, also used for TinyGo) under Go 1.27,
independent of the bump.

### What changes are included in this PR?

Test-only:

- Fix the JSON literal in `TestIsInDecimal`.
- A helper `assertTruncatedJSONError` checks that truncated input is an
error and **not** a clean `io.EOF` — the invariant #1341 added — while
accepting either `io.ErrUnexpectedEOF` or an "unexpected end of JSON
input" syntax error.
- `TestBuilderJSONErrors` keeps all its malformed inputs but only checks
that `ParseJSON` rejects them.

### Are these changes tested?

The affected packages (`arrow/array`, `arrow/compute`,
`parquet/variant`) pass with Go 1.26 and Go 1.27, each with go-json
v0.10.6, go-json v0.11.2 and `-tags arrow_json_stdlib`. Disabling the
`io.EOF` → `io.ErrUnexpectedEOF` conversion in
`RecordBuilder.unmarshalOne` still fails
`TestRecordBuilderUnmarshalOneReturnUnexpectedEOF` ("truncated input
must not be reported as a clean EOF").

### Are there any user-facing changes?

No.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants