Skip to content

feat(arrow/ipc): add Reader.ContinueFrom for streams split across blobs - #1346

Merged
zeroshade merged 2 commits into
apache:mainfrom
zeroshade:ipc-reader-continue-from
Oct 5, 2026
Merged

zeroshade merged 2 commits into
apache:mainfrom
zeroshade:ipc-reader-continue-from

Conversation

@zeroshade

@zeroshade zeroshade commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Rationale for this change

Fixes #1325. Some callers decode one logical IPC stream that arrives as a sequence of blobs, where only the first blob carries the schema. Through v18.7.0 they could reuse one ipc.Reader by swapping the underlying io.Reader. Since v18.8.0, done stays set once a blob reaches EOF and can't be reset, so every blob after the first decodes as zero rows with a nil error.

What changes are included in this PR?

  • (*Reader).ContinueFrom(io.Reader) error and (*Reader).ContinueFromMessageReader(MessageReader) error resume a reader on a new source. The schema and dictionaries already read are kept. Both methods also:
    • discard the current record batch, release the previous message reader, and clear done;
    • refuse to continue a reader that has already failed, so an earlier error can't be hidden;
    • refuse to continue a reader that hasn't read its schema yet.
  • As requested in Reusing ipc.Reader across concatenated streams stopped working in v18.8.0 #1325 (comment), a schema message where a record batch is expected now fails with arrow/ipc: unexpected schema message: …. That marks the reader done, and the error is sticky. Before, this gave the generic invalid-message-type error. The other invalid-type errors now also have their closing parenthesis back.

Are these changes tested?

Yes. TestReaderContinueFrom splits a single writer's output, with an int64 column and a dictionary column, into three blobs and checks:

  • all batches round-trip through both Next and Read, and dictionaries carry across blobs;
  • a continuation that starts with a schema message fails loudly and stays failed;
  • ContinueFrom on a reader whose schema hasn't been read yet returns an error and leaves the reader usable.

The test uses a checked allocator. Removing the done reset makes it fail.

Are there any user-facing changes?

Yes: two new methods on ipc.Reader, and a clearer error when a schema message appears mid-stream.

Message size limits (follow-up commit)

NewReader built its messageReader without the configured limits. Those limits were added in #955, which never touched reader.go, so a stream Reader ignored WithMetadataSizeLimit/WithBodySizeLimit and enforced no limit at all. NewReader now creates its message reader with the options it was given, and ContinueFrom reuses the same limits.

Behavior change: stream readers created with NewReader now enforce the documented default limits, 64 MiB for metadata and 256 MiB for bodies. A stream with larger messages needs WithBodySizeLimit/WithMetadataSizeLimit; passing a value ≤ 0 disables the limit. TestReaderSizeLimits covers both NewReader and ContinueFrom.

Since v18.8.0, a Reader that reached the end of its source stays done, so
swapping the underlying io.Reader to decode a later schema-less blob yields
zero rows with a nil error. ContinueFrom and ContinueFromMessageReader
resume a reader on a new source, keeping the schema and dictionaries
already read.

A schema message where a record batch is expected now fails with a clear
error instead of the generic invalid-message-type one, so a continuation
that is really a new stream fails loudly rather than dropping rows.

Fixes apache#1325
NewReader built its message reader without the configured
WithMetadataSizeLimit/WithBodySizeLimit, so stream readers enforced no
limit at all, and ContinueFrom applied the defaults instead of the
reader's own limits. Both now use the limits the Reader was created with.
@zeroshade
zeroshade requested review from amoeba and lidavidm October 2, 2026 21:33
@zeroshade
zeroshade merged commit 4818a62 into apache:main Oct 5, 2026
23 checks passed
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.

Reusing ipc.Reader across concatenated streams stopped working in v18.8.0

2 participants