From a7d66032aabf82aa219debf531f2934973a7d622 Mon Sep 17 00:00:00 2001 From: Will Jones Date: Thu, 7 Mar 2024 08:33:46 -0800 Subject: [PATCH] fix: Allow converting from NativeTable to Table (#1069) --- rust/ffi/node/src/table.rs | 2 +- rust/lancedb/src/connection.rs | 6 +++--- rust/lancedb/src/ipc.rs | 1 - rust/lancedb/src/table.rs | 9 ++++++++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/rust/ffi/node/src/table.rs b/rust/ffi/node/src/table.rs index 1e0e71a3..9d0013e7 100644 --- a/rust/ffi/node/src/table.rs +++ b/rust/ffi/node/src/table.rs @@ -323,7 +323,7 @@ impl JsTable { .and_then(|val| val.downcast::(&mut cx).ok()) .map(|val| val.value(&mut cx) as i64) .unwrap_or_else(|| 2 * 7 * 24 * 60); // 2 weeks - let older_than = chrono::Duration::minutes(older_than); + let older_than = chrono::Duration::try_minutes(older_than).unwrap(); let delete_unverified: Option = Some( cx.argument_opt(1) .and_then(|val| val.downcast::(&mut cx).ok()) diff --git a/rust/lancedb/src/connection.rs b/rust/lancedb/src/connection.rs index 842539cd..8394879c 100644 --- a/rust/lancedb/src/connection.rs +++ b/rust/lancedb/src/connection.rs @@ -796,10 +796,10 @@ mod tests { let tmp_dir = tempdir().unwrap(); let mut names = Vec::with_capacity(100); for _ in 0..100 { - let name = uuid::Uuid::new_v4().to_string(); + let mut name = uuid::Uuid::new_v4().to_string(); names.push(name.clone()); - let table_name = name + ".lance"; - create_dir_all(tmp_dir.path().join(&table_name)).unwrap(); + name.push_str(".lance"); + create_dir_all(tmp_dir.path().join(&name)).unwrap(); } names.sort(); diff --git a/rust/lancedb/src/ipc.rs b/rust/lancedb/src/ipc.rs index 14cee1f8..79c6fe91 100644 --- a/rust/lancedb/src/ipc.rs +++ b/rust/lancedb/src/ipc.rs @@ -65,7 +65,6 @@ mod tests { use super::*; use arrow_array::{Float32Array, Int64Array, RecordBatch}; - use arrow_ipc::writer::StreamWriter; use arrow_schema::{DataType, Field, Schema}; use std::sync::Arc; diff --git a/rust/lancedb/src/table.rs b/rust/lancedb/src/table.rs index 7dc62fdb..04031e6e 100644 --- a/rust/lancedb/src/table.rs +++ b/rust/lancedb/src/table.rs @@ -504,6 +504,13 @@ impl Table { } } +impl From for Table { + fn from(table: NativeTable) -> Self { + Self { + inner: Arc::new(table), + } + } +} /// A table in a LanceDB database. #[derive(Debug, Clone)] pub struct NativeTable { @@ -1141,7 +1148,7 @@ impl TableInternal for NativeTable { .compaction; stats.prune = self .optimize(OptimizeAction::Prune { - older_than: Duration::days(7), + older_than: Duration::try_days(7).unwrap(), delete_unverified: None, }) .await?