| 323 | }; |
| 324 | |
| 325 | Status CheckReplaceMaskInputs(const DataType& value_type, int64_t arr_length, |
| 326 | const ExecValue& mask_box, |
| 327 | const DataType& replacements_type, |
| 328 | int64_t replacements_length, bool replacements_is_array) { |
| 329 | // Needed for FixedSizeBinary/parameterized types |
| 330 | if (!value_type.Equals(replacements_type, /*check_metadata=*/false)) { |
| 331 | return Status::Invalid("Replacements must be of same type (expected ", |
| 332 | value_type.ToString(), " but got ", |
| 333 | replacements_type.ToString(), ")"); |
| 334 | } |
| 335 | |
| 336 | int64_t mask_count = 0; |
| 337 | if (mask_box.is_scalar()) { |
| 338 | const auto& mask = mask_box.scalar_as<BooleanScalar>(); |
| 339 | mask_count = (mask.is_valid && mask.value) ? arr_length : 0; |
| 340 | } else { |
| 341 | const ArraySpan& mask = mask_box.array; |
| 342 | mask_count = GetTrueCount(mask); |
| 343 | if (mask.length != arr_length) { |
| 344 | return Status::Invalid("Mask must be of same length as array (expected ", |
| 345 | arr_length, " items but got ", mask.length, " items)"); |
| 346 | } |
| 347 | } |
| 348 | if (replacements_is_array) { |
| 349 | if (replacements_length < mask_count) { |
| 350 | return Status::Invalid("Replacement array must be of appropriate length (expected ", |
| 351 | mask_count, " items but got ", replacements_length, |
| 352 | " items)"); |
| 353 | } |
| 354 | } |
| 355 | return Status::OK(); |
| 356 | } |
| 357 | |
| 358 | template <typename Type> |
| 359 | struct ReplaceMask { |