Validates the values stored within this [`ArrayData`] are valid without recursing into child [`ArrayData`] Does not (yet) check 1. Union type_ids are valid see [#85](https://github.com/apache/arrow-rs/issues/85) 2. the the null count is correct and that any 3. nullability requirements of its children are correct [#85]: https://github.com/apache/arrow-rs/issues/85
(&self)
| 1346 | /// |
| 1347 | /// [#85]: https://github.com/apache/arrow-rs/issues/85 |
| 1348 | pub fn validate_nulls(&self) -> Result<(), ArrowError> { |
| 1349 | if let Some(nulls) = &self.nulls { |
| 1350 | let actual = nulls.len() - nulls.inner().count_set_bits(); |
| 1351 | if actual != nulls.null_count() { |
| 1352 | return Err(ArrowError::InvalidArgumentError(format!( |
| 1353 | "null_count value ({}) doesn't match actual number of nulls in array ({})", |
| 1354 | nulls.null_count(), |
| 1355 | actual |
| 1356 | ))); |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | // In general non-nullable children should not contain nulls, however, for certain |
| 1361 | // types, such as StructArray and FixedSizeList, nulls in the parent take up |
| 1362 | // space in the child. As such we permit nulls in the children in the corresponding |
| 1363 | // positions for such types |
| 1364 | match &self.data_type { |
| 1365 | DataType::List(f) | DataType::LargeList(f) | DataType::Map(f, _) => { |
| 1366 | if !f.is_nullable() { |
| 1367 | self.validate_non_nullable(None, &self.child_data[0])? |
| 1368 | } |
| 1369 | } |
| 1370 | DataType::FixedSizeList(field, len) => { |
| 1371 | let child = &self.child_data[0]; |
| 1372 | if !field.is_nullable() { |
| 1373 | match &self.nulls { |
| 1374 | Some(nulls) => { |
| 1375 | let element_len = *len as usize; |
| 1376 | let expanded = nulls.expand(element_len); |
| 1377 | self.validate_non_nullable(Some(&expanded), child)?; |
| 1378 | } |
| 1379 | None => self.validate_non_nullable(None, child)?, |
| 1380 | } |
| 1381 | } |
| 1382 | } |
| 1383 | DataType::Struct(fields) => { |
| 1384 | for (field, child) in fields.iter().zip(&self.child_data) { |
| 1385 | if !field.is_nullable() { |
| 1386 | self.validate_non_nullable(self.nulls(), child)? |
| 1387 | } |
| 1388 | } |
| 1389 | } |
| 1390 | _ => {} |
| 1391 | } |
| 1392 | |
| 1393 | Ok(()) |
| 1394 | } |
| 1395 | |
| 1396 | /// Verifies that `child` contains no nulls not present in `mask` |
| 1397 | fn validate_non_nullable( |
no test coverage detected