mod record;
mod simple;
pub(crate) use record::locate_file_groups;
pub use record::{RecordIndex, is_record_index_enabled};
pub use simple::SimpleIndex;
use std::collections::HashMap;
use crate::Result;
use crate::table::Table;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct HoodieKey {
pub record_key: String,
pub partition_path: String,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct RecordLocation {
pub file_id: String,
pub instant_time: String,
pub partition_path: String,
}
#[allow(async_fn_in_trait)]
pub trait HoodieIndex {
async fn tag_location(
&self,
table: &Table,
keys: &[HoodieKey],
) -> Result<HashMap<HoodieKey, Option<RecordLocation>>>;
}
pub enum TableIndex {
Record(RecordIndex),
Simple(SimpleIndex),
}
impl HoodieIndex for TableIndex {
async fn tag_location(
&self,
table: &Table,
keys: &[HoodieKey],
) -> Result<HashMap<HoodieKey, Option<RecordLocation>>> {
match self {
Self::Record(index) => index.tag_location(table, keys).await,
Self::Simple(index) => index.tag_location(table, keys).await,
}
}
}
pub fn for_table(table: &Table) -> TableIndex {
if is_record_index_enabled(table) {
TableIndex::Record(RecordIndex)
} else {
TableIndex::Simple(SimpleIndex)
}
}
pub async fn for_table_checked(table: &Table) -> TableIndex {
if record::record_index_has_file_groups(table).await {
TableIndex::Record(RecordIndex)
} else {
TableIndex::Simple(SimpleIndex)
}
}