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

Method SetupPreallocation

cpp/src/arrow/compute/exec.cc:931–984  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

929 }
930
931 Status SetupPreallocation(int64_t total_length, const std::vector<Datum>& args) {
932 output_num_buffers_ = static_cast<int>(output_type_.type->layout().buffers.size());
933 auto out_type_id = output_type_.type->id();
934 // Default to no validity pre-allocation for following cases:
935 // - Output Array is NullArray
936 // - kernel_->null_handling is COMPUTED_NO_PREALLOCATE or OUTPUT_NOT_NULL
937 validity_preallocated_ = false;
938
939 if (out_type_id != Type::NA) {
940 if (kernel_->null_handling == NullHandling::COMPUTED_PREALLOCATE) {
941 // Override the flag if kernel asks for pre-allocation
942 validity_preallocated_ = true;
943 } else if (kernel_->null_handling == NullHandling::INTERSECTION) {
944 elide_validity_bitmap_ = true;
945 for (const auto& arg : args) {
946 auto null_gen = NullGeneralization::Get(arg) == NullGeneralization::ALL_VALID;
947
948 // If not all valid, this becomes false
949 elide_validity_bitmap_ = elide_validity_bitmap_ && null_gen;
950 }
951 validity_preallocated_ = !elide_validity_bitmap_;
952 } else if (kernel_->null_handling == NullHandling::OUTPUT_NOT_NULL) {
953 elide_validity_bitmap_ = true;
954 }
955 }
956 if (kernel_->mem_allocation == MemAllocation::PREALLOCATE) {
957 data_preallocated_.clear();
958 ComputeDataPreallocate(*output_type_.type, &data_preallocated_);
959 }
960
961 // Validity bitmap either preallocated or elided, and all data
962 // buffers allocated. This is basically only true for primitive
963 // types that are not dictionary-encoded
964 preallocating_all_buffers_ =
965 ((validity_preallocated_ || elide_validity_bitmap_) &&
966 data_preallocated_.size() == static_cast<size_t>(output_num_buffers_ - 1) &&
967 !is_nested(out_type_id) && !is_dictionary(out_type_id));
968
969 // TODO(wesm): why was this check ever here? Fixed width binary
970 // can be 0-width but anything else?
971 DCHECK(std::all_of(
972 data_preallocated_.begin(), data_preallocated_.end(),
973 [](const BufferPreallocation& prealloc) { return prealloc.bit_width >= 0; }));
974
975 // Contiguous preallocation only possible on non-nested types if all
976 // buffers are preallocated. Otherwise, we must go chunk-by-chunk.
977 //
978 // Some kernels are also unable to write into sliced outputs, so we respect the
979 // kernel's attributes.
980 preallocate_contiguous_ =
981 (exec_context()->preallocate_contiguous() && kernel_->can_write_into_slices &&
982 preallocating_all_buffers_);
983 return Status::OK();
984 }
985
986 // Used to account for the case where we do not preallocate a
987 // validity bitmap because the inputs are all non-null and we're

Callers

nothing calls this directly

Calls 12

ComputeDataPreallocateFunction · 0.85
GetFunction · 0.70
exec_contextFunction · 0.70
is_nestedFunction · 0.50
is_dictionaryFunction · 0.50
OKFunction · 0.50
sizeMethod · 0.45
layoutMethod · 0.45
idMethod · 0.45
clearMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected