| 667 | struct StringToDecimal { |
| 668 | template <typename OutValue, typename StringType> |
| 669 | OutValue Call(KernelContext*, StringType val, Status* st) const { |
| 670 | OutValue parsed_out; |
| 671 | int32_t parsed_precision; |
| 672 | int32_t parsed_scale; |
| 673 | auto r_parse = OutValue::FromString(std::string_view(val.data(), val.size()), |
| 674 | &parsed_out, &parsed_precision, &parsed_scale); |
| 675 | |
| 676 | if (ARROW_PREDICT_TRUE(r_parse.ok())) { |
| 677 | if (allow_truncate_) { |
| 678 | return (parsed_scale < out_scale_) |
| 679 | ? parsed_out.IncreaseScaleBy(out_scale_ - parsed_scale) |
| 680 | : parsed_out.ReduceScaleBy(parsed_scale - out_scale_, false); |
| 681 | } |
| 682 | |
| 683 | auto maybe_rescaled = parsed_out.Rescale(parsed_scale, out_scale_); |
| 684 | if (!maybe_rescaled.ok()) { |
| 685 | *st = maybe_rescaled.status(); |
| 686 | return {}; // Zero |
| 687 | } |
| 688 | if (maybe_rescaled->FitsInPrecision(out_precision_)) { |
| 689 | return maybe_rescaled.MoveValueUnsafe(); |
| 690 | } else { |
| 691 | *st = Status::Invalid("Decimal value does not fit in precision ", out_precision_); |
| 692 | return {}; // Zero |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | *st = r_parse; |
| 697 | return {}; // Zero |
| 698 | } |
| 699 | |
| 700 | int32_t out_scale_, out_precision_; |
| 701 | bool allow_truncate_; |
nothing calls this directly
no test coverage detected