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