[Rust] Re-export WriteMode from lancedb instead of lance (#257)

`Table::add(.., mode: WriteMode)`, which is a public API, currently uses
the WriteMode exported from `lance`. Re-export it to lancedb so that the
pub API looks better.
This commit is contained in:
Lei Xu
2023-07-05 18:20:31 -07:00
committed by GitHub
parent 3c46d7f268
commit d701947f0b
3 changed files with 16 additions and 6 deletions

View File

@@ -239,7 +239,7 @@ fn table_create(mut cx: FunctionContext) -> JsResult<JsPromise> {
"overwrite" => WriteMode::Overwrite,
"append" => WriteMode::Append,
"create" => WriteMode::Create,
_ => return cx.throw_error("Table::create only supports 'overwrite' and 'create' modes")
_ => return cx.throw_error("Table::create only supports 'overwrite' and 'create' modes"),
};
let mut params = WriteParams::default();
params.mode = mode;
@@ -255,7 +255,9 @@ fn table_create(mut cx: FunctionContext) -> JsResult<JsPromise> {
batches.into_iter().map(Ok),
schema,
));
let table_rst = database.create_table(&table_name, batch_reader, Some(params)).await;
let table_rst = database
.create_table(&table_name, batch_reader, Some(params))
.await;
deferred.settle_with(&channel, move |mut cx| {
let table = Arc::new(Mutex::new(

View File

@@ -19,3 +19,6 @@ pub mod query;
pub mod table;
pub use database::Database;
pub use table::Table;
pub use lance::dataset::WriteMode;

View File

@@ -16,12 +16,13 @@ use std::path::Path;
use std::sync::Arc;
use arrow_array::{Float32Array, RecordBatchReader};
use lance::dataset::{Dataset, ReadParams, WriteMode, WriteParams};
use lance::dataset::{Dataset, ReadParams, WriteParams};
use lance::index::IndexType;
use snafu::prelude::*;
use crate::error::{Error, InvalidTableNameSnafu, Result};
use crate::index::vector::VectorIndexBuilder;
use crate::WriteMode;
use crate::query::Query;
pub const VECTOR_COLUMN_NAME: &str = "vector";
@@ -305,12 +306,16 @@ mod tests {
let mut table = Table::create(&uri, "test", batches, None).await.unwrap();
assert_eq!(table.count_rows().await.unwrap(), 10);
let new_batches: Box<dyn RecordBatchReader> =
Box::new(RecordBatchIterator::new(vec![RecordBatch::try_new(
let new_batches: Box<dyn RecordBatchReader> = Box::new(RecordBatchIterator::new(
vec![RecordBatch::try_new(
schema.clone(),
vec![Arc::new(Int32Array::from_iter_values(100..110))],
)
.unwrap()].into_iter().map(Ok), schema.clone()));
.unwrap()]
.into_iter()
.map(Ok),
schema.clone(),
));
table.add(new_batches, None).await.unwrap();
assert_eq!(table.count_rows().await.unwrap(), 20);