liamzwbao opened a new issue, #8670: URL: https://github.com/apache/arrow-rs/issues/8670
**Is your feature request related to a problem or challenge? Please describe what you are trying to do.** <!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] (This section helps Arrow developers understand the context and *why* for this feature, in addition to the *what*) --> Refactor decimal casting in [arrow-cast](https://github.com/apache/arrow-rs/blob/c74cbf21f003890e927e932d28940d0427737ac2/arrow-cast/src/cast/decimal.rs#L169-L287) to converge on the same rescale logic used by the [parquet variant cast](https://github.com/apache/arrow-rs/blob/c74cbf21f003890e927e932d28940d0427737ac2/parquet-variant-compute/src/type_conversion.rs#L189-L246) **Describe the solution you'd like** <!-- A clear and concise description of what you want to happen. --> Originally post by @scovich in https://github.com/apache/arrow-rs/pull/8552#discussion_r2415217002 > * rework `convert_to_smaller_scale_decimal` and `convert_to_bigger_or_equal_scale_decimal` > > * no longer take `array` or `cast_options` as input > * return `Ok((f, is_infallible_cast)` which corresponds to the return type `Result<(impl Fn(I::Native) -> Option<O::Native>, bool), ArrowError>` > * define a new generic `apply_decimal_cast` function helper > > * it takes as input `array`, `cast_options` and the `(impl Fn, bool)` pair produced by a `convert_to_xxx_scale_decimal` helper > * it handles the three ways of applying `f` to an array > * rework `cast_decimal_to_decimal` and `cast_decimal_to_decimal_same_type` to call those functions (see below) > * `rescale_decimal` would be the single-row equivalent of `cast_decimal_to_decimal`, returning `Option<O::Native>` > * The decimal builder's constructor calls `validate_decimal_precision_and_scale` and fails on error, so we don't need to validate on a per-row basis. > > cast_decimal_to_decimal > ```rust > let array: PrimitiveArray<O> = if input_scale > output_scale { > let (f, is_infallible_cast) = convert_to_smaller_scale_decimal(...)?; > apply_decimal_cast(array, cast_options, f, is_infallible)? > } else { > let (f, is_infallible_cast) = convert_to_bigger_or_equal_scale_decimal(...)?; > apply_decimal_cast(array, cast_options, f, is_infallible)? > } > ``` > > rescale_decimal > ```rust > if input_scale > output_scale { > let (f, _) = convert_to_smaller_scale_decimal(...)?; > f(integer) > } else { > let (f, _) = convert_to_bigger_or_equal_scale_decimal(...)?; > f(integer) > } > ``` **Describe alternatives you've considered** <!-- A clear and concise description of any alternative solutions or features you've considered. --> **Additional context** <!-- Add any other context or screenshots about the feature request here. --> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
