Skip to content

Commit 25d44fc

Browse files
Revert "remove unused columnar api (#2742)" (#2748)
* Revert "remove unused columnar api (#2742)" This reverts commit 8725594. * Clippy comment + removing fill_vals --------- Co-authored-by: Paul Masurel <[email protected]>
1 parent 842fe92 commit 25d44fc

File tree

5 files changed

+60
-22
lines changed

5 files changed

+60
-22
lines changed

columnar/benches/bench_access.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,26 @@ fn bench_group(mut runner: InputGroup<Column>) {
4343
}
4444
black_box(sum);
4545
});
46+
runner.register("access_first_vals", |column| {
47+
let mut sum = 0;
48+
const BLOCK_SIZE: usize = 32;
49+
let mut docs = vec![0; BLOCK_SIZE];
50+
let mut buffer = vec![None; BLOCK_SIZE];
51+
for i in (0..NUM_DOCS).step_by(BLOCK_SIZE) {
52+
// fill docs
53+
#[allow(clippy::needless_range_loop)]
54+
for idx in 0..BLOCK_SIZE {
55+
docs[idx] = idx as u32 + i;
56+
}
57+
58+
column.first_vals(&docs, &mut buffer);
59+
for val in buffer.iter() {
60+
let Some(val) = val else { continue };
61+
sum += *val;
62+
}
63+
}
64+
65+
black_box(sum);
66+
});
4667
runner.run();
4768
}

columnar/src/column/mod.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use serialize::{
1414
serialize_column_mappable_to_u128,
1515
};
1616

17-
use crate::column_index::ColumnIndex;
17+
use crate::column_index::{ColumnIndex, Set};
1818
use crate::column_values::monotonic_mapping::StrictlyMonotonicMappingToInternal;
1919
use crate::column_values::{ColumnValues, monotonic_map_column};
2020
use crate::{Cardinality, DocId, EmptyColumnValues, MonotonicallyMappableToU64, RowId};
@@ -89,6 +89,31 @@ impl<T: PartialOrd + Copy + Debug + Send + Sync + 'static> Column<T> {
8989
self.values_for_doc(row_id).next()
9090
}
9191

92+
/// Load the first value for each docid in the provided slice.
93+
#[inline]
94+
pub fn first_vals(&self, docids: &[DocId], output: &mut [Option<T>]) {
95+
match &self.index {
96+
ColumnIndex::Empty { .. } => {}
97+
ColumnIndex::Full => self.values.get_vals_opt(docids, output),
98+
ColumnIndex::Optional(optional_index) => {
99+
for (i, docid) in docids.iter().enumerate() {
100+
output[i] = optional_index
101+
.rank_if_exists(*docid)
102+
.map(|rowid| self.values.get_val(rowid));
103+
}
104+
}
105+
ColumnIndex::Multivalued(multivalued_index) => {
106+
for (i, docid) in docids.iter().enumerate() {
107+
let range = multivalued_index.range(*docid);
108+
let is_empty = range.start == range.end;
109+
if !is_empty {
110+
output[i] = Some(self.values.get_val(range.start));
111+
}
112+
}
113+
}
114+
}
115+
}
116+
92117
/// Translates a block of docids to row_ids.
93118
///
94119
/// returns the row_ids and the matching docids on the same index

src/fastfield/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -726,24 +726,22 @@ mod tests {
726726
.column_opt::<DateTime>("multi_date")
727727
.unwrap()
728728
.unwrap();
729+
729730
{
730-
let mut dates = Vec::new();
731731
assert_eq!(date_fast_field.get_val(0).into_timestamp_nanos(), 1i64);
732-
dates.extend(dates_fast_field.values_for_doc(0));
732+
let dates: Vec<DateTime> = dates_fast_field.values_for_doc(0u32).collect();
733733
assert_eq!(dates.len(), 2);
734734
assert_eq!(dates[0].into_timestamp_nanos(), 2i64);
735735
assert_eq!(dates[1].into_timestamp_nanos(), 3i64);
736736
}
737737
{
738-
let mut dates = Vec::new();
739738
assert_eq!(date_fast_field.get_val(1).into_timestamp_nanos(), 4i64);
740-
dates.extend(dates_fast_field.values_for_doc(1));
739+
let dates: Vec<DateTime> = dates_fast_field.values_for_doc(1u32).collect();
741740
assert!(dates.is_empty());
742741
}
743742
{
744-
let mut dates = Vec::new();
745743
assert_eq!(date_fast_field.get_val(2).into_timestamp_nanos(), 0i64);
746-
dates.extend(dates_fast_field.values_for_doc(2));
744+
let dates: Vec<DateTime> = dates_fast_field.values_for_doc(2u32).collect();
747745
assert_eq!(dates.len(), 2);
748746
assert_eq!(dates[0].into_timestamp_nanos(), 5i64);
749747
assert_eq!(dates[1].into_timestamp_nanos(), 6i64);

src/query/range_query/range_query.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,7 @@ mod tests {
268268
use crate::indexer::NoMergePolicy;
269269
use crate::query::range_query::fast_field_range_doc_set::RangeDocSet;
270270
use crate::query::range_query::range_query::InvertedIndexRangeQuery;
271-
use crate::query::{
272-
AllScorer, BitSetDocSet, ConstScorer, EmptyScorer, EnableScoring, Query, QueryParser,
273-
};
271+
use crate::query::{AllScorer, ConstScorer, EmptyScorer, EnableScoring, Query, QueryParser};
274272
use crate::schema::{
275273
Field, IntoIpv6Addr, Schema, TantivyDocument, FAST, INDEXED, STORED, TEXT,
276274
};

src/query/term_query/term_weight.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ pub struct TermWeight {
1818
}
1919

2020
enum TermOrEmptyOrAllScorer {
21-
TermScorer(TermScorer),
21+
TermScorer(Box<TermScorer>),
2222
Empty,
2323
AllMatch(AllScorer),
2424
}
2525

2626
impl TermOrEmptyOrAllScorer {
2727
pub fn into_boxed_scorer(self) -> Box<dyn Scorer> {
2828
match self {
29-
TermOrEmptyOrAllScorer::TermScorer(scorer) => Box::new(scorer),
29+
TermOrEmptyOrAllScorer::TermScorer(scorer) => scorer,
3030
TermOrEmptyOrAllScorer::Empty => Box::new(EmptyScorer),
3131
TermOrEmptyOrAllScorer::AllMatch(scorer) => Box::new(scorer),
3232
}
@@ -48,9 +48,7 @@ impl Weight for TermWeight {
4848
explanation.add_context(format!("Term={:?}", self.term,));
4949
Ok(explanation)
5050
}
51-
TermOrEmptyOrAllScorer::Empty => {
52-
return Err(does_not_match(doc));
53-
}
51+
TermOrEmptyOrAllScorer::Empty => Err(does_not_match(doc)),
5452
TermOrEmptyOrAllScorer::AllMatch(_) => AllWeight.explain(reader, doc),
5553
}
5654
}
@@ -75,7 +73,7 @@ impl Weight for TermWeight {
7573
) -> crate::Result<()> {
7674
match self.specialized_scorer(reader, 1.0)? {
7775
TermOrEmptyOrAllScorer::TermScorer(mut term_scorer) => {
78-
for_each_scorer(&mut term_scorer, callback);
76+
for_each_scorer(&mut *term_scorer, callback);
7977
}
8078
TermOrEmptyOrAllScorer::Empty => {}
8179
TermOrEmptyOrAllScorer::AllMatch(mut all_scorer) => {
@@ -127,7 +125,7 @@ impl Weight for TermWeight {
127125
match specialized_scorer {
128126
TermOrEmptyOrAllScorer::TermScorer(term_scorer) => {
129127
crate::query::boolean_query::block_wand_single_scorer(
130-
term_scorer,
128+
*term_scorer,
131129
threshold,
132130
callback,
133131
);
@@ -173,7 +171,7 @@ impl TermWeight {
173171
) -> crate::Result<Option<TermScorer>> {
174172
let scorer = self.specialized_scorer(reader, boost)?;
175173
Ok(match scorer {
176-
TermOrEmptyOrAllScorer::TermScorer(scorer) => Some(scorer),
174+
TermOrEmptyOrAllScorer::TermScorer(scorer) => Some(*scorer),
177175
_ => None,
178176
})
179177
}
@@ -203,10 +201,8 @@ impl TermWeight {
203201

204202
let fieldnorm_reader = self.fieldnorm_reader(reader)?;
205203
let similarity_weight = self.similarity_weight.boost_by(boost);
206-
Ok(TermOrEmptyOrAllScorer::TermScorer(TermScorer::new(
207-
segment_postings,
208-
fieldnorm_reader,
209-
similarity_weight,
204+
Ok(TermOrEmptyOrAllScorer::TermScorer(Box::new(
205+
TermScorer::new(segment_postings, fieldnorm_reader, similarity_weight),
210206
)))
211207
}
212208

0 commit comments

Comments
 (0)