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,
)
| 1021 | /// share, taken from [`BinaryTypeCoercer::get_result_type`] — this mirrors |
| 1022 | /// what arrow's numeric kernels would produce when computing the operation. |
| 1023 | fn 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. |
| 1046 | pub fn apply_operator(op: &Operator, lhs: &Interval, rhs: &Interval) -> Result<Interval> { |