pub fn from(json: &Value) -> Result<Self> {
        match *json {
            Value::Object(ref map) => {
                let name = match map.get("name") {
                    Some(&Value::String(ref name)) => name.to_string(),
                    _ => {
                        return Err(ArrowError::ParseError(
                            "Field missing 'name' attribute".to_string(),
                        ));
                    }
                };
                let nullable = match map.get("nullable") {
                    Some(&Value::Bool(b)) => b,
                    _ => {
                        return Err(ArrowError::ParseError(
                            "Field missing 'nullable' attribute".to_string(),
                        ));
                    }
                };
                let data_type = match map.get("type") {
                    Some(t) => DataType::from(t)?,
                    _ => {
                        return Err(ArrowError::ParseError(
                            "Field missing 'type' attribute".to_string(),
                        ));
                    }
                };
                // if data_type is a struct or list, get its children
                let data_type = match data_type {
                    DataType::List(_) | DataType::FixedSizeList(_, _) => {
                        match map.get("children") {
                            Some(Value::Array(values)) => {
                                if values.len() != 1 {
                                    return Err(ArrowError::ParseError(
                                    "Field 'children' must have one element for a list data type".to_string(),
                                ));
                                }
                                match data_type {
                                    DataType::List(_) => DataType::List(Box::new(
                                        Self::from(&values[0])?.data_type,
                                    )),
                                    DataType::FixedSizeList(_, int) => {
                                        DataType::FixedSizeList(
                                            Box::new(Self::from(&values[0])?.data_type),
                                            int,
                                        )
                                    }
                                    _ => unreachable!(
                                        "Data type should be a list or fixedsizelist"
                                    ),
                                }
                            }
                            Some(_) => {
                                return Err(ArrowError::ParseError(
                                    "Field 'children' must be an array".to_string(),
                                ))
                            }
                            None => {
                                return Err(ArrowError::ParseError(
                                    "Field missing 'children' attribute".to_string(),
                                ));
                            }
                        }
                    }
                    DataType::Struct(mut fields) => match map.get("children") {
                        Some(Value::Array(values)) => {
                            let struct_fields: Result<Vec<Field>> =
                                values.iter().map(|v| Field::from(v)).collect();
                            fields.append(&mut struct_fields?);
                            DataType::Struct(fields)
                        }
                        Some(_) => {
                            return Err(ArrowError::ParseError(
                                "Field 'children' must be an array".to_string(),
                            ))
                        }
                        None => {
                            return Err(ArrowError::ParseError(
                                "Field missing 'children' attribute".to_string(),
                            ));
                        }
                    },
                    _ => data_type,
                };

                let mut dict_id = 0;
                let mut dict_is_ordered = false;

                let data_type = match map.get("dictionary") {
                    Some(dictionary) => {
                        let index_type = match dictionary.get("indexType") {
                            Some(t) => DataType::from(t)?,
                            _ => {
                                return Err(ArrowError::ParseError(
                                    "Field missing 'indexType' attribute".to_string(),
                                ));
                            }
                        };
                        dict_id = match dictionary.get("id") {
                            Some(Value::Number(n)) => n.as_i64().unwrap(),
                            _ => {
                                return Err(ArrowError::ParseError(
                                    "Field missing 'id' attribute".to_string(),
                                ));
                            }
                        };
                        dict_is_ordered = match dictionary.get("isOrdered") {
                            Some(&Value::Bool(n)) => n,
                            _ => {
                                return Err(ArrowError::ParseError(
                                    "Field missing 'isOrdered' attribute".to_string(),
                                ));
                            }
                        };
                        DataType::Dictionary(Box::new(index_type), Box::new(data_type))
                    }
                    _ => data_type,
                };
                Ok(Field {
                    name,
                    nullable,
                    data_type,
                    dict_id,
                    dict_is_ordered,
                })
            }
            _ => Err(ArrowError::ParseError(
                "Invalid json value type for field".to_string(),
            )),
        }
    }
/// Parse a `Field` definition from a JSON representation
Parse a `Field` definition from a JSON representation
Parse a ` Field ` definition from a JSON representation
pub fn from(json: &Value) -> Result<Self> {
        match *json {
            Value::Object(ref map) => {
                let name = match map.get("name") {
                    Some(&Value::String(ref name)) => name.to_string(),
                    _ => {
                        return Err(ArrowError::ParseError(
                            "Field missing 'name' attribute".to_string(),
                        ));
                    }
                };
                let nullable = match map.get("nullable") {
                    Some(&Value::Bool(b)) => b,
                    _ => {
                        return Err(ArrowError::ParseError(
                            "Field missing 'nullable' attribute".to_string(),
                        ));
                    }
                };
                let data_type = match map.get("type") {
                    Some(t) => DataType::from(t)?,
                    _ => {
                        return Err(ArrowError::ParseError(
                            "Field missing 'type' attribute".to_string(),
                        ));
                    }
                };
                // if data_type is a struct or list, get its children
                let data_type = match data_type {
                    DataType::List(_) | DataType::FixedSizeList(_, _) => {
                        match map.get("children") {
                            Some(Value::Array(values)) => {
                                if values.len() != 1 {
                                    return Err(ArrowError::ParseError(
                                    "Field 'children' must have one element for a list data type".to_string(),
                                ));
                                }
                                match data_type {
                                    DataType::List(_) => DataType::List(Box::new(
                                        Self::from(&values[0])?.data_type,
                                    )),
                                    DataType::FixedSizeList(_, int) => {
                                        DataType::FixedSizeList(
                                            Box::new(Self::from(&values[0])?.data_type),
                                            int,
                                        )
                                    }
                                    _ => unreachable!(
                                        "Data type should be a list or fixedsizelist"
                                    ),
                                }
                            }
                            Some(_) => {
                                return Err(ArrowError::ParseError(
                                    "Field 'children' must be an array".to_string(),
                                ))
                            }
                            None => {
                                return Err(ArrowError::ParseError(
                                    "Field missing 'children' attribute".to_string(),
                                ));
                            }
                        }
                    }
                    DataType::Struct(mut fields) => match map.get("children") {
                        Some(Value::Array(values)) => {
                            let struct_fields: Result<Vec<Field>> =
                                values.iter().map(|v| Field::from(v)).collect();
                            fields.append(&mut struct_fields?);
                            DataType::Struct(fields)
                        }
                        Some(_) => {
                            return Err(ArrowError::ParseError(
                                "Field 'children' must be an array".to_string(),
                            ))
                        }
                        None => {
                            return Err(ArrowError::ParseError(
                                "Field missing 'children' attribute".to_string(),
                            ));
                        }
                    },
                    _ => data_type,
                };
                let mut dict_id = 0;
                let mut dict_is_ordered = false;
                let data_type = match map.get("dictionary") {
                    Some(dictionary) => {
                        let index_type = match dictionary.get("indexType") {
                            Some(t) => DataType::from(t)?,
                            _ => {
                                return Err(ArrowError::ParseError(
                                    "Field missing 'indexType' attribute".to_string(),
                                ));
                            }
                        };
                        dict_id = match dictionary.get("id") {
                            Some(Value::Number(n)) => n.as_i64().unwrap(),
                            _ => {
                                return Err(ArrowError::ParseError(
                                    "Field missing 'id' attribute".to_string(),
                                ));
                            }
                        };
                        dict_is_ordered = match dictionary.get("isOrdered") {
                            Some(&Value::Bool(n)) => n,
                            _ => {
                                return Err(ArrowError::ParseError(
                                    "Field missing 'isOrdered' attribute".to_string(),
                                ));
                            }
                        };
                        DataType::Dictionary(Box::new(index_type), Box::new(data_type))
                    }
                    _ => data_type,
                };
                Ok(Field {
                    name,
                    nullable,
                    data_type,
                    dict_id,
                    dict_is_ordered,
                })
            }
            _ => Err(ArrowError::ParseError(
                "Invalid json value type for field".to_string(),
            )),
        }
    }
pub fn from ( json : & Value ) -> Result < Self > { match * json { Value :: Object ( ref map ) => { let name = match map . get ( " " ) { Some ( & Value :: String ( ref name ) ) => name . to_string ( ) , _ => { return Err ( ArrowError :: ParseError ( " " . to_string ( ) , ) ) ; } } ; let nullable = match map . get ( " " ) { Some ( & Value :: Bool ( b ) ) => b , _ => { return Err ( ArrowError :: ParseError ( " " . to_string ( ) , ) ) ; } } ; let data_type = match map . get ( " " ) { Some ( t ) => DataType :: from ( t ) ? , _ => { return Err ( ArrowError :: ParseError ( " " . to_string ( ) , ) ) ; } } ; // if data_type is a struct or list, get its children let data_type = match data_type { DataType :: List ( _ ) | DataType :: FixedSizeList ( _ , _ ) => { match map . get ( " " ) { Some ( Value :: Array ( values ) ) => { if values . len ( ) != 1 { return Err ( ArrowError :: ParseError ( " " . to_string ( ) , ) ) ; } match data_type { DataType :: List ( _ ) => DataType :: List ( Box :: new ( Self :: from ( & values [ 0 ] ) ? . data_type , ) ) , DataType :: FixedSizeList ( _ , int ) => { DataType :: FixedSizeList ( Box :: new ( Self :: from ( & values [ 0 ] ) ? . data_type ) , int , ) } _ => unreachable ! ( " " ) , } } Some ( _ ) => { return Err ( ArrowError :: ParseError ( " " . to_string ( ) , ) ) } None => { return Err ( ArrowError :: ParseError ( " " . to_string ( ) , ) ) ; } } } DataType :: Struct ( mut fields ) => match map . get ( " " ) { Some ( Value :: Array ( values ) ) => { let struct_fields : Result < Vec < Field > > = values . iter ( ) . map ( | v | Field :: from ( v ) ) . collect ( ) ; fields . append ( & mut struct_fields ? ) ; DataType :: Struct ( fields ) } Some ( _ ) => { return Err ( ArrowError :: ParseError ( " " . to_string ( ) , ) ) } None => { return Err ( ArrowError :: ParseError ( " " . to_string ( ) , ) ) ; } } , _ => data_type , } ; let mut dict_id = 0 ; let mut dict_is_ordered = false ; let data_type = match map . get ( " " ) { Some ( dictionary ) => { let index_type = match dictionary . get ( " " ) { Some ( t ) => DataType :: from ( t ) ? , _ => { return Err ( ArrowError :: ParseError ( " " . to_string ( ) , ) ) ; } } ; dict_id = match dictionary . get ( " " ) { Some ( Value :: Number ( n ) ) => n . as_i64 ( ) . unwrap ( ) , _ => { return Err ( ArrowError :: ParseError ( " " . to_string ( ) , ) ) ; } } ; dict_is_ordered = match dictionary . get ( " " ) { Some ( & Value :: Bool ( n ) ) => n , _ => { return Err ( ArrowError :: ParseError ( " " . to_string ( ) , ) ) ; } } ; DataType :: Dictionary ( Box :: new ( index_type ) , Box :: new ( data_type ) ) } _ => data_type , } ; Ok ( Field { name , nullable , data_type , dict_id , dict_is_ordered , } ) } _ => Err ( ArrowError :: ParseError ( " " . to_string ( ) , ) ) , } }
Parse a `Field` definition from a JSON representation
Parse a ` Field ` definition from a JSON representation
json
&Value
json
&Value