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

Method ValidateArrayDataCapacity

cpp/src/gandiva/projector.cc:241–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

239}
240
241Status Projector::ValidateArrayDataCapacity(const arrow::ArrayData& array_data,
242 const arrow::Field& field,
243 int64_t num_records) const {
244 ARROW_RETURN_IF(array_data.buffers.size() < 2,
245 Status::Invalid("ArrayData must have at least 2 buffers"));
246
247 int64_t min_bitmap_len = arrow::bit_util::BytesForBits(num_records);
248 int64_t bitmap_len = array_data.buffers[0]->capacity();
249 ARROW_RETURN_IF(
250 bitmap_len < min_bitmap_len,
251 Status::Invalid("Bitmap buffer too small for ", field.name(), " expected minimum ",
252 min_bitmap_len, " actual size ", bitmap_len));
253
254 auto type_id = field.type()->id();
255 if (arrow::is_binary_like(type_id)) {
256 // validate size of offsets buffer.
257 int64_t min_offsets_len = arrow::bit_util::BytesForBits((num_records + 1) * 32);
258 int64_t offsets_len = array_data.buffers[1]->capacity();
259 ARROW_RETURN_IF(
260 offsets_len < min_offsets_len,
261 Status::Invalid("offsets buffer too small for ", field.name(),
262 " minimum required ", min_offsets_len, " actual ", offsets_len));
263
264 // check that it's resizable.
265 auto resizable = dynamic_cast<arrow::ResizableBuffer*>(array_data.buffers[2].get());
266 ARROW_RETURN_IF(
267 resizable == nullptr,
268 Status::Invalid("data buffer for varlen output vectors must be resizable"));
269 } else if (arrow::is_primitive(type_id) || type_id == arrow::Type::DECIMAL) {
270 // verify size of data buffer.
271 const auto& fw_type = static_cast<const arrow::FixedWidthType&>(*field.type());
272 int64_t min_data_len =
273 arrow::bit_util::BytesForBits(num_records * fw_type.bit_width());
274 int64_t data_len = array_data.buffers[1]->capacity();
275 ARROW_RETURN_IF(data_len < min_data_len,
276 Status::Invalid("Data buffer too small for ", field.name()));
277 } else {
278 return Status::Invalid("Unsupported output data type " + field.type()->ToString());
279 }
280
281 return Status::OK();
282}
283
284const std::string& Projector::DumpIR() { return llvm_generator_->ir(); }
285

Callers

nothing calls this directly

Calls 13

BytesForBitsFunction · 0.85
is_binary_likeFunction · 0.85
InvalidFunction · 0.50
is_primitiveFunction · 0.50
OKFunction · 0.50
sizeMethod · 0.45
capacityMethod · 0.45
nameMethod · 0.45
idMethod · 0.45
typeMethod · 0.45
getMethod · 0.45
bit_widthMethod · 0.45

Tested by

no test coverage detected