Extract Min and Max scalars from big-endian representation of Decimals.
| 122 | |
| 123 | // Extract Min and Max scalars from big-endian representation of Decimals. |
| 124 | Status ExtractDecimalMinMaxFromBytes(std::string_view min_bytes, |
| 125 | std::string_view max_bytes, |
| 126 | const LogicalType& logical_type, |
| 127 | std::shared_ptr<::arrow::Scalar>* min, |
| 128 | std::shared_ptr<::arrow::Scalar>* max) { |
| 129 | const DecimalLogicalType& decimal_type = |
| 130 | checked_cast<const DecimalLogicalType&>(logical_type); |
| 131 | |
| 132 | Result<std::shared_ptr<DataType>> maybe_type = |
| 133 | Decimal128Type::Make(decimal_type.precision(), decimal_type.scale()); |
| 134 | std::shared_ptr<DataType> arrow_type; |
| 135 | if (maybe_type.ok()) { |
| 136 | arrow_type = maybe_type.ValueOrDie(); |
| 137 | ARROW_ASSIGN_OR_RAISE( |
| 138 | *min, DecimalScalarFromBigEndianBytes<Decimal128>(min_bytes, arrow_type)); |
| 139 | ARROW_ASSIGN_OR_RAISE(*max, DecimalScalarFromBigEndianBytes<Decimal128>( |
| 140 | max_bytes, std::move(arrow_type))); |
| 141 | return Status::OK(); |
| 142 | } |
| 143 | // Fallback to see if Decimal256 can represent the type. |
| 144 | ARROW_ASSIGN_OR_RAISE( |
| 145 | arrow_type, Decimal256Type::Make(decimal_type.precision(), decimal_type.scale())); |
| 146 | ARROW_ASSIGN_OR_RAISE( |
| 147 | *min, DecimalScalarFromBigEndianBytes<Decimal256>(min_bytes, arrow_type)); |
| 148 | ARROW_ASSIGN_OR_RAISE(*max, DecimalScalarFromBigEndianBytes<Decimal256>( |
| 149 | max_bytes, std::move(arrow_type))); |
| 150 | |
| 151 | return Status::OK(); |
| 152 | } |
| 153 | |
| 154 | template <typename Int> |
| 155 | Status ExtractDecimalMinMaxFromInteger(Int min_value, Int max_value, |
no test coverage detected