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

Function compute_median

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

Source from the content-addressed store, hash-verified

857 note = "Part of the unused Statistics V2 framework; see https://github.com/apache/datafusion/pull/22071"
858)]
859pub fn compute_median(
860 op: &Operator,
861 left: &Distribution,
862 right: &Distribution,
863) -> Result<ScalarValue> {
864 match (left, right) {
865 (Uniform(lu), Uniform(ru)) => {
866 let (left_median, right_median) = (lu.median()?, ru.median()?);
867 // Under the independence assumption, the result is a symmetric
868 // triangular distribution, so we can simply add/subtract the
869 // median values:
870 match op {
871 Operator::Plus => return left_median.add_checked(right_median),
872 Operator::Minus => return left_median.sub_checked(right_median),
873 // Fall back to an unknown median value for other cases:
874 _ => {}
875 }
876 }
877 // Under the independence assumption, the result is another Gaussian
878 // distribution, so we can simply add/subtract the median values:
879 (Gaussian(lg), Gaussian(rg)) => match op {
880 Operator::Plus => return lg.mean().add_checked(rg.mean()),
881 Operator::Minus => return lg.mean().sub_checked(rg.mean()),
882 // Fall back to an unknown median value for other cases:
883 _ => {}
884 },
885 // Fall back to an unknown median value for other cases:
886 _ => {}
887 }
888
889 let (left_median, right_median) = (left.median()?, right.median()?);
890 let target_type = Distribution::target_type(&[&left_median, &right_median])?;
891 ScalarValue::try_from(target_type)
892}
893
894/// Computes the variance value for the result of the given binary operation on
895/// two unknown quantities represented by their [`Distribution`] objects.

Callers 1

Calls 4

medianMethod · 0.80
add_checkedMethod · 0.80
sub_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…