diff --git a/src/aggregation/value_source/jitexpr_value_source/input_column.rs b/src/aggregation/value_source/jitexpr_value_source/input_column.rs index 2027b6f77..dc121ed17 100644 --- a/src/aggregation/value_source/jitexpr_value_source/input_column.rs +++ b/src/aggregation/value_source/jitexpr_value_source/input_column.rs @@ -1,8 +1,6 @@ //! The fast-field columns bound to the inputs of a compiled jitexpr expression. -use columnar::{ - Column, ColumnIndex, DynamicColumn, DynamicColumnHandle, MonotonicallyMappableToU64, -}; +use columnar::{Column, DynamicColumn, DynamicColumnHandle, MonotonicallyMappableToU64}; use jitexpr::types::{VarType, VariableValue}; use super::term_resolver::TermResolver; @@ -11,11 +9,12 @@ use crate::{DocId, TantivyError, COLLECT_BLOCK_BUFFER_LEN}; /// A fast-field column bound to an input of the compiled expression. pub(super) struct InputColumn { - var_type: VarType, - /// Values in their monotonic `u64` mapping. Term ords for a `Str` input. - column: Column, + pub(super) var_type: VarType, + /// Values in their monotonic `u64` mapping. Term ords for a `Str` input. Its index tells + /// which docs have a value. + pub(super) column: Column, /// `first_values[i]` is the first value of `docs[i]`, for the docs of the last block. - first_values: Vec>, + pub(super) first_values: Vec>, /// The terms of `first_values`. Not `TermResolver::None` if and only if `var_type` is `Str`. term_resolver: TermResolver, } @@ -57,20 +56,17 @@ impl InputColumn { } } - pub(super) fn var_type(&self) -> VarType { - self.var_type - } - /// Returns the number of terms of the dictionary of a `Str` input, or `None` for the other /// types. pub(super) fn num_terms(&self) -> Option { self.term_resolver.num_terms() } - /// Loads the first value of each doc of `docs`, without resolving their terms. + /// Loads the first value of each doc of `docs` in `first_values`, without resolving their + /// terms. /// - /// Afterwards, read the values with `first_value`, and their terms with `value_of`: `value` - /// must not be called before the next `load_block`. + /// Afterwards, resolve the terms with `value_of`: `value` must not be called before the next + /// `load_block`. pub(super) fn load_block_values(&mut self, docs: &[DocId]) { // `first_vals` does not write the entries of the docs without a value: we reset them. self.first_values.clear(); @@ -78,20 +74,6 @@ impl InputColumn { self.column.first_vals(docs, &mut self.first_values); } - /// Returns the first value of `docs[doc_pos]` in its monotonic `u64` mapping (a term ord for - /// a `Str` input), for the `docs` of the last `load_block_values` call. - #[inline] - pub(super) fn first_value(&self, doc_pos: usize) -> Option { - self.first_values[doc_pos] - } - - /// Returns the first value of `doc` in its monotonic `u64` mapping, without going through a - /// block. - #[inline] - pub(super) fn first_value_for_doc(&self, doc: DocId) -> Option { - self.column.first(doc) - } - /// Loads the first value of each doc of `docs`. /// /// Panics if the dictionary of a text column is corrupted. @@ -116,29 +98,18 @@ impl InputColumn { } } - /// Returns the value of `doc`, without going through `load_block`. + /// Returns the variable value of `value`, a value of the column in its monotonic `u64` + /// mapping, or null. Resolves the term of a `Str` input outside of the block path. /// /// Invalidates the last `load_block` call: `value` must not be called before the next /// `load_block`. /// /// Panics if the dictionary of a text column is corrupted. #[inline] - pub(super) fn value_for_doc(&mut self, doc: DocId) -> VariableValue<'_> { - let Some(value) = self.column.first(doc) else { + pub(super) fn value_of(&mut self, value: Option) -> VariableValue<'_> { + let Some(value) = value else { return VariableValue::none(); }; - self.value_of(value) - } - - /// Returns the variable value of `value`, a value of the column in its monotonic `u64` - /// mapping. Resolves the term of a `Str` input outside of the block path. - /// - /// Invalidates the last `load_block` call: `value` must not be called before the next - /// `load_block`. - /// - /// Panics if the dictionary of a text column is corrupted. - #[inline] - pub(super) fn value_of(&mut self, value: u64) -> VariableValue<'_> { match self.var_type { VarType::Bool => VariableValue::from(bool::from_u64(value)), VarType::I64 => VariableValue::from(i64::from_u64(value)), @@ -148,9 +119,4 @@ impl InputColumn { VarType::None => VariableValue::none(), } } - - /// Returns the index of the column: which docs have a value. - pub(super) fn column_index(&self) -> &ColumnIndex { - &self.column.index - } } diff --git a/src/aggregation/value_source/jitexpr_value_source/jitexpr_value_source.rs b/src/aggregation/value_source/jitexpr_value_source/jitexpr_value_source.rs index 85be4d58a..931276703 100644 --- a/src/aggregation/value_source/jitexpr_value_source/jitexpr_value_source.rs +++ b/src/aggregation/value_source/jitexpr_value_source/jitexpr_value_source.rs @@ -150,10 +150,7 @@ fn eval_single_input( ) -> Option { let result_type: VarType = compiled_fn.result_type(); let mut args = args.borrow::(); - args.push(match input_value { - Some(value) => input.value_of(value), - None => VariableValue::none(), - }); + args.push(input.value_of(input_value)); // SAFETY: `args` follow the compiled inputs, with their types (precondition). The string is // borrowed from `input`, which is not modified during the call. let result: VariableValue = unsafe { compiled_fn.call(&args) }; @@ -173,7 +170,7 @@ impl JitExprValueSource { // Evaluating the function with inputs of the wrong type is undefined behavior. assert_eq!(compiled_fn.inputs().len(), inputs.len()); for (compiled_input, input) in compiled_fn.inputs().iter().zip(&inputs) { - assert_eq!(compiled_input.r#type, input.var_type()); + assert_eq!(compiled_input.r#type, input.var_type); } let num_inputs = inputs.len(); let evaluation = match inputs.as_slice() { @@ -213,7 +210,7 @@ impl JitExprValueSource { } = self; if let Evaluation::PerTermOrd(results) = evaluation { let input = &mut inputs[0]; - let input_value = input.first_value_for_doc(doc); + let input_value = input.column.first(doc); return results.get_or_eval(input_value, || { eval_single_input(compiled_fn, args, term_dictionary, input, input_value) }); @@ -222,7 +219,7 @@ impl JitExprValueSource { let mut args = args.borrow::(); // Each input is borrowed once: the values can borrow their input. for input in inputs.iter_mut() { - args.push(input.value_for_doc(doc)); + args.push(input.value_of(input.column.first(doc))); } // SAFETY: `args` follow the compiled inputs, with their types (see `new`). The strings // are borrowed from `inputs`, which are not modified during the call. @@ -238,7 +235,7 @@ impl JitExprValueSource { .iter() .zip(&self.inputs) .map(|(compiled_input, input)| { - (compiled_input.variable_name.as_ref(), input.column_index()) + (compiled_input.variable_name.as_ref(), &input.column.index) }) } } @@ -280,7 +277,7 @@ impl ValueSource for JitExprValueSource { // Terms are only resolved for the term ords evaluated for the first time. input.load_block_values(docs); for (doc_pos, &doc) in docs.iter().enumerate() { - let input_value = input.first_value(doc_pos); + let input_value = input.first_values[doc_pos]; let value_opt = results.get_or_eval(input_value, || { eval_single_input(compiled_fn, args, term_dictionary, input, input_value) }); diff --git a/src/aggregation/value_source/jitexpr_value_source/mod.rs b/src/aggregation/value_source/jitexpr_value_source/mod.rs index 9886a29c4..2ffdee755 100644 --- a/src/aggregation/value_source/jitexpr_value_source/mod.rs +++ b/src/aggregation/value_source/jitexpr_value_source/mod.rs @@ -186,7 +186,7 @@ impl JitExprValueSourceProvider { ))); }; let input = InputColumn::open(&handle)?; - if input.var_type() != compiled_input.r#type { + if input.var_type != compiled_input.r#type { return Err(TantivyError::InternalError(format!( "the compiled input `{}` expects {:?}, but its column has type {}", compiled_input.variable_name,