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

Function PreallocateFixedWidthArrayData

cpp/src/arrow/util/fixed_width_internal.cc:112–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110namespace internal {
111
112Status PreallocateFixedWidthArrayData(::arrow::compute::KernelContext* ctx,
113 int64_t length, const ArraySpan& source,
114 bool allocate_validity, ArrayData* out) {
115 DCHECK(!source.MayHaveNulls() || allocate_validity)
116 << "allocate_validity cannot be false if source may have nulls";
117 DCHECK_EQ(source.type->id(), out->type->id());
118 auto* type = source.type;
119 out->length = length;
120 if (type->id() == Type::FIXED_SIZE_LIST) {
121 out->buffers.resize(1);
122 out->child_data = {std::make_shared<ArrayData>()};
123 } else {
124 out->buffers.resize(2);
125 }
126 if (allocate_validity) {
127 ARROW_ASSIGN_OR_RAISE(out->buffers[0], ctx->AllocateBitmap(length));
128 }
129
130 if (type->id() == Type::BOOL) {
131 ARROW_ASSIGN_OR_RAISE(out->buffers[1], ctx->AllocateBitmap(length));
132 return Status::OK();
133 }
134 if (is_fixed_width(type->id())) {
135 if (type->id() == Type::DICTIONARY) {
136 return Status::NotImplemented(
137 "PreallocateFixedWidthArrayData: DICTIONARY type allocation: ", *type);
138 }
139 ARROW_ASSIGN_OR_RAISE(out->buffers[1],
140 ctx->Allocate(length * source.type->byte_width()));
141 return Status::OK();
142 }
143 if (type->id() == Type::FIXED_SIZE_LIST) {
144 auto& fsl_type = checked_cast<const FixedSizeListType&>(*type);
145 auto& value_type = fsl_type.value_type();
146 if (ARROW_PREDICT_FALSE(value_type->id() == Type::DICTIONARY)) {
147 return Status::NotImplemented(
148 "PreallocateFixedWidthArrayData: DICTIONARY type allocation: ", *type);
149 }
150 if (source.child_data[0].MayHaveNulls()) {
151 return Status::Invalid(
152 "PreallocateFixedWidthArrayData: "
153 "FixedSizeList may have null values in child array: ",
154 fsl_type);
155 }
156 auto* child_values = out->child_data[0].get();
157 child_values->type = value_type;
158 return PreallocateFixedWidthArrayData(ctx, length * fsl_type.list_size(),
159 /*source=*/source.child_data[0],
160 /*allocate_validity=*/false,
161 /*out=*/child_values);
162 }
163 return Status::Invalid("PreallocateFixedWidthArrayData: Invalid type: ", *type);
164}
165
166} // namespace internal
167

Callers 2

PrimitiveFilterExecFunction · 0.85
FixedWidthTakeExecFunction · 0.85

Calls 13

is_fixed_widthFunction · 0.85
resizeMethod · 0.80
AllocateBitmapMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.50
OKFunction · 0.50
NotImplementedFunction · 0.50
InvalidFunction · 0.50
idMethod · 0.45
AllocateMethod · 0.45
byte_widthMethod · 0.45
value_typeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected