(
op: &Operator,
left: &BernoulliDistribution,
right: &BernoulliDistribution,
)
| 633 | note = "Part of the unused Statistics V2 framework; see https://github.com/apache/datafusion/pull/22071" |
| 634 | )] |
| 635 | pub fn combine_bernoullis( |
| 636 | op: &Operator, |
| 637 | left: &BernoulliDistribution, |
| 638 | right: &BernoulliDistribution, |
| 639 | ) -> Result<BernoulliDistribution> { |
| 640 | let left_p = left.p_value(); |
| 641 | let right_p = right.p_value(); |
| 642 | match op { |
| 643 | Operator::And => match (left_p.is_null(), right_p.is_null()) { |
| 644 | (false, false) => { |
| 645 | BernoulliDistribution::try_new(left_p.mul_checked(right_p)?) |
| 646 | } |
| 647 | (false, true) if left_p.eq(&ScalarValue::new_zero(&left_p.data_type())?) => { |
| 648 | Ok(left.clone()) |
| 649 | } |
| 650 | (true, false) |
| 651 | if right_p.eq(&ScalarValue::new_zero(&right_p.data_type())?) => |
| 652 | { |
| 653 | Ok(right.clone()) |
| 654 | } |
| 655 | _ => { |
| 656 | let dt = Distribution::target_type(&[left_p, right_p])?; |
| 657 | BernoulliDistribution::try_new(ScalarValue::try_from(&dt)?) |
| 658 | } |
| 659 | }, |
| 660 | Operator::Or => match (left_p.is_null(), right_p.is_null()) { |
| 661 | (false, false) => { |
| 662 | let sum = left_p.add_checked(right_p)?; |
| 663 | let product = left_p.mul_checked(right_p)?; |
| 664 | let or_success = sum.sub_checked(product)?; |
| 665 | BernoulliDistribution::try_new(or_success) |
| 666 | } |
| 667 | (false, true) if left_p.eq(&ScalarValue::new_one(&left_p.data_type())?) => { |
| 668 | Ok(left.clone()) |
| 669 | } |
| 670 | (true, false) if right_p.eq(&ScalarValue::new_one(&right_p.data_type())?) => { |
| 671 | Ok(right.clone()) |
| 672 | } |
| 673 | _ => { |
| 674 | let dt = Distribution::target_type(&[left_p, right_p])?; |
| 675 | BernoulliDistribution::try_new(ScalarValue::try_from(&dt)?) |
| 676 | } |
| 677 | }, |
| 678 | _ => { |
| 679 | not_impl_err!("Statistical evaluation only supports AND and OR operators") |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | /// Applies the given operation to the given Gaussian distributions. Currently, |
| 685 | /// this function handles only addition and subtraction operations. If the |
no test coverage detected
searching dependent graphs…