| 195 | |
| 196 | template <typename RunEndCType> |
| 197 | Status ValidateRunEndEncodedChildren(const RunEndEncodedType& type, |
| 198 | int64_t logical_length, |
| 199 | const std::shared_ptr<ArrayData>& run_ends_data, |
| 200 | const std::shared_ptr<ArrayData>& values_data, |
| 201 | int64_t null_count, int64_t logical_offset) { |
| 202 | // Overflow was already checked at this point |
| 203 | if (logical_offset + logical_length > std::numeric_limits<RunEndCType>::max()) { |
| 204 | return Status::Invalid( |
| 205 | "Offset + length of a run-end encoded array must fit in a value" |
| 206 | " of the run end type ", |
| 207 | *type.run_end_type(), ", but offset + length is ", |
| 208 | logical_offset + logical_length, " while the allowed maximum is ", |
| 209 | std::numeric_limits<RunEndCType>::max()); |
| 210 | } |
| 211 | if (!run_ends_data) { |
| 212 | return Status::Invalid("Run ends array is null pointer"); |
| 213 | } |
| 214 | if (!values_data) { |
| 215 | return Status::Invalid("Values array is null pointer"); |
| 216 | } |
| 217 | if (*run_ends_data->type != *type.run_end_type()) { |
| 218 | return Status::Invalid("Run ends array of ", type, " must be ", *type.run_end_type(), |
| 219 | ", but run end type is ", *run_ends_data->type); |
| 220 | } |
| 221 | if (*values_data->type != *type.value_type()) { |
| 222 | return Status::Invalid("Parent type says this array encodes ", *type.value_type(), |
| 223 | " values, but value type is ", *values_data->type); |
| 224 | } |
| 225 | if (run_ends_data->GetNullCount() != 0) { |
| 226 | return Status::Invalid("Null count must be 0 for run ends array, but is ", |
| 227 | run_ends_data->GetNullCount()); |
| 228 | } |
| 229 | if (run_ends_data->length > values_data->length) { |
| 230 | return Status::Invalid("Length of run_ends is greater than the length of values: ", |
| 231 | run_ends_data->length, " > ", values_data->length); |
| 232 | } |
| 233 | if (run_ends_data->length == 0) { |
| 234 | if (logical_length == 0) { |
| 235 | return Status::OK(); |
| 236 | } |
| 237 | return Status::Invalid("Run-end encoded array has non-zero length ", logical_length, |
| 238 | ", but run ends array has zero length"); |
| 239 | } |
| 240 | if (null_count != 0) { |
| 241 | return Status::Invalid("Null count must be 0 for run-end encoded array, but is ", |
| 242 | null_count); |
| 243 | } |
| 244 | if (!run_ends_data->buffers[1]->is_cpu()) { |
| 245 | return Status::OK(); |
| 246 | } |
| 247 | const auto* run_ends = run_ends_data->GetValues<RunEndCType>(1); |
| 248 | // The last run-end is the logical offset + the logical length. |
| 249 | if (run_ends[run_ends_data->length - 1] < logical_offset + logical_length) { |
| 250 | return Status::Invalid("Last run end is ", run_ends[run_ends_data->length - 1], |
| 251 | " but it should match ", logical_offset + logical_length, |
| 252 | " (offset: ", logical_offset, ", length: ", logical_length, |
| 253 | ")"); |
| 254 | } |
no test coverage detected