pub mod immutable_null_index;
pub mod mutable_null_index;
pub mod read_only_null_index;
mod read_ops;
use crate::common::counter::hardware_accumulator::HwMeasurementAcc;
use crate::common::counter::hardware_counter::HardwareCounterCell;
use crate::common::types::PointOffsetType;
use crate::common::universal_io::MmapFile;
pub use immutable_null_index::ImmutableNullIndex;
pub use mutable_null_index::MutableNullIndex;
pub use read_only_null_index::ReadOnlyNullIndex;
pub use read_ops::{NullConditionChecker, NullIndexRead};
use serde_json::Value;
use super::{PayloadFieldIndex, PayloadFieldIndexRead};
use crate::segment::common::flags::roaring_flags::RoaringFlags;
use crate::segment::common::operation_error::{OperationError, OperationResult};
use crate::segment::index::condition_checker::ConditionCheckerEnum;
use crate::segment::index::payload_config::IndexMutability;
use crate::segment::types::FieldCondition;
pub enum NullIndex {
Mutable(MutableNullIndex),
Immutable(ImmutableNullIndex),
}
impl From<MutableNullIndex> for NullIndex {
fn from(value: MutableNullIndex) -> Self {
NullIndex::Mutable(value)
}
}
impl From<ImmutableNullIndex> for NullIndex {
fn from(value: ImmutableNullIndex) -> Self {
NullIndex::Immutable(value)
}
}
impl NullIndex {
pub fn add_point(
&mut self,
id: PointOffsetType,
payload: &[&Value],
hw_counter: &HardwareCounterCell,
) -> OperationResult<()> {
match self {
NullIndex::Mutable(mutable) => mutable.add_point(id, payload, hw_counter),
NullIndex::Immutable(_immutable) => Err(OperationError::service_error(
"Can't add values to immutable null index",
)),
}
}
pub fn remove_point(&mut self, id: PointOffsetType) -> OperationResult<()> {
match self {
NullIndex::Mutable(mutable) => mutable.remove_point(id),
NullIndex::Immutable(immutable) => immutable.remove_point(id),
}
}
pub fn get_mutability_type(&self) -> IndexMutability {
match self {
NullIndex::Mutable(_) => IndexMutability::Mutable,
NullIndex::Immutable(_) => IndexMutability::Immutable,
}
}
}
impl NullIndexRead for NullIndex {
type Flags = RoaringFlags<MmapFile>;
fn has_values_flags(&self) -> &Self::Flags {
match self {
NullIndex::Mutable(m) => m.has_values_flags(),
NullIndex::Immutable(i) => i.has_values_flags(),
}
}
fn is_null_flags(&self) -> &Self::Flags {
match self {
NullIndex::Mutable(m) => m.is_null_flags(),
NullIndex::Immutable(i) => i.is_null_flags(),
}
}
fn total_point_count(&self) -> usize {
match self {
NullIndex::Mutable(m) => m.total_point_count(),
NullIndex::Immutable(i) => i.total_point_count(),
}
}
fn telemetry_index_type(&self) -> &'static str {
match self {
NullIndex::Mutable(m) => m.telemetry_index_type(),
NullIndex::Immutable(i) => i.telemetry_index_type(),
}
}
}
impl PayloadFieldIndexRead for NullIndex {
fn count_indexed_points(&self) -> OperationResult<usize> {
Ok(self.indexed_points_count())
}
fn filter<'a>(
&'a self,
condition: &'a FieldCondition,
_hw_counter: &'a HardwareCounterCell,
) -> OperationResult<Option<Box<dyn Iterator<Item = PointOffsetType> + 'a>>> {
read_ops::filter(self, condition)
}
fn estimate_cardinality(
&self,
condition: &FieldCondition,
_hw_counter: &HardwareCounterCell,
) -> OperationResult<Option<super::CardinalityEstimation>> {
read_ops::estimate_cardinality(self, condition)
}
fn for_each_payload_block(
&self,
_threshold: usize,
_key: crate::segment::types::PayloadKeyType,
_f: &mut dyn FnMut(super::PayloadBlockCondition) -> OperationResult<()>,
) -> OperationResult<()> {
Ok(())
}
fn condition_checker<'a>(
&'a self,
condition: &FieldCondition,
hw_acc: HwMeasurementAcc,
) -> OperationResult<Option<ConditionCheckerEnum<'a>>> {
match self {
NullIndex::Mutable(idx) => idx.condition_checker(condition, hw_acc),
NullIndex::Immutable(idx) => idx.condition_checker(condition, hw_acc),
}
}
}
impl PayloadFieldIndex for NullIndex {
fn wipe(self) -> OperationResult<()> {
match self {
NullIndex::Mutable(mutable) => mutable.wipe(),
NullIndex::Immutable(immutable) => immutable.wipe(),
}
}
fn flusher(&self) -> crate::segment::common::Flusher {
match self {
NullIndex::Mutable(mutable) => mutable.flusher(),
NullIndex::Immutable(immutable) => immutable.flusher(),
}
}
fn files(&self) -> Vec<std::path::PathBuf> {
NullIndexRead::files(self)
}
fn immutable_files(&self) -> Vec<std::path::PathBuf> {
match self {
NullIndex::Mutable(_) => Vec::new(),
NullIndex::Immutable(immutable) => immutable.immutable_files(),
}
}
}