MCPcopy Create free account
hub / github.com/apache/arrow / FromArraysInternal

Method FromArraysInternal

cpp/src/arrow/array/array_nested.cc:808–861  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

GetNullCountMethod · 0.80
resizeMethod · 0.80
InvalidFunction · 0.50
TypeErrorFunction · 0.50
type_nameFunction · 0.50
NotImplementedFunction · 0.50
lengthMethod · 0.45
type_idMethod · 0.45
null_countMethod · 0.45
dataMethod · 0.45
offsetMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected