Repository navigation
Open
Labels
enhancementNew feature or request
Description
Context & SDK Reference
Currently lancedb-c materializes entire datasets in memory on both read and write boundaries:
- Read path (
src/query.rs):lancedb_query_result_to_arrowcollects the entireSendableRecordBatchStreamintoVec<RecordBatch>viatry_collect(), andlancedb_query_result_to_ipc_filebuffers a complete Arrow IPC file in memory. - Write path (
src/table.rs):lancedb_record_batch_reader_from_arrowtakes an already-materialized array ofFFI_ArrowArray*batches.
For large tables, full-table scans, exports, and streaming ingest (in both C/C++ and lancedb-go), buffering all batches in memory causes unnecessary peak memory usage and OOM risk.
arrow-array::ffi_stream::FFI_ArrowArrayStream (already available in the pinned arrow-array crate) provides standard zero-copy Arrow C Stream Interface (struct ArrowArrayStream) bridging in both directions.
Proposed C API Scope
- Streaming read: Add
lancedb_query_result_to_arrow_stream(LanceDBQueryResult* result, struct ArrowArrayStream* stream_out, char** error_message)(or returning an allocated stream handle) that wrapsSendableRecordBatchStreaminto anFFI_ArrowArrayStream, pulling batches on demand from the Tokio runtime and propagating stream errors viaArrowArrayStream.get_last_error. - Streaming write: Add
lancedb_record_batch_reader_from_arrow_stream(struct ArrowArrayStream* stream, LanceDBRecordBatchReader** reader_out, char** error_message)that consumes an Arrow C Stream (ArrowArrayStreamReader) socreate_table,add, andmerge_insertcan ingest streams lazily without buffering all batches upfront. - Declare
struct ArrowArrayStreamininclude/lancedb.hguarded by#ifndef ARROW_C_STREAM_INTERFACE(matching the existing#ifndef ARROW_C_DATA_INTERFACEpattern forArrowSchema/ArrowArray).
Non-Goals
- Removing existing
lancedb_query_result_to_arrow,lancedb_query_result_to_ipc_file, orlancedb_record_batch_reader_from_arrowAPIs.
Acceptance Criteria
- Both
ArrowArrayStreamexport (query result -> C consumer) and import (C producer ->create_table/add/merge_insert) work end-to-end throughinclude/lancedb.h. - Stream errors from the Rust async stream are surfaced through
ArrowArrayStream::get_last_error, and early consumer release (stream->release) cleanly drops the underlying Rust stream without leaking memory or hanging runtime tasks. - C++ Catch2 tests (using Arrow C++
ImportRecordBatchReader/ExportRecordBatchReader) verify multi-batch streaming reads, streaming writes, early termination, and error propagation under valgrind.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
docs: avoid duplicate Arrow C ABI struct declarations
arrow: reject root-null struct rows on stream import
arrow: import Arrow C Stream batches (#147)