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

Function compute_mean

datafusion/expr-common/src/statistics.rs:823–848  ·  view source on GitHub ↗
(
    op: &Operator,
    left: &Distribution,
    right: &Distribution,
)

Source from the content-addressed store, hash-verified

821 note = "Part of the unused Statistics V2 framework; see https://github.com/apache/datafusion/pull/22071"
822)]
823pub fn compute_mean(
824 op: &Operator,
825 left: &Distribution,
826 right: &Distribution,
827) -> Result<ScalarValue> {
828 let (left_mean, right_mean) = (left.mean()?, right.mean()?);
829
830 match op {
831 Operator::Plus => return left_mean.add_checked(right_mean),
832 Operator::Minus => return left_mean.sub_checked(right_mean),
833 // Note the independence assumption below:
834 Operator::Multiply => return left_mean.mul_checked(right_mean),
835 // TODO: We can calculate the mean for division when we support reciprocals,
836 // or know the distributions of the operands. For details, see:
837 //
838 // <https://en.wikipedia.org/wiki/Algebra_of_random_variables>
839 // <https://stats.stackexchange.com/questions/185683/distribution-of-ratio-between-two-independent-uniform-random-variables>
840 //
841 // Fall back to an unknown mean value for division:
842 Operator::Divide => {}
843 // Fall back to an unknown mean value for other cases:
844 _ => {}
845 }
846 let target_type = Distribution::target_type(&[&left_mean, &right_mean])?;
847 ScalarValue::try_from(target_type)
848}
849
850/// Computes the median value for the result of the given binary operation on
851/// two unknown quantities represented by its [`Distribution`] objects. Currently,

Callers 1

Calls 4

add_checkedMethod · 0.80
sub_checkedMethod · 0.80
mul_checkedMethod · 0.80
meanMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…