feat(rust): create index API improvement (#853)

* Extract a minimal Table interface in Rust SDK
* Make create_index composable in Rust.
* Fix compiling issues from ffi
This commit is contained in:
Lei Xu
2024-01-24 10:05:12 -08:00
committed by GitHub
parent 82cbcf6d07
commit 008e0b1a93
15 changed files with 665 additions and 497 deletions

View File

@@ -16,16 +16,16 @@ use crate::query::Query;
use arrow_ipc::writer::FileWriter;
use napi::bindgen_prelude::*;
use napi_derive::napi;
use vectordb::{ipc::ipc_file_to_batches, table::Table as LanceDBTable};
use vectordb::{ipc::ipc_file_to_batches, table::TableRef};
#[napi]
pub struct Table {
pub(crate) table: LanceDBTable,
pub(crate) table: TableRef,
}
#[napi]
impl Table {
pub(crate) fn new(table: LanceDBTable) -> Self {
pub(crate) fn new(table: TableRef) -> Self {
Self { table }
}
@@ -46,7 +46,7 @@ impl Table {
pub async unsafe fn add(&mut self, buf: Buffer) -> napi::Result<()> {
let batches = ipc_file_to_batches(buf.to_vec())
.map_err(|e| napi::Error::from_reason(format!("Failed to read IPC file: {}", e)))?;
self.table.add(batches, None).await.map_err(|e| {
self.table.add(Box::new(batches), None).await.map_err(|e| {
napi::Error::from_reason(format!(
"Failed to add batches to table {}: {}",
self.table, e