use std::sync::Arc;
use async_trait::async_trait;
use lance_core::Result;
use crate::{optimize::OptimizeOptions, IndexParams, IndexType};
use lance_table::format::Index;
use uuid::Uuid;
#[async_trait]
pub trait DatasetIndexExt {
async fn create_index(
&mut self,
columns: &[&str],
index_type: IndexType,
name: Option<String>,
params: &dyn IndexParams,
replace: bool,
) -> Result<()>;
async fn load_indices(&self) -> Result<Arc<Vec<Index>>>;
async fn load_index(&self, uuid: &str) -> Result<Option<Index>> {
self.load_indices().await.map(|indices| {
indices
.iter()
.find(|idx| idx.uuid.to_string() == uuid)
.cloned()
})
}
async fn load_indices_by_name(&self, name: &str) -> Result<Vec<Index>> {
self.load_indices().await.map(|indices| {
indices
.iter()
.filter(|idx| idx.name == name)
.cloned()
.collect()
})
}
async fn load_scalar_index_for_column(&self, col: &str) -> Result<Option<Index>>;
async fn optimize_indices(&mut self, options: &OptimizeOptions) -> Result<()>;
async fn index_statistics(&self, index_name: &str) -> Result<String>;
async fn commit_existing_index(
&mut self,
index_name: &str,
column: &str,
index_id: Uuid,
) -> Result<()>;
}