Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
with:
components: clippy
- uses: Swatinem/rust-cache@v2
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Clippy
run: cargo clippy --all-targets -- -D warnings

Expand All @@ -52,6 +54,8 @@ jobs:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: Swatinem/rust-cache@v2
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Run tests
run: cargo test
- name: Run C/C++ compilation tests
Expand All @@ -65,6 +69,8 @@ jobs:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: Swatinem/rust-cache@v2
- name: Install dependencies
run: brew install protobuf
- name: Run tests
run: cargo test
- name: Run C/C++ compilation tests
Expand All @@ -78,6 +84,8 @@ jobs:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: Swatinem/rust-cache@v2
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Check documentation
run: RUSTDOCFLAGS="-D warnings" cargo doc --no-deps

Expand All @@ -91,6 +99,8 @@ jobs:
with:
toolchain: "1.91.0"
- uses: Swatinem/rust-cache@v2
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Check MSRV
run: cargo check --all-targets

Expand Down
29 changes: 29 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# AGENTS.md

## Structure
Rust FFI source: `src/`
C header (stable ABI): `include/lance.h`
C++ RAII wrappers (header-only): `include/lance.hpp`
Tests (Rust): `tests/c_api_test.rs`
Tests (C/C++): `tests/cpp/`
Historical test data: `test_data/`

## Commands
check: `cargo check --all-targets`
format: `cargo fmt`
lint: `cargo clippy --all-targets -- -D warnings`
test: `cargo test`
test C/C++ compilation: `cargo test --test compile_and_run_test -- --ignored`

## Key Patterns
- Opaque handles with `lance_*_open`/`lance_*_close` lifecycle.
- Thread-local error handling via `ffi_try!` macro.
- Arrow C Data Interface for zero-copy data exchange.
- `panic = "abort"` in release to prevent unwinding across FFI.

## Adding New APIs
1. Add `extern "C"` function in `src/`.
2. Add declaration to `include/lance.h`.
3. Add C++ wrapper to `include/lance.hpp`.
4. Add test in `tests/c_api_test.rs`.

1 change: 1 addition & 0 deletions CLAUDE.md
2 changes: 1 addition & 1 deletion src/async_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! sequentially, avoiding reentrancy and Tokio thread blocking.

use std::ffi::c_void;
use std::sync::{mpsc, LazyLock};
use std::sync::{LazyLock, mpsc};

/// C callback function pointer type for async operations.
/// - `ctx`: opaque pointer passed back to the caller
Expand Down
4 changes: 2 additions & 2 deletions src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use std::sync::Arc;
use arrow::ffi::FFI_ArrowSchema;
use arrow::ffi_stream::FFI_ArrowArrayStream;
use arrow_schema::Schema as ArrowSchema;
use lance::dataset::builder::DatasetBuilder;
use lance::Dataset;
use lance::dataset::builder::DatasetBuilder;
use lance_core::Result;

use crate::error::{ffi_try, set_last_error, LanceErrorCode};
use crate::error::{LanceErrorCode, ffi_try, set_last_error};
use crate::helpers;
use crate::runtime::block_on;

Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! the caller retrieves the error code and message from thread-local storage.

use std::cell::RefCell;
use std::ffi::{c_char, CString};
use std::ffi::{CString, c_char};
use std::ptr;

/// Error codes returned by `lance_last_error_code()`.
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! C string parsing utilities.

use std::collections::HashMap;
use std::ffi::{c_char, CStr};
use std::ffi::{CStr, c_char};

use lance_core::{Error, Result};
use snafu::location;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ mod scanner;
pub use batch::*;
pub use dataset::*;
pub use error::{
lance_free_string, lance_last_error_code, lance_last_error_message, LanceErrorCode,
LanceErrorCode, lance_free_string, lance_last_error_code, lance_last_error_message,
};
pub use scanner::*;
30 changes: 15 additions & 15 deletions src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
use arrow::ffi_stream::FFI_ArrowArrayStream;
use arrow_schema::SchemaRef;
use futures::{Stream, StreamExt};
use lance::dataset::scanner::DatasetRecordBatchStream;
use lance::Dataset;
use lance::dataset::scanner::DatasetRecordBatchStream;
use lance_core::Result;
use lance_io::ffi::to_ffi_arrow_array_stream;
use lance_io::stream::RecordBatchStream;

use crate::async_dispatcher::{self, LanceCallback};
use crate::batch::LanceBatch;
use crate::dataset::LanceDataset;
use crate::error::{clear_last_error, ffi_try, set_lance_error, set_last_error, LanceErrorCode};
use crate::error::{LanceErrorCode, clear_last_error, ffi_try, set_lance_error, set_last_error};
use crate::helpers;
use crate::runtime::{block_on, RT};
use crate::runtime::{RT, block_on};

/// Opaque scanner handle. Stores configuration until stream materialization.
pub struct LanceScanner {
Expand Down Expand Up @@ -294,12 +294,12 @@ pub unsafe extern "C" fn lance_scanner_next(
let s = unsafe { &mut *scanner };

// Lazily materialize the stream on first call.
if s.stream.is_none() {
if let Err(err) = s.materialize_stream() {
set_lance_error(&err);
unsafe { *out = ptr::null_mut() };
return -1;
}
if s.stream.is_none()
&& let Err(err) = s.materialize_stream()
{
set_lance_error(&err);
unsafe { *out = ptr::null_mut() };
return -1;
}

let stream = s.stream.as_mut().unwrap();
Expand Down Expand Up @@ -431,12 +431,12 @@ pub unsafe extern "C" fn lance_scanner_poll_next(
let s = unsafe { &mut *scanner };

// Lazily materialize the stream.
if s.stream.is_none() {
if let Err(err) = s.materialize_stream() {
set_lance_error(&err);
unsafe { *out = ptr::null_mut() };
return LancePollStatus::Error;
}
if s.stream.is_none()
&& let Err(err) = s.materialize_stream()
{
set_lance_error(&err);
unsafe { *out = ptr::null_mut() };
return LancePollStatus::Error;
}

let stream = s.stream.as_mut().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion tests/c_api_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use std::ffi::CString;
use std::ptr;
use std::sync::Arc;

use arrow::ffi::from_ffi;
use arrow::ffi::FFI_ArrowSchema;
use arrow::ffi::from_ffi;
use arrow::ffi_stream::ArrowArrayStreamReader;
use arrow::ffi_stream::FFI_ArrowArrayStream;
use arrow::record_batch::RecordBatchReader;
Expand Down
Loading