fn child_schema_lookup()

in crates/core/src/avro_to_arrow/arrow_array_reader.rs [100:144]


    fn child_schema_lookup<'b>(
        parent_field_name: &str,
        schema: &AvroSchema,
        schema_lookup: &'b mut BTreeMap<String, usize>,
    ) -> Result<&'b BTreeMap<String, usize>> {
        match schema {
            AvroSchema::Union(us) => {
                let has_nullable = us
                    .find_schema_with_known_schemata::<apache_avro::Schema>(
                        &Value::Null,
                        None,
                        &None,
                    )
                    .is_some();
                let sub_schemas = us.variants();
                if has_nullable && sub_schemas.len() == 2 {
                    if let Some(sub_schema) =
                        sub_schemas.iter().find(|&s| !matches!(s, AvroSchema::Null))
                    {
                        Self::child_schema_lookup(parent_field_name, sub_schema, schema_lookup)?;
                    }
                }
            }
            AvroSchema::Record(RecordSchema { fields, lookup, .. }) => {
                lookup.iter().for_each(|(field_name, pos)| {
                    schema_lookup.insert(format!("{}.{}", parent_field_name, field_name), *pos);
                });

                for field in fields {
                    let sub_parent_field_name = format!("{}.{}", parent_field_name, field.name);
                    Self::child_schema_lookup(
                        &sub_parent_field_name,
                        &field.schema,
                        schema_lookup,
                    )?;
                }
            }
            AvroSchema::Array(schema) => {
                let sub_parent_field_name = format!("{}.element", parent_field_name);
                Self::child_schema_lookup(&sub_parent_field_name, &schema.items, schema_lookup)?;
            }
            _ => (),
        }
        Ok(schema_lookup)
    }