[Rust] Expose Table schema and version in Rust (#312)

This commit is contained in:
Lei Xu
2023-07-14 22:01:23 -07:00
committed by GitHub
parent c62e4ca1eb
commit 04c6814fb1

View File

@@ -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");
}