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

Method apply_operator

datafusion/expr-common/src/interval_arithmetic.rs:2112–2163  ·  view source on GitHub ↗

Apply the given operator to this interval and the given interval. # Examples ``` use datafusion_common::ScalarValue; use datafusion_expr_common::interval_arithmetic::Interval; use datafusion_expr_common::interval_arithmetic::NullableInterval; use datafusion_expr_common::operator::Operator; // 4 > 3 -> true let lhs = NullableInterval::from(ScalarValue::Int32(Some(4))); let rhs = NullableInterval

(&self, op: &Operator, rhs: &Self)

Source from the content-addressed store, hash-verified

2110 /// );
2111 /// ```
2112 pub fn apply_operator(&self, op: &Operator, rhs: &Self) -> Result<Self> {
2113 match op {
2114 Operator::IsDistinctFrom => {
2115 let values = match (self, rhs) {
2116 // NULL is distinct from NULL -> False
2117 (Self::Null { .. }, Self::Null { .. }) => Interval::FALSE,
2118 // x is distinct from y -> x != y,
2119 // if at least one of them is never null.
2120 (Self::NotNull { .. }, _) | (_, Self::NotNull { .. }) => {
2121 let lhs_values = self.values();
2122 let rhs_values = rhs.values();
2123 match (lhs_values, rhs_values) {
2124 (Some(lhs_values), Some(rhs_values)) => {
2125 lhs_values.equal(rhs_values)?.not()?
2126 }
2127 (Some(_), None) | (None, Some(_)) => Interval::TRUE,
2128 (None, None) => unreachable!("Null case handled above"),
2129 }
2130 }
2131 _ => Interval::TRUE_OR_FALSE,
2132 };
2133 // IsDistinctFrom never returns null.
2134 Ok(Self::NotNull { values })
2135 }
2136 Operator::IsNotDistinctFrom => self
2137 .apply_operator(&Operator::IsDistinctFrom, rhs)
2138 .map(|i| i.not())?,
2139 Operator::And => self.and(rhs),
2140 Operator::Or => self.or(rhs),
2141 _ => {
2142 if let (Some(left_values), Some(right_values)) =
2143 (self.values(), rhs.values())
2144 {
2145 let values = apply_operator(op, left_values, right_values)?;
2146 match (self, rhs) {
2147 (Self::NotNull { .. }, Self::NotNull { .. }) => {
2148 Ok(Self::NotNull { values })
2149 }
2150 _ => Ok(Self::MaybeNull { values }),
2151 }
2152 } else if op.supports_propagation() {
2153 Ok(Self::Null {
2154 datatype: DataType::Boolean,
2155 })
2156 } else {
2157 Ok(Self::Null {
2158 datatype: self.data_type(),
2159 })
2160 }
2161 }
2162 }
2163 }
2164
2165 /// Decide if this interval is a superset of, overlaps with, or
2166 /// disjoint with `other` by returning `[true, true]`, `[false, true]` or

Callers 1

rewrite_binary_exprFunction · 0.80

Calls 9

apply_operatorFunction · 0.85
equalMethod · 0.80
supports_propagationMethod · 0.80
valuesMethod · 0.45
notMethod · 0.45
mapMethod · 0.45
andMethod · 0.45
orMethod · 0.45
data_typeMethod · 0.45

Tested by

no test coverage detected