From d99a5d4e91dc7a4c4a3b18a27ab97d6bc7fb6479 Mon Sep 17 00:00:00 2001 From: Mohammad Dashti Date: Thu, 14 May 2026 19:50:34 -0700 Subject: [PATCH] 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. --- src/aggregation/agg_req.rs | 11 ++++++++--- src/aggregation/agg_tests.rs | 6 ++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/aggregation/agg_req.rs b/src/aggregation/agg_req.rs index 8b021b656..7b9c14af6 100644 --- a/src/aggregation/agg_req.rs +++ b/src/aggregation/agg_req.rs @@ -121,9 +121,14 @@ pub fn get_fast_field_names(aggs: &Aggregations) -> HashSet { /// 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 { /// /// // 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<()> { diff --git a/src/aggregation/agg_tests.rs b/src/aggregation/agg_tests.rs index 3042753cb..09d9752e9 100644 --- a/src/aggregation/agg_tests.rs +++ b/src/aggregation/agg_tests.rs @@ -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()); }