| 804 | : MapArray(type, length, {null_bitmap, offsets}, keys, items, null_count, offset) {} |
| 805 | |
| 806 | Result<std::shared_ptr<Array>> MapArray::FromArraysInternal( |
| 807 | std::shared_ptr<DataType> type, const std::shared_ptr<Array>& offsets, |
| 808 | const std::shared_ptr<Array>& keys, const std::shared_ptr<Array>& items, |
| 809 | MemoryPool* pool, std::shared_ptr<Buffer> null_bitmap) { |
| 810 | using offset_type = typename MapType::offset_type; |
| 811 | using OffsetArrowType = typename CTypeTraits<offset_type>::ArrowType; |
| 812 | |
| 813 | if (offsets->length() == 0) { |
| 814 | return Status::Invalid("Map offsets must have non-zero length"); |
| 815 | } |
| 816 | |
| 817 | if (offsets->type_id() != OffsetArrowType::type_id) { |
| 818 | return Status::TypeError("Map offsets must be ", OffsetArrowType::type_name()); |
| 819 | } |
| 820 | |
| 821 | if (keys->null_count() != 0) { |
| 822 | return Status::Invalid("Map cannot contain NULL valued keys"); |
| 823 | } |
| 824 | |
| 825 | if (keys->length() != items->length()) { |
| 826 | return Status::Invalid("Map key and item arrays must be equal length"); |
| 827 | } |
| 828 | |
| 829 | if (null_bitmap != nullptr && offsets->data()->MayHaveNulls()) { |
| 830 | return Status::Invalid( |
| 831 | "Ambiguous to specify both validity map and offsets with nulls"); |
| 832 | } |
| 833 | |
| 834 | if (null_bitmap != nullptr && offsets->offset() != 0) { |
| 835 | return Status::NotImplemented("Null bitmap with offsets slice not supported."); |
| 836 | } |
| 837 | |
| 838 | if (offsets->data()->MayHaveNulls()) { |
| 839 | ARROW_ASSIGN_OR_RAISE(auto buffers, |
| 840 | CleanListOffsets<MapType>(NULLPTR, *offsets, pool)); |
| 841 | return std::make_shared<MapArray>(type, offsets->length() - 1, std::move(buffers), |
| 842 | keys, items, offsets->null_count(), 0); |
| 843 | } |
| 844 | |
| 845 | using OffsetArrayType = typename TypeTraits<OffsetArrowType>::ArrayType; |
| 846 | const auto& typed_offsets = checked_cast<const OffsetArrayType&>(*offsets); |
| 847 | |
| 848 | BufferVector buffers; |
| 849 | buffers.resize(2); |
| 850 | int64_t null_count = 0; |
| 851 | if (null_bitmap) { |
| 852 | buffers[0] = std::move(null_bitmap); |
| 853 | null_count = kUnknownNullCount; |
| 854 | } |
| 855 | buffers[1] = typed_offsets.values(); |
| 856 | return std::make_shared<MapArray>(std::move(type), offsets->length() - 1, |
| 857 | std::move(buffers), keys, items, |
| 858 | /*null_count=*/null_count, offsets->offset()); |
| 859 | } |
| 860 | |
| 861 | Result<std::shared_ptr<Array>> MapArray::FromArrays(const std::shared_ptr<Array>& offsets, |
| 862 | const std::shared_ptr<Array>& keys, |
nothing calls this directly
no test coverage detected