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

Method ValidateBinaryLike

cpp/src/arrow/array/validate.cc:597–634  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

595
596 template <typename BinaryType>
597 Status ValidateBinaryLike(const BinaryType& type) {
598 if (!IsBufferValid(2)) {
599 return Status::Invalid("Value data buffer is null");
600 }
601 const Buffer& values = *data.buffers[2];
602
603 // First validate offsets, to make sure the accesses below are valid
604 RETURN_NOT_OK(ValidateOffsetsAndSizes(type, values.size()));
605
606 if (data.length > 0 && data.buffers[1]->is_cpu()) {
607 using offset_type = typename BinaryType::offset_type;
608
609 const auto offsets = data.GetValues<offset_type>(1);
610 const Buffer& values = *data.buffers[2];
611
612 const auto first_offset = offsets[0];
613 const auto last_offset = offsets[data.length];
614 // This early test avoids undefined behaviour when computing `data_extent`
615 if (first_offset < 0 || last_offset < 0) {
616 return Status::Invalid("Negative offsets in binary array");
617 }
618 const auto data_extent = last_offset - first_offset;
619 const auto values_length = values.size();
620 if (values_length < data_extent) {
621 return Status::Invalid("Length spanned by binary offsets (", data_extent,
622 ") larger than values array (size ", values_length, ")");
623 }
624 // These tests ensure that array concatenation is safe if Validate() succeeds
625 // (for delta dictionaries)
626 if (first_offset > values_length || last_offset > values_length) {
627 return Status::Invalid("First or last binary offset out of bounds");
628 }
629 if (first_offset > last_offset) {
630 return Status::Invalid("First offset larger than last offset in binary array");
631 }
632 }
633 return Status::OK();
634 }
635
636 Status ValidateBinaryView(const BinaryViewType& type) {
637 int64_t views_byte_size = data.buffers[1]->size();

Callers

nothing calls this directly

Calls 3

InvalidFunction · 0.50
OKFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected