Creates a [`RowColumnarDecoder`] that decodes from the provided [`StructArray`]. Returns an error if the schema of the [`StructArray`] does not match the provided [`RelationDesc`].
(col: StructArray, desc: &RelationDesc)
| 1311 | /// Returns an error if the schema of the [`StructArray`] does not match |
| 1312 | /// the provided [`RelationDesc`]. |
| 1313 | pub fn new(col: StructArray, desc: &RelationDesc) -> Result<Self, anyhow::Error> { |
| 1314 | let inner_columns = col.columns(); |
| 1315 | let desc_columns = desc.typ().columns(); |
| 1316 | |
| 1317 | if desc_columns.len() > inner_columns.len() { |
| 1318 | anyhow::bail!( |
| 1319 | "provided array has too few columns! {desc_columns:?} > {inner_columns:?}" |
| 1320 | ); |
| 1321 | } |
| 1322 | |
| 1323 | // For performance reasons we downcast just a single time. |
| 1324 | let mut decoders = Vec::with_capacity(desc_columns.len()); |
| 1325 | |
| 1326 | let null_mask = col.nulls(); |
| 1327 | |
| 1328 | // The columns of the `StructArray` are named with their column index. |
| 1329 | for (col_idx, col_name, col_type) in desc.iter_all() { |
| 1330 | let field_name = col_idx.to_stable_name(); |
| 1331 | let column = col.column_by_name(&field_name).ok_or_else(|| { |
| 1332 | anyhow::anyhow!( |
| 1333 | "StructArray did not contain column name {field_name}, found {:?}", |
| 1334 | col.column_names() |
| 1335 | ) |
| 1336 | })?; |
| 1337 | let column = mask_nulls(column, null_mask); |
| 1338 | let null_count = col_type.nullable.then(|| column.null_count()); |
| 1339 | let decoder = array_to_decoder(&column, &col_type.scalar_type)?; |
| 1340 | decoders.push((col_name.as_str().into(), null_count, decoder)); |
| 1341 | } |
| 1342 | |
| 1343 | Ok(RowColumnarDecoder { |
| 1344 | len: col.len(), |
| 1345 | decoders, |
| 1346 | nullability: col.logical_nulls(), |
| 1347 | }) |
| 1348 | } |
| 1349 | |
| 1350 | // Returns the number of null entries in this array of Row structs. This |
| 1351 | // will be 0 when `Row` is encoded directly, but could be non-zero when it's |
nothing calls this directly
no test coverage detected