MCPcopy Create free account
hub / github.com/apache/datafusion / create_groups_accumulator

Method create_groups_accumulator

datafusion/functions-aggregate/src/average.rs:347–488  ·  view source on GitHub ↗
(
        &self,
        args: AccumulatorArgs,
    )

Source from the content-addressed store, hash-verified

345 }
346
347 fn create_groups_accumulator(
348 &self,
349 args: AccumulatorArgs,
350 ) -> Result<Box<dyn GroupsAccumulator>> {
351 use DataType::*;
352
353 let data_type = args.expr_fields[0].data_type();
354
355 // instantiate specialized accumulator based for the type
356 match (data_type, args.return_field.data_type()) {
357 (Float64, Float64) => {
358 Ok(Box::new(AvgGroupsAccumulator::<Float64Type, _>::new(
359 data_type,
360 args.return_field.data_type(),
361 |sum: f64, count: u64| Ok(sum / count as f64),
362 )))
363 }
364 (
365 Decimal32(_sum_precision, sum_scale),
366 Decimal32(target_precision, target_scale),
367 ) => {
368 let decimal_averager = DecimalAverager::<Decimal32Type>::try_new(
369 *sum_scale,
370 *target_precision,
371 *target_scale,
372 )?;
373
374 let avg_fn =
375 move |sum: i32, count: u64| decimal_averager.avg(sum, count as i32);
376
377 Ok(Box::new(AvgGroupsAccumulator::<Decimal32Type, _>::new(
378 data_type,
379 args.return_field.data_type(),
380 avg_fn,
381 )))
382 }
383 (
384 Decimal64(_sum_precision, sum_scale),
385 Decimal64(target_precision, target_scale),
386 ) => {
387 let decimal_averager = DecimalAverager::<Decimal64Type>::try_new(
388 *sum_scale,
389 *target_precision,
390 *target_scale,
391 )?;
392
393 let avg_fn =
394 move |sum: i64, count: u64| decimal_averager.avg(sum, count as i64);
395
396 Ok(Box::new(AvgGroupsAccumulator::<Decimal64Type, _>::new(
397 data_type,
398 args.return_field.data_type(),
399 avg_fn,
400 )))
401 }
402 (
403 Decimal128(_sum_precision, sum_scale),
404 Decimal128(target_precision, target_scale),

Callers

nothing calls this directly

Calls 4

newFunction · 0.85
avgMethod · 0.80
data_typeMethod · 0.45
return_typeMethod · 0.45

Tested by

no test coverage detected