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

Method single_value

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

If the interval has collapsed to a single value, return that value. Otherwise, returns `None`. # Examples ``` use datafusion_common::ScalarValue; use datafusion_expr_common::interval_arithmetic::Interval; use datafusion_expr_common::interval_arithmetic::NullableInterval; let interval = NullableInterval::from(ScalarValue::Int32(Some(4))); assert_eq!(interval.single_value(), Some(ScalarValue::Int

(&self)

Source from the content-addressed store, hash-verified

2237 /// assert_eq!(interval.single_value(), None);
2238 /// ```
2239 pub fn single_value(&self) -> Option<ScalarValue> {
2240 match self {
2241 Self::Null { datatype } => {
2242 Some(ScalarValue::try_from(datatype).unwrap_or(ScalarValue::Null))
2243 }
2244 Self::MaybeNull { values } | Self::NotNull { values }
2245 if values.lower == values.upper && !values.lower.is_null() =>
2246 {
2247 Some(values.lower.clone())
2248 }
2249 _ => None,
2250 }
2251 }
2252}
2253
2254#[cfg(test)]

Callers 1

rewrite_exprFunction · 0.80

Calls 2

is_nullMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected