Repository navigation
ipc: add Arrow IPC file transport for inputs and query results - #87
Merged
Merged
Conversation
A consumer without the Arrow C Data interface, such as a pure Go program where Arrow Go's cdata package sits behind a cgo build tag, cannot use the current single-batch input and C Data result conversion. Such a consumer also cannot see the projected schema of an empty result or the SDK error text of a query that never started. Add six additive entry points beside the existing ones: - lancedb_query_execute_with_status and lancedb_vector_query_execute_with_status report the SDK status and text instead of a NULL pointer. The existing execute entries share the same implementation and keep their pointer-return convention. - lancedb_query_result_to_ipc_file writes the SDK stream to one Arrow IPC file and hands the bytes over only after the footer is written, so a stream error after any batch yields no file. The projected schema is kept when the result has no batch, and zero-row batches stay batches. - lancedb_table_schema_ipc_file writes a valid file with the table schema and no batch. - lancedb_record_batch_reader_from_ipc_file decodes a borrowed file into an owned reader over every batch and optionally the Arrow C ABI schema. All batches are decoded before returning, so a corrupt batch fails before a table can be written. - lancedb_ipc_buffer_free frees the file bytes and zeroes the buffer, so freeing twice is a no-op. The IPC file format and the SDK stream interface are the same on the pinned 0.33 SDK and on the 0.42 upgrade, so this slice does not depend on it.
Decoding borrowed bytes at the C boundary now rejects what it cannot read before the Arrow reader allocates anything: a size that cannot describe a Rust slice, an announced footer that does not fit the input, and a NULL pointer with no bytes, which joins zero bytes as empty input. A panic inside the decoder is caught at the entry point, so a malformed batch cannot unwind across the C boundary; it reports LANCEDB_INVALID_INPUT with a message like any other unreadable file. Unit tests cover the parts a public C caller cannot reach: batch order including a zero-row batch, an SDK stream error after valid batches keeping the original error, the footer bound, and the panic barrier with a synthetic panic instead of crafted input. The public vector query file keeps the distance column the SDK adds to a projection, so its test expects key followed by _distance. Start-error and invalid-input tests now assert the actual SDK diagnostic instead of only a non-success status. The IPC buffer typedef is anonymous, matching the other C structs in the public header: a named struct and its typedef make Doxygen and Breathe register the declaration twice, which fails the docs build.
The coverage job showed the new IPC entry points with branches no public caller reached: a too-short input, a footer larger than the input, a size that cannot describe a buffer, and the missing result pointer of both status executors. Each of those is a documented input contract, so cover it through the public header instead of leaving it to the internal tests. The remaining uncovered lines are error arms a public caller cannot reach on purpose (a decoder panic, an SDK stream that fails mid-stream, an Arrow encoding failure of an SDK-provided schema).
Keep the slice on main's dependency pins: resolve the manifest to the git lancedb v0.42.0-beta.21 and lance v15.0.0-beta.25 tags with the Arrow 59 crates, and add arrow-ipc 59.2.0 beside them so the lock resolves the same 59.3.3 every other Arrow crate uses. In src/query.rs keep the shared run_vector_query helper instead of main's inline copy, and make its nprobes call fallible like main's, so the vector builder keeps one implementation for both execute entry points. The SQL predicate handling stays as main has it: a DataFusion expression takes precedence over the SQL filter on both paths, and the explain paths honor the SQL filter too.
Decoding already prepared both requested C outputs inside the panic barrier, but only a unit test proved that an input whose schema cannot be exported to the C data interface is a normal error. A field name with a NUL byte is valid Arrow and survives an IPC round trip, while the C data interface carries names as C strings, so it is the ordinary way such an input reaches the boundary. Cover it on both sides: an internal test asserts that the file decodes and only the C schema conversion fails, and a public test writes such a file with the Arrow C++ writer and asserts LANCEDB_INVALID_INPUT with both outputs left clear. The error text now says the file is unusable instead of claiming it could not be read, which is what happens when only the conversion fails.
The coverage report for the merged head showed the new decode guard only partly exercised: the unreadable-footer arm, the dictionary-block loop and the "ends outside the file" arm never ran, because every test file was a plain two-batch utf8 file with an intact footer. Cover them with ordinary inputs through the public header: a file whose announced footer length fits but whose footer bytes are not a footer, a valid file with a dictionary-encoded column that must decode with its dictionary encoding intact, and a file with an intact footer whose middle was dropped so the blocks it declares no longer fit. The panic message fits one line now, which removes two instrumented lines without changing where the panic is contained. Remaining uncovered lines are the negative-length guard, which a valid footer cannot reach, and the panic path itself, which only a decoder panic reaches; both stay covered by internal tests.
The example crate has its own lock, and it did not gain the arrow-ipc edge that the root manifest now declares, so `cargo metadata --locked` there would have to rewrite the lock. Add the edge and keep every pinned version as it was.
The optional outputs are already covered for a plain file; the dictionary file now also asks for the reader alone and the schema alone, so the one-at-a-time contract is exercised with a non-trivial type.
The packaging matrix keeps the targets whose artifacts the release matrix consumes: Linux amd64/arm64, macOS arm64 and Windows amd64/arm64. The Intel runner entry only built darwin-amd64 and is removed here so the packaging workflow no longer needs an Intel-specific runner.
…slice Two conflicts: - src/query.rs kept the shared run_vector_query instead of main's inline copy, and gained main's post-filter call there. The SQL filter still yields to a DataFusion expression and nprobes stays fallible. - tests/test_table.cpp kept both sides: the Arrow IPC input case and the schema-evolution helpers and case from main. Everything else merged cleanly, including the raw enum entry validation, the vector post-filter setter and explain path, and the history, tag and index listing APIs. Dependency pins and both locks are unchanged.
src/query.rs kept one plain and one vector executor for both the legacy and the status/IPC entry points. The full-text search from main is applied in those shared executors, next to the post-filter, the checked distance and the SQL filter that still yields to a DataFusion expression; probes stay fallible. The imports merge both sides. The hybrid EXPLAIN caveat and the index statistics arrive unchanged from main. tests/test_fts.cpp gains one focused case: the plain full-text result and the fused hybrid result go through the status executors and the IPC file, reusing the existing FTS fixture and the shared IPC reader instead of duplicating the broad search tests. Everything else merged cleanly, including the C17 consumer and the FTS test registration. Dependency pins and both locks are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
lancedb-go has to run with
CGO_ENABLED=0, and Arrow Go'sarrow/cdatapackage is behind acgobuild tag, so the Arrow C Data interface is not usable there. The C ABI also only accepts a single batch as C Data input, and its result conversion drops the projected schema of an empty result and turns a stream error intoLANCEDB_UNKNOWN.What it adds
Six additive entry points. No existing symbol, struct layout, return convention or ownership rule changes.
lancedb_query_execute_with_status,lancedb_vector_query_execute_with_statuslancedb_query_result_to_ipc_filelancedb_table_schema_ipc_filelancedb_record_batch_reader_from_ipc_file(bytes, len)into an owned reader over every batch and/or the Arrow C ABI schema. All batches are decoded before the call returns, so a corrupt batch fails before a table can be written. Bad bytes areLANCEDB_INVALID_INPUTwith a decoding message.lancedb_ipc_buffer_freeThe new entries clear their writable outputs and the error message on entry. A NULL pointer with
len == 0is the same empty input as zero bytes; a NULL pointer with bytes is an invalid argument.Decoding and the preparation of the requested C outputs run inside one panic barrier, and neither output is written unless every requested conversion succeeded. An input whose schema cannot be represented in the C data interface, for example a field name with a NUL byte, is a normal
LANCEDB_INVALID_INPUTwith both outputs clear. Before the Arrow reader can allocate from file metadata, the decoder rejects a size that cannot describe a buffer, a footer that does not fit the input, and any footer-declared record-batch or dictionary block whose checked offset plus metadata plus body length ends outside the borrowed bytes; valid files are not limited by any new cap. A decoder panic is contained asLANCEDB_INVALID_INPUTinstead of unwinding across the C boundary.The IPC buffer is an anonymous struct typedef, like the other public C structs: a named struct plus typedef makes Doxygen/Breathe register the declaration twice, which fails the docs build.
Dependencies
This branch is merged onto main after the 0.42 SDK upgrade (#78), and keeps main's pins unchanged:
lancedbv0.42.0-beta.21 andlancev15.0.0-beta.25 git tags, the Arrow 59 crates, andarrow-ipc = "59.2.0"beside them so the lock resolves 59.3.3 like every other Arrow crate. The vector builder'snprobescall is fallible as on main, and main's SQL predicate handling is preserved: a DataFusion expression wins over the SQL filter on both paths, and the explain paths honor the SQL filter.Still open and not required:
get_runtime().block_oncalls the same way it applies to the existing ones.run_vector_querythis PR extracts.xuanwo/c-fts-hybrid-migration, committed on 861a706) addsfull_text_searchfields, setters and two apply calls insrc/query.rs. Whichever side lands second keeps those two apply calls: here they belong inrun_plain_queryandrun_vector_query, which are the single builder implementations both execute entries share.Validation
Local, at head
74ad4f2(main2b2b3df, 0.42.0-beta.21 / Arrow 59.3.3), Arrow C++ 26.0.1, Rust 1.98.1:cargo fmt --check,cargo clippy --lib,cargo check --libclean;cargo test --lib4/4 (batch order including a zero-row batch, SDK stream error after valid batches keeping the original error, footer bound, synthetic panic containment).cmake -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release+ninja, thenctest --test-dir build -j4 --output-on-failure: 9/9 suites passed, 7 of them under Valgrind (table and query:ERROR SUMMARY: 0 errors,definitely lost: 0 bytes).cargo test --lib: 6/6, covering batch order with a zero-row batch, a stream error after valid batches, the footer and block-range bounds including checked-overflow cases, the C-schema conversion failure with both outputs clear, and the panic barrier;ninja docswith warnings as errors succeeded at the merge head, whose public header is unchanged since.src/ipc.rsgoes from 20 missed lines to 5, and the total from 90.85% to 91.32% (2882/3156). On the CI line set that is about 2801/3069 ≈ 91.3% against the 90.79% baseline. The five lines that remain are the negative-length guard, which a valid footer cannot reach, the panic path, and one?continuation line.ninja docs(Doxygen + Sphinx with warnings as errors) succeeded at the merge head.485081ein a scratch worktree with only the falliblenprobesline adapted.Hosted CI is running on the new head; the vector projection assertion that failed on the previous head (
_distanceis added by the SDK after the projected column) is corrected.