From 04c6814fb1a2f65bc0962beb337f40227426e194 Mon Sep 17 00:00:00 2001 From: Lei Xu Date: Fri, 14 Jul 2023 22:01:23 -0700 Subject: [PATCH] [Rust] Expose Table schema and version in Rust (#312) --- rust/vectordb/src/table.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/rust/vectordb/src/table.rs b/rust/vectordb/src/table.rs index d01ceacd..b4641826 100644 --- a/rust/vectordb/src/table.rs +++ b/rust/vectordb/src/table.rs @@ -16,6 +16,7 @@ use std::path::Path; use std::sync::Arc; use arrow_array::{Float32Array, RecordBatchReader}; +use arrow_schema::SchemaRef; use lance::dataset::{Dataset, ReadParams, WriteParams}; use lance::index::IndexType; use snafu::prelude::*; @@ -144,6 +145,16 @@ impl Table { }) } + /// Schema of this Table. + pub fn schema(&self) -> SchemaRef { + Arc::new(self.dataset.schema().into()) + } + + /// Version of this Table + pub fn version(&self) -> u64 { + self.dataset.version().version + } + /// Create index on the table. pub async fn create_index(&mut self, index_builder: &impl VectorIndexBuilder) -> Result<()> { use lance::index::DatasetIndexExt; @@ -350,10 +361,7 @@ mod tests { ..Default::default() }; - table - .add(new_batches, Some(param)) - .await - .unwrap(); + table.add(new_batches, Some(param)).await.unwrap(); assert_eq!(table.count_rows().await.unwrap(), 10); assert_eq!(table.name, "test"); }