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

Method ValidateOffsetsAndSizes

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

Source from the content-addressed store, hash-verified

905 public:
906 template <typename TypeClass>
907 Status ValidateOffsetsAndSizes(const TypeClass&, int64_t offset_limit) {
908 using offset_type = typename TypeClass::offset_type;
909 constexpr bool is_list_view = is_list_view_type<TypeClass>::value;
910
911 const bool non_empty = data.length > 0;
912 if constexpr (is_list_view) {
913 if (!IsBufferValid(1)) {
914 return Status::Invalid("offsets buffer is null");
915 }
916 if (!IsBufferValid(2)) {
917 return Status::Invalid("sizes buffer is null");
918 }
919 } else {
920 if (!IsBufferValid(1)) {
921 // For length 0, an empty offsets buffer is accepted (ARROW-544).
922 return non_empty ? Status::Invalid("Non-empty array but offsets are null")
923 : Status::OK();
924 }
925 }
926
927 const auto offsets_byte_size = data.buffers[1]->size();
928 const auto required_offsets = ((data.length > 0) || (offsets_byte_size > 0))
929 ? data.length + data.offset + (is_list_view ? 0 : 1)
930 : 0;
931 if (offsets_byte_size / static_cast<int32_t>(sizeof(offset_type)) <
932 required_offsets) {
933 return Status::Invalid("Offsets buffer size (bytes): ", offsets_byte_size,
934 " isn't large enough for length: ", data.length,
935 " and offset: ", data.offset);
936 }
937 if constexpr (is_list_view) {
938 const auto required_sizes = data.length + data.offset;
939 const auto sizes_bytes_size = data.buffers[2]->size();
940 if (sizes_bytes_size / static_cast<int32_t>(sizeof(offset_type)) < required_sizes) {
941 return Status::Invalid("Sizes buffer size (bytes): ", sizes_bytes_size,
942 " isn't large enough for length: ", data.length,
943 " and offset: ", data.offset);
944 }
945 }
946
947 if (full_validation && required_offsets > 0) {
948 if constexpr (is_list_view) {
949 return FullyValidateOffsetsAndSizes<offset_type>(offset_limit);
950 } else {
951 return FullyValidateOffsets<offset_type>(offset_limit);
952 }
953 }
954 return Status::OK();
955 }
956
957 template <typename DecimalType>
958 Status ValidateDecimals(const DecimalType& type) {

Callers

nothing calls this directly

Calls 3

InvalidFunction · 0.50
OKFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected