| 394 | } |
| 395 | |
| 396 | Result<std::shared_ptr<DataType>> WidenDecimals( |
| 397 | const std::shared_ptr<DataType>& promoted_type, |
| 398 | const std::shared_ptr<DataType>& other_type, const Field::MergeOptions& options) { |
| 399 | const auto& left = checked_cast<const DecimalType&>(*promoted_type); |
| 400 | const auto& right = checked_cast<const DecimalType&>(*other_type); |
| 401 | if (!options.promote_numeric_width && left.bit_width() != right.bit_width()) { |
| 402 | return Status::TypeError( |
| 403 | "Cannot promote decimal types without promote_numeric_width=true"); |
| 404 | } |
| 405 | const int32_t max_scale = std::max<int32_t>(left.scale(), right.scale()); |
| 406 | const int32_t common_precision = |
| 407 | std::max<int32_t>(left.precision() + max_scale - left.scale(), |
| 408 | right.precision() + max_scale - right.scale()); |
| 409 | if (left.id() == Type::DECIMAL256 || right.id() == Type::DECIMAL256 || |
| 410 | common_precision > BasicDecimal128::kMaxPrecision) { |
| 411 | return DecimalType::Make(Type::DECIMAL256, common_precision, max_scale); |
| 412 | } else if (left.id() == Type::DECIMAL128 || right.id() == Type::DECIMAL128 || |
| 413 | common_precision > BasicDecimal64::kMaxPrecision) { |
| 414 | return DecimalType::Make(Type::DECIMAL128, common_precision, max_scale); |
| 415 | } else if (left.id() == Type::DECIMAL64 || right.id() == Type::DECIMAL64 || |
| 416 | common_precision > BasicDecimal32::kMaxPrecision) { |
| 417 | return DecimalType::Make(Type::DECIMAL64, common_precision, max_scale); |
| 418 | } |
| 419 | return DecimalType::Make(Type::DECIMAL32, common_precision, max_scale); |
| 420 | } |
| 421 | |
| 422 | Result<std::shared_ptr<DataType>> MergeTypes(std::shared_ptr<DataType> promoted_type, |
| 423 | std::shared_ptr<DataType> other_type, |