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