Skip to content

arrow: import Arrow C Stream batches - #144

Closed
Xuanwo wants to merge 5 commits into
mainfrom
xuanwo/arrow-c-stream-import
Closed

Xuanwo wants to merge 5 commits into
mainfrom
xuanwo/arrow-c-stream-import

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Superseded by #147, which preserves the importer and corrects the root-null test bitmap and commit authorship.

Summary

  • Add lancedb_record_batch_reader_from_arrow_stream() for the write side of query: support Arrow C Data Stream (ArrowArrayStream) for streaming reads and writes #129. It moves a validated ArrowArrayStream into an existing LanceDBRecordBatchReader, so create, add and merge_insert can consume a C producer without the binding collecting batches first.
  • Validate the stream, output pointer and required get_schema / get_next / release callbacks before taking ownership. On a pre-move failure the caller still owns the stream. After the move, the binding releases the producer exactly once, including when schema acquisition fails, and leaves the caller's outer struct storage with its release pointer cleared.
  • Acquire the schema synchronously on the calling thread and pull batches lazily. Preserve producer schema and read error text; when a valid get_last_error callback returns NULL, fall back to the callback error code instead of panicking.
  • Declare the standard Arrow C Data and Stream structures in include/lancedb.h under the shared ARROW_C_DATA_INTERFACE / ARROW_C_STREAM_INTERFACE guards. Both include orders with arrow/c/abi.h compile in C and C++.
  • Document serial callbacks, possible SDK worker/free threads, and the SDK backend buffering boundary.

Arrow stream export is intentionally left for the runtime bridge work around #76. This change is additive and independent of the #122/#135 query changes.

Tests

  • Real Arrow C++ ExportRecordBatchReader producer with multi-batch data through table create, add and merge, checking actual row values.
  • Controlled producers cover schema acquisition before return, lazy batch reads, unused-reader free, callback validation before moving, release exactly once after schema failure, read error text, NULL get_last_error, and zero-row batches not being treated as EOF.
  • New Catch2 executable runs under valgrind.

Validation

  • cargo check --package lancedb-c
  • cargo clippy --all-targets -- -D warnings
  • cargo fmt --check
  • CMake Debug build of lancedb_arrow_stream_tests
  • ctest --test-dir build -R arrow_stream --output-on-failure (valgrind: 0 errors, 0 definitely/possibly lost)
  • ninja -C build check-c17
  • ninja -C build check-abi (host and x86_64-pc-windows-msvc)
  • Manual C17 and C++20 compile checks for both lancedb.h / arrow header inclusion orders

Refs #129

Fixture added 5 commits November 22, 2026 08:57
Add lancedb_record_batch_reader_from_arrow_stream() to move a validated
ArrowArrayStream into a LanceDBRecordBatchReader. The imported reader
acquires the schema once, pulls batches lazily, and preserves producer
schema and read errors, including a NULL get_last_error result.

The public header now declares the standard Arrow C Data and Stream
structures behind the shared inclusion guards. Import tests cover real
Arrow C++ multi-batch producers through create, add and merge, plus
callback validation, release ownership, schema failures, read failures
and zero-row batches under valgrind.

Refs #129
Declare the Arrow C ABI structs as canonical named structs and keep the
C typedef aliases behind Doxygen conditionals. This preserves the public
C ABI and both Arrow header inclusion orders while leaving Breathe with a
single struct declaration for each type.

Teach the ABI checker to resolve a typedef that refers to an earlier struct
tag and to keep complete struct definitions out of the opaque-type list.

Refs #129
A RecordBatch cannot represent null rows in the top-level struct, and the
previous child-column extraction silently dropped the root validity bitmap.
Check the parsed root null count first and return an Arrow error before
building the batch. The imported ArrowArray is still released by RAII.

Document the accepted shape, child nullability and independent stream,
schema and array ownership. Add a valid root-null Arrow fixture that checks
the destination table and stream release stay unchanged.

Refs #129
@Xuanwo Xuanwo closed this Nov 22, 2026
Xuanwo added a commit that referenced this pull request Nov 22, 2026
Add lancedb_record_batch_reader_from_arrow_stream() for the write side of
#129. It moves a validated ArrowArrayStream into a LanceDBRecordBatchReader,
acquires the schema once, pulls batches lazily, and preserves producer
schema and read errors, including a NULL get_last_error result.

Validate required callbacks before taking ownership, clear the source
release pointer, and release the producer exactly once after the move,
including schema failure. Reject top-level struct null rows before
extracting child columns, because a RecordBatch cannot represent them.
Document the accepted RecordBatch shape and independent stream, schema and
array ownership.

Declare the standard Arrow C Data and Stream structures behind the shared
inclusion guards, keep Doxygen from emitting duplicate typedef structs, and
teach the ABI checker to resolve separate struct/typedef declarations.
Add real C++ multi-batch create/add/merge coverage plus focused ownership,
error and root-null fixtures.

This replacement is based on actual main 55cd8a6 and retains the original
#144 tests, headers, ABI checker and Delta/DML integration.

Refs #144
Refs #129
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.

1 participant