make_downscaler

Function make_downscaler 

Source
fn make_downscaler<I: DecimalType, O: DecimalType>(
    input_precision: u8,
    input_scale: i8,
    output_precision: u8,
    output_scale: i8,
) -> Option<(impl Fn(I::Native) -> Option<O::Native>, Option<impl Fn(I::Native) -> O::Native>)>
where I::Native: DecimalCast + ArrowNativeTypeOp, O::Native: DecimalCast + ArrowNativeTypeOp,
Expand description

Construct closures to downscale decimals from (input_precision, input_scale) to (output_precision, output_scale).

Returns (f_fallible, f_infallible) where:

  • f_fallible yields None when the requested cast would overflow
  • f_infallible is present only when every input is guaranteed to succeed; otherwise it is None and callers must fall back to f_fallible

Returns None if the required scale reduction delta_scale = input_scale - output_scale exceeds the supported precomputed precision table I::MAX_FOR_EACH_PRECISION. In this scenario, any value would round to zero (e.g., dividing by 10^k where k exceeds the available precision). Callers should therefore produce zero values (preserving nulls) rather than returning an error.