Rename validate_aggregation_fields to validate_aggregation_fields_exist

Applies @PSeitz's review suggestion to make the function name more
descriptive of what it checks. Also adds a doc note clarifying why
validation is opt-in rather than enforced by default.
This commit is contained in:
Mohammad Dashti
2026-05-14 19:50:34 -07:00
committed by PSeitz
parent 2de6f075ce
commit d99a5d4e91
2 changed files with 12 additions and 5 deletions

View File

@@ -121,9 +121,14 @@ pub fn get_fast_field_names(aggs: &Aggregations) -> HashSet<String> {
/// This is a convenience function for upfront validation before executing aggregations.
/// Returns an error if any field doesn't exist or is not a fast field.
///
/// Validation is intentionally opt-in rather than baked into aggregation execution: the
/// default lenient behavior (returning empty results for missing fields) supports
/// schema evolution and federated queries where the same request runs against segments
/// or indices with different schemas.
///
/// # Example
/// ```
/// use tantivy::aggregation::agg_req::{Aggregations, validate_aggregation_fields};
/// use tantivy::aggregation::agg_req::{Aggregations, validate_aggregation_fields_exist};
/// use tantivy::schema::{Schema, FAST};
/// use tantivy::Index;
///
@@ -144,12 +149,12 @@ pub fn get_fast_field_names(aggs: &Aggregations) -> HashSet<String> {
///
/// // Validate fields before executing
/// for segment_reader in searcher.segment_readers() {
/// validate_aggregation_fields(&agg_req, segment_reader)?;
/// validate_aggregation_fields_exist(&agg_req, segment_reader)?;
/// }
/// # Ok(())
/// # }
/// ```
pub fn validate_aggregation_fields(
pub fn validate_aggregation_fields_exist(
aggs: &Aggregations,
reader: &crate::SegmentReader,
) -> crate::Result<()> {

View File

@@ -1455,7 +1455,8 @@ fn test_aggregation_field_validation_helper() {
)
.unwrap();
let result = crate::aggregation::agg_req::validate_aggregation_fields(&agg_req, segment_reader);
let result =
crate::aggregation::agg_req::validate_aggregation_fields_exist(&agg_req, segment_reader);
assert!(result.is_err());
match result {
Err(crate::TantivyError::FieldNotFound(field_name)) => {
@@ -1474,6 +1475,7 @@ fn test_aggregation_field_validation_helper() {
)
.unwrap();
let result = crate::aggregation::agg_req::validate_aggregation_fields(&agg_req, segment_reader);
let result =
crate::aggregation::agg_req::validate_aggregation_fields_exist(&agg_req, segment_reader);
assert!(result.is_ok());
}