| 750 | typename = ::arrow::enable_if_t<::arrow::internal::IsOneOf< |
| 751 | ParquetIntegerType, Int32Type, Int64Type>::value>> |
| 752 | static Status DecimalIntegerTransfer(RecordReader* reader, MemoryPool* pool, |
| 753 | const std::shared_ptr<Field>& field, Datum* out) { |
| 754 | using ArrayTypeClass = typename DecimalArrayType::TypeClass; |
| 755 | using DecimalValue = typename DecimalTypeTrait<DecimalArrayType>::value; |
| 756 | |
| 757 | // Decimal32, Decimal64, Decimal128 and Decimal256 are only Arrow constructs. Parquet |
| 758 | // does not specifically distinguish between decimal byte widths. |
| 759 | DCHECK(field->type()->id() == ArrayTypeClass::type_id); |
| 760 | |
| 761 | const int64_t length = reader->values_written(); |
| 762 | |
| 763 | using ElementType = typename ParquetIntegerType::c_type; |
| 764 | static_assert(std::is_same<ElementType, int32_t>::value || |
| 765 | std::is_same<ElementType, int64_t>::value, |
| 766 | "ElementType must be int32_t or int64_t"); |
| 767 | |
| 768 | const auto values = reinterpret_cast<const ElementType*>(reader->values()); |
| 769 | |
| 770 | const auto& decimal_type = checked_cast<const ArrayTypeClass&>(*field->type()); |
| 771 | const int64_t type_length = decimal_type.byte_width(); |
| 772 | |
| 773 | ARROW_ASSIGN_OR_RAISE(auto data, ::arrow::AllocateBuffer(length * type_length, pool)); |
| 774 | uint8_t* out_ptr = data->mutable_data(); |
| 775 | |
| 776 | for (int64_t i = 0; i < length; ++i, out_ptr += type_length) { |
| 777 | // sign/zero extend int32_t values, otherwise a no-op |
| 778 | const auto value = static_cast<int64_t>(values[i]); |
| 779 | DecimalValue decimal(value); |
| 780 | decimal.ToBytes(out_ptr); |
| 781 | } |
| 782 | |
| 783 | if (reader->nullable_values() && field->nullable()) { |
| 784 | std::shared_ptr<ResizableBuffer> is_valid = reader->ReleaseIsValid(); |
| 785 | *out = std::make_shared<DecimalArrayType>(field->type(), length, std::move(data), |
| 786 | is_valid, reader->null_count()); |
| 787 | } else { |
| 788 | *out = std::make_shared<DecimalArrayType>(field->type(), length, std::move(data)); |
| 789 | } |
| 790 | return Status::OK(); |
| 791 | } |
| 792 | |
| 793 | /// \brief Convert an arrow::BinaryArray to an arrow::Decimal{128,256}Array |
| 794 | /// We do this by: |
nothing calls this directly
no test coverage detected