Repository navigation
fix(array/record): bldr stop ignore unexpected EOF - #1341
Conversation
zeroshade
left a comment
There was a problem hiding this comment.
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.
| if delim, ok := t.(json.Delim); !ok || delim != '{' { | ||
| return fmt.Errorf("record should start with '{', not %s", t) | ||
| } | ||
| defer func() { |
There was a problem hiding this comment.
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.
| src := strings.NewReader(`{"a": 9`) | ||
| dec := json.NewDecoder(src) | ||
|
|
||
| assert.ErrorIs(t, bldr.UnmarshalOne(dec), io.ErrUnexpectedEOF) |
There was a problem hiding this comment.
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.
…#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.
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": 2What 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