MCPcopy Create free account
hub / github.com/apache/arrow / Call

Method Call

cpp/src/arrow/compute/kernels/scalar_cast_numeric.cc:669–698  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

667struct 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_;

Callers

nothing calls this directly

Calls 11

FromStringFunction · 0.85
IncreaseScaleByMethod · 0.80
ReduceScaleByMethod · 0.80
RescaleMethod · 0.80
FitsInPrecisionMethod · 0.80
MoveValueUnsafeMethod · 0.80
InvalidFunction · 0.50
dataMethod · 0.45
sizeMethod · 0.45
okMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected