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

Function div_bounds

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

Helper function used for dividing the end-point values of intervals. Caution:** This function contains multiple calls to `unwrap()`, and may return non-standardized interval bounds. Therefore, it should be used with caution. Currently, it is used in contexts where the `DataType` (`dt`) is validated prior to calling this function, and the following interval creation is standardized with `Interval:

(
    dt: &DataType,
    lhs: &ScalarValue,
    rhs: &ScalarValue,
)

Source from the content-addressed store, hash-verified

1144/// (`dt`) is validated prior to calling this function, and the following
1145/// interval creation is standardized with `Interval::new`.
1146fn div_bounds<const UPPER: bool>(
1147 dt: &DataType,
1148 lhs: &ScalarValue,
1149 rhs: &ScalarValue,
1150) -> ScalarValue {
1151 let zero = ScalarValue::new_zero(dt).unwrap();
1152
1153 if (lhs.is_null() || rhs.eq(&zero)) || (dt.is_unsigned_integer() && rhs.is_null()) {
1154 return ScalarValue::try_from(dt).unwrap();
1155 } else if rhs.is_null() {
1156 return zero;
1157 }
1158
1159 match dt {
1160 DataType::Float64 | DataType::Float32 => {
1161 alter_fp_rounding_mode::<UPPER, _>(lhs, rhs, |lhs, rhs| lhs.div(rhs))
1162 }
1163 _ => lhs.div(rhs),
1164 }
1165 .unwrap_or_else(|_| handle_overflow::<UPPER>(dt, Operator::Divide, lhs, rhs))
1166}
1167
1168/// This function handles cases where an operation results in an overflow. Such
1169/// results are converted to an *unbounded endpoint* if:

Callers

nothing calls this directly

Calls 3

is_nullMethod · 0.45
eqMethod · 0.45
divMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…