Added Empty ColumnIndex (#1910)

This commit is contained in:
Paul Masurel
2023-02-27 13:59:22 +09:00
committed by GitHub
parent 66ff53b0f4
commit 0a726a0897
4 changed files with 19 additions and 6 deletions

View File

@@ -45,6 +45,7 @@ impl<T: PartialOrd + Copy + Debug + Send + Sync + 'static> Column<T> {
pub fn num_docs(&self) -> RowId {
match &self.idx {
ColumnIndex::Empty { num_docs } => *num_docs,
ColumnIndex::Full => self.values.num_vals(),
ColumnIndex::Optional(optional_index) => optional_index.num_docs(),
ColumnIndex::Multivalued(col_index) => {
@@ -78,17 +79,17 @@ impl<T: PartialOrd + Copy + Debug + Send + Sync + 'static> Column<T> {
&self,
value_range: RangeInclusive<T>,
selected_docid_range: Range<u32>,
docids: &mut Vec<u32>,
doc_ids: &mut Vec<u32>,
) {
// convert passed docid range to row id range
let rowid_range = self.idx.docid_range_to_rowids(selected_docid_range.clone());
// Load rows
self.values
.get_row_ids_for_value_range(value_range, rowid_range, docids);
.get_row_ids_for_value_range(value_range, rowid_range, doc_ids);
// Convert rows to docids
self.idx
.select_batch_in_place(docids, selected_docid_range.start);
.select_batch_in_place(selected_docid_range.start, doc_ids);
}
/// Fils the output vector with the (possibly multiple values that are associated_with
@@ -151,6 +152,7 @@ impl<T: PartialOrd + Debug + Send + Sync + Copy + 'static> ColumnValues<T>
fn num_vals(&self) -> u32 {
match &self.column.idx {
ColumnIndex::Empty { .. } => 0u32,
ColumnIndex::Full => self.column.values.num_vals(),
ColumnIndex::Optional(optional_idx) => optional_idx.num_docs(),
ColumnIndex::Multivalued(multivalue_idx) => multivalue_idx.num_docs(),

View File

@@ -91,6 +91,7 @@ fn iter_num_values<'a>(
return 0u32;
};
match column_index {
ColumnIndex::Empty { .. } => 0u32,
ColumnIndex::Full => 1,
ColumnIndex::Optional(optional_index) => {
u32::from(optional_index.contains(row_addr.row_id))

View File

@@ -55,7 +55,7 @@ impl<'a> Iterable<RowId> for StackedOptionalIndex<'a> {
Some(ColumnIndex::Multivalued(_)) => {
panic!("No multivalued index is allowed when stacking column index");
}
None => Box::new(std::iter::empty()),
None | Some(ColumnIndex::Empty { .. }) => Box::new(std::iter::empty()),
};
rows_it
}),
@@ -74,7 +74,9 @@ fn convert_column_opt_to_multivalued_index<'a>(
num_rows: RowId,
) -> Box<dyn Iterator<Item = RowId> + 'a> {
match column_index_opt {
None => Box::new(iter::repeat(0u32).take(num_rows as usize + 1)),
None | Some(ColumnIndex::Empty { .. }) => {
Box::new(iter::repeat(0u32).take(num_rows as usize + 1))
}
Some(ColumnIndex::Full) => Box::new(0..num_rows + 1),
Some(ColumnIndex::Optional(optional_index)) => {
Box::new(

View File

@@ -14,6 +14,9 @@ use crate::{Cardinality, DocId, RowId};
#[derive(Clone)]
pub enum ColumnIndex {
Empty {
num_docs: u32,
},
Full,
Optional(OptionalIndex),
/// In addition, at index num_rows, an extra value is added
@@ -37,6 +40,7 @@ impl ColumnIndex {
#[inline]
pub fn get_cardinality(&self) -> Cardinality {
match self {
ColumnIndex::Empty { .. } => Cardinality::Optional,
ColumnIndex::Full => Cardinality::Full,
ColumnIndex::Optional(_) => Cardinality::Optional,
ColumnIndex::Multivalued(_) => Cardinality::Multivalued,
@@ -46,6 +50,7 @@ impl ColumnIndex {
/// Returns true if and only if there are at least one value associated to the row.
pub fn has_value(&self, doc_id: DocId) -> bool {
match self {
ColumnIndex::Empty { .. } => false,
ColumnIndex::Full => true,
ColumnIndex::Optional(optional_index) => optional_index.contains(doc_id),
ColumnIndex::Multivalued(multivalued_index) => {
@@ -56,6 +61,7 @@ impl ColumnIndex {
pub fn value_row_ids(&self, doc_id: DocId) -> Range<RowId> {
match self {
ColumnIndex::Empty { .. } => 0..0,
ColumnIndex::Full => doc_id..doc_id + 1,
ColumnIndex::Optional(optional_index) => {
if let Some(val) = optional_index.rank_if_exists(doc_id) {
@@ -70,6 +76,7 @@ impl ColumnIndex {
pub fn docid_range_to_rowids(&self, doc_id: Range<DocId>) -> Range<RowId> {
match self {
ColumnIndex::Empty { .. } => 0..0,
ColumnIndex::Full => doc_id,
ColumnIndex::Optional(optional_index) => {
let row_start = optional_index.rank(doc_id.start);
@@ -88,8 +95,9 @@ impl ColumnIndex {
}
}
pub fn select_batch_in_place(&self, rank_ids: &mut Vec<RowId>, doc_id_start: DocId) {
pub fn select_batch_in_place(&self, doc_id_start: DocId, rank_ids: &mut Vec<RowId>) {
match self {
ColumnIndex::Empty { .. } => {}
ColumnIndex::Full => {
// No need to do anything:
// value_idx and row_idx are the same.