| 595 | }; |
| 596 | |
| 597 | class RepeatedArrayFactory { |
| 598 | public: |
| 599 | RepeatedArrayFactory(MemoryPool* pool, const Scalar& scalar, int64_t length) |
| 600 | : pool_(pool), scalar_(scalar), length_(length) {} |
| 601 | |
| 602 | template <typename T> |
| 603 | const auto& scalar() const { |
| 604 | return checked_cast<const typename TypeTraits<T>::ScalarType&>(scalar_); |
| 605 | } |
| 606 | |
| 607 | Result<std::shared_ptr<Array>> Create() { |
| 608 | RETURN_NOT_OK(VisitTypeInline(*scalar_.type, this)); |
| 609 | return out_; |
| 610 | } |
| 611 | |
| 612 | Status Visit(const NullType& type) { |
| 613 | DCHECK(false); // already forwarded to MakeArrayOfNull |
| 614 | return Status::OK(); |
| 615 | } |
| 616 | |
| 617 | Status Visit(const BooleanType&) { |
| 618 | ARROW_ASSIGN_OR_RAISE(auto buffer, AllocateBitmap(length_, pool_)); |
| 619 | bit_util::SetBitsTo(buffer->mutable_data(), 0, length_, |
| 620 | checked_cast<const BooleanScalar&>(scalar_).value); |
| 621 | out_ = std::make_shared<BooleanArray>(length_, buffer); |
| 622 | return Status::OK(); |
| 623 | } |
| 624 | |
| 625 | template <typename T> |
| 626 | enable_if_t<is_number_type<T>::value || is_temporal_type<T>::value, Status> Visit( |
| 627 | const T&) { |
| 628 | auto value = scalar<T>().value; |
| 629 | return FinishFixedWidth(&value, sizeof(value)); |
| 630 | } |
| 631 | |
| 632 | Status Visit(const FixedSizeBinaryType& type) { |
| 633 | auto value = checked_cast<const FixedSizeBinaryScalar&>(scalar_).value; |
| 634 | return FinishFixedWidth(value->data(), type.byte_width()); |
| 635 | } |
| 636 | |
| 637 | template <typename T> |
| 638 | enable_if_decimal<T, Status> Visit(const T&) { |
| 639 | auto value = scalar<T>().value.ToBytes(); |
| 640 | return FinishFixedWidth(value.data(), value.size()); |
| 641 | } |
| 642 | |
| 643 | Status Visit(const Decimal256Type&) { |
| 644 | auto value = checked_cast<const Decimal256Scalar&>(scalar_).value.ToBytes(); |
| 645 | return FinishFixedWidth(value.data(), value.size()); |
| 646 | } |
| 647 | |
| 648 | template <typename T> |
| 649 | enable_if_base_binary<T, Status> Visit(const T&) { |
| 650 | const std::shared_ptr<Buffer>& value = scalar<T>().value; |
| 651 | std::shared_ptr<Buffer> values_buffer, offsets_buffer; |
| 652 | RETURN_NOT_OK(CreateBufferOf(value->data(), value->size(), &values_buffer)); |
| 653 | auto size = static_cast<typename T::offset_type>(value->size()); |
| 654 | RETURN_NOT_OK(CreateOffsetsBuffer(size, &offsets_buffer)); |
no outgoing calls
no test coverage detected