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

Function coerce_operands

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

Coerces two intervals to a common type for the given binary `op` so that downstream interval helpers can operate on a single, consistent data type. Returns `(coerced_lhs, coerced_rhs, common_type)`. Each `coerced_*` is `Some(...)` when a cast was required, and `None` when the original interval already had the common type (the caller should use the original in that case). The returned `common_type

(
    lhs: &Interval,
    rhs: &Interval,
    op: &Operator,
)

Source from the content-addressed store, hash-verified

1021/// share, taken from [`BinaryTypeCoercer::get_result_type`] — this mirrors
1022/// what arrow's numeric kernels would produce when computing the operation.
1023fn coerce_operands(
1024 lhs: &Interval,
1025 rhs: &Interval,
1026 op: &Operator,
1027) -> Result<(Option<Interval>, Option<Interval>, DataType)> {
1028 let lhs_type = lhs.data_type();
1029 let rhs_type = rhs.data_type();
1030 if lhs_type == rhs_type {
1031 return Ok((None, None, lhs_type));
1032 }
1033 let common_type =
1034 BinaryTypeCoercer::new(&lhs_type, op, &rhs_type).get_result_type()?;
1035 let cast_options = CastOptions::default();
1036 let new_lhs = (lhs_type != common_type)
1037 .then(|| lhs.cast_to(&common_type, &cast_options))
1038 .transpose()?;
1039 let new_rhs = (rhs_type != common_type)
1040 .then(|| rhs.cast_to(&common_type, &cast_options))
1041 .transpose()?;
1042 Ok((new_lhs, new_rhs, common_type))
1043}
1044
1045/// Applies the given binary operator the `lhs` and `rhs` arguments.
1046pub fn apply_operator(op: &Operator, lhs: &Interval, rhs: &Interval) -> Result<Interval> {

Callers 2

mulMethod · 0.85
divMethod · 0.85

Calls 4

newFunction · 0.85
get_result_typeMethod · 0.80
data_typeMethod · 0.45
cast_toMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…