fn from_thrift_helper(elements: &[SchemaElement], index: usize) -> Result<(usize, ParquetType)> {
    // Whether or not the current node is root (message type).
    // There is only one message type node in the schema tree.
    let is_root_node = index == 0;

    let element = &elements[index];
    let name = element.name.clone();
    let converted_type = element.converted_type;

    let id = element.field_id;
    match element.num_children {
        // From parquet-format:
        //   The children count is used to construct the nested relationship.
        //   This field is not set when the element is a primitive type
        // Sometimes parquet-cpp sets num_children field to 0 for primitive types, so we
        // have to handle this case too.
        None | Some(0) => {
            // primitive type
            let repetition = element
                .repetition_type
                .ok_or_else(|| {
                    general_err!("Repetition level must be defined for a primitive type")
                })?
                .try_into()
                .unwrap();
            let physical_type = element.type_.ok_or_else(|| {
                general_err!("Physical type must be defined for a primitive type")
            })?;

            let converted_type = converted_type
                .map(|converted_type| {
                    let maybe_decimal = match (element.precision, element.scale) {
                        (Some(precision), Some(scale)) => Some((precision, scale)),
                        (None, None) => None,
                        _ => {
                            return Err(general_err!(
                                "When precision or scale are defined, both must be defined"
                            ))
                        }
                    };
                    (converted_type, maybe_decimal).try_into()
                })
                .transpose()?;

            let logical_type = element
                .logical_type
                .clone()
                .map(|x| x.try_into())
                .transpose()?;

            let tp = ParquetType::try_from_primitive(
                name,
                (physical_type, element.type_length).try_into()?,
                repetition,
                converted_type,
                logical_type,
                id,
            )?;

            Ok((index + 1, tp))
        }
        Some(n) => {
            let mut fields = vec![];
            let mut next_index = index + 1;
            for _ in 0..n {
                let child_result = from_thrift_helper(elements, next_index)?;
                next_index = child_result.0;
                fields.push(child_result.1);
            }

            let tp = if is_root_node {
                ParquetType::new_root(name, fields)
            } else {
                let repetition = if let Some(repetition) = element.repetition_type {
                    repetition.try_into()?
                } else {
                    return Err(Error::OutOfSpec(
                        "The repetition level of a non-root must be non-null".to_string(),
                    ));
                };

                let converted_type = converted_type.map(|x| x.try_into()).transpose()?;

                let logical_type = element
                    .logical_type
                    .clone()
                    .map(|x| x.try_into())
                    .transpose()?;

                ParquetType::GroupType {
                    field_info: FieldInfo {
                        name,
                        repetition,
                        id,
                    },
                    fields,
                    converted_type,
                    logical_type,
                }
            };
            Ok((next_index, tp))
        }
    }
}
/// Constructs a new Type from the `elements`, starting at index `index`.
/// The first result is the starting index for the next Type after this one. If it is
/// equal to `elements.len()`, then this Type is the last one.
/// The second result is the result Type.
Constructs a new Type from the `elements`, starting at index `index`.
The first result is the starting index for the next Type after this one. If it is
equal to `elements.len()`, then this Type is the last one.
The second result is the result Type.
Constructs a new Type from the ` elements ` starting at index ` index ` . The first result is the starting index for the next Type after this one . If it is equal to ` elements . len () ` then this Type is the last one . The second result is the result Type .
fn from_thrift_helper(elements: &[SchemaElement], index: usize) -> Result<(usize, ParquetType)> {
    // Whether or not the current node is root (message type).
    // There is only one message type node in the schema tree.
    let is_root_node = index == 0;
    let element = &elements[index];
    let name = element.name.clone();
    let converted_type = element.converted_type;
    let id = element.field_id;
    match element.num_children {
        // From parquet-format:
        //   The children count is used to construct the nested relationship.
        //   This field is not set when the element is a primitive type
        // Sometimes parquet-cpp sets num_children field to 0 for primitive types, so we
        // have to handle this case too.
        None | Some(0) => {
            // primitive type
            let repetition = element
                .repetition_type
                .ok_or_else(|| {
                    general_err!("Repetition level must be defined for a primitive type")
                })?
                .try_into()
                .unwrap();
            let physical_type = element.type_.ok_or_else(|| {
                general_err!("Physical type must be defined for a primitive type")
            })?;
            let converted_type = converted_type
                .map(|converted_type| {
                    let maybe_decimal = match (element.precision, element.scale) {
                        (Some(precision), Some(scale)) => Some((precision, scale)),
                        (None, None) => None,
                        _ => {
                            return Err(general_err!(
                                "When precision or scale are defined, both must be defined"
                            ))
                        }
                    };
                    (converted_type, maybe_decimal).try_into()
                })
                .transpose()?;
            let logical_type = element
                .logical_type
                .clone()
                .map(|x| x.try_into())
                .transpose()?;
            let tp = ParquetType::try_from_primitive(
                name,
                (physical_type, element.type_length).try_into()?,
                repetition,
                converted_type,
                logical_type,
                id,
            )?;
            Ok((index + 1, tp))
        }
        Some(n) => {
            let mut fields = vec![];
            let mut next_index = index + 1;
            for _ in 0..n {
                let child_result = from_thrift_helper(elements, next_index)?;
                next_index = child_result.0;
                fields.push(child_result.1);
            }
            let tp = if is_root_node {
                ParquetType::new_root(name, fields)
            } else {
                let repetition = if let Some(repetition) = element.repetition_type {
                    repetition.try_into()?
                } else {
                    return Err(Error::OutOfSpec(
                        "The repetition level of a non-root must be non-null".to_string(),
                    ));
                };
                let converted_type = converted_type.map(|x| x.try_into()).transpose()?;
                let logical_type = element
                    .logical_type
                    .clone()
                    .map(|x| x.try_into())
                    .transpose()?;
                ParquetType::GroupType {
                    field_info: FieldInfo {
                        name,
                        repetition,
                        id,
                    },
                    fields,
                    converted_type,
                    logical_type,
                }
            };
            Ok((next_index, tp))
        }
    }
}
fn from_thrift_helper ( elements : & [ SchemaElement ] , index : usize ) -> Result < ( usize , ParquetType ) > { // Whether or not the current node is root (message type). // There is only one message type node in the schema tree. let is_root_node = index == 0 ; let element = & elements [ index ] ; let name = element . name . clone ( ) ; let converted_type = element . converted_type ; let id = element . field_id ; match element . num_children { // From parquet-format: //   The children count is used to construct the nested relationship. //   This field is not set when the element is a primitive type // Sometimes parquet-cpp sets num_children field to 0 for primitive types, so we // have to handle this case too. None | Some ( 0 ) => { // primitive type let repetition = element . repetition_type . ok_or_else ( | | { general_err ! ( " " ) } ) ? . try_into ( ) . unwrap ( ) ; let physical_type = element . type_ . ok_or_else ( | | { general_err ! ( " " ) } ) ? ; let converted_type = converted_type . map ( | converted_type | { let maybe_decimal = match ( element . precision , element . scale ) { ( Some ( precision ) , Some ( scale ) ) => Some ( ( precision , scale ) ) , ( None , None ) => None , _ => { return Err ( general_err ! ( " " ) ) } } ; ( converted_type , maybe_decimal ) . try_into ( ) } ) . transpose ( ) ? ; let logical_type = element . logical_type . clone ( ) . map ( | x | x . try_into ( ) ) . transpose ( ) ? ; let tp = ParquetType :: try_from_primitive ( name , ( physical_type , element . type_length ) . try_into ( ) ? , repetition , converted_type , logical_type , id , ) ? ; Ok ( ( index + 1 , tp ) ) } Some ( n ) => { let mut fields = vec ! [ ] ; let mut next_index = index + 1 ; for _ in 0 .. n { let child_result = from_thrift_helper ( elements , next_index ) ? ; next_index = child_result . 0 ; fields . push ( child_result . 1 ) ; } let tp = if is_root_node { ParquetType :: new_root ( name , fields ) } else { let repetition = if let Some ( repetition ) = element . repetition_type { repetition . try_into ( ) ? } else { return Err ( Error :: OutOfSpec ( " " . to_string ( ) , ) ) ; } ; let converted_type = converted_type . map ( | x | x . try_into ( ) ) . transpose ( ) ? ; let logical_type = element . logical_type . clone ( ) . map ( | x | x . try_into ( ) ) . transpose ( ) ? ; ParquetType :: GroupType { field_info : FieldInfo { name , repetition , id , } , fields , converted_type , logical_type , } } ; Ok ( ( next_index , tp ) ) } } }
Constructs a new Type from the `elements`, starting at index `index`.
Constructs a new Type from the ` elements ` starting at index ` index ` .
elements
&[SchemaElement]
index
usize