@@ -222,6 +222,12 @@ impl PercentilesCollector {
222222 self . sketch . add ( val) ;
223223 }
224224
225+ /// Encode the underlying DDSketch to Java-compatible binary format
226+ /// for cross-language serialization with Java consumers.
227+ pub fn to_sketch_bytes ( & self ) -> Vec < u8 > {
228+ self . sketch . to_java_bytes ( )
229+ }
230+
225231 pub ( crate ) fn merge_fruits ( & mut self , right : PercentilesCollector ) -> crate :: Result < ( ) > {
226232 self . sketch . merge ( & right. sketch ) . map_err ( |err| {
227233 TantivyError :: AggregationError ( AggregationError :: InternalError ( format ! (
@@ -325,7 +331,7 @@ mod tests {
325331 use crate :: aggregation:: AggregationCollector ;
326332 use crate :: query:: AllQuery ;
327333 use crate :: schema:: { Schema , FAST } ;
328- use crate :: Index ;
334+ use crate :: { assert_nearly_equals , Index } ;
329335
330336 #[ test]
331337 fn test_aggregation_percentiles_empty_index ( ) -> crate :: Result < ( ) > {
@@ -608,12 +614,16 @@ mod tests {
608614 let res = exec_request_with_query ( agg_req, & index, None ) ?;
609615 assert_eq ! ( res[ "range_with_stats" ] [ "buckets" ] [ 0 ] [ "doc_count" ] , 3 ) ;
610616
611- assert_eq ! (
612- res[ "range_with_stats" ] [ "buckets" ] [ 0 ] [ "percentiles" ] [ "values" ] [ "1.0" ] ,
617+ assert_nearly_equals ! (
618+ res[ "range_with_stats" ] [ "buckets" ] [ 0 ] [ "percentiles" ] [ "values" ] [ "1.0" ]
619+ . as_f64( )
620+ . unwrap( ) ,
613621 5.0028295751107414
614622 ) ;
615- assert_eq ! (
616- res[ "range_with_stats" ] [ "buckets" ] [ 0 ] [ "percentiles" ] [ "values" ] [ "99.0" ] ,
623+ assert_nearly_equals ! (
624+ res[ "range_with_stats" ] [ "buckets" ] [ 0 ] [ "percentiles" ] [ "values" ] [ "99.0" ]
625+ . as_f64( )
626+ . unwrap( ) ,
617627 10.07469668951144
618628 ) ;
619629
@@ -659,8 +669,14 @@ mod tests {
659669
660670 let res = exec_request_with_query ( agg_req, & index, None ) ?;
661671
662- assert_eq ! ( res[ "percentiles" ] [ "values" ] [ "1.0" ] , 5.0028295751107414 ) ;
663- assert_eq ! ( res[ "percentiles" ] [ "values" ] [ "99.0" ] , 10.07469668951144 ) ;
672+ assert_nearly_equals ! (
673+ res[ "percentiles" ] [ "values" ] [ "1.0" ] . as_f64( ) . unwrap( ) ,
674+ 5.0028295751107414
675+ ) ;
676+ assert_nearly_equals ! (
677+ res[ "percentiles" ] [ "values" ] [ "99.0" ] . as_f64( ) . unwrap( ) ,
678+ 10.07469668951144
679+ ) ;
664680
665681 Ok ( ( ) )
666682 }
0 commit comments