pub(crate) fn to_field(&self, schema: &Schema) -> Result<Field> {
        use Expr::*;
        match self {
            Alias(expr, name) => Ok(Field::new(name, expr.get_type(schema)?, true)),
            Column(name) => {
                let field = schema.field_with_name(name).map(|f| f.clone())?;
                Ok(field)
            }
            Literal(sv) => Ok(Field::new("lit", sv.get_datatype(), true)),
            BinaryExpr { left, right, .. } => {
                let left_type = left.get_type(schema)?;
                let right_type = right.get_type(schema)?;
                let expr_type = get_supertype(&left_type, &right_type)?;
                Ok(Field::new("binary_expr", expr_type, true))
            }
            Not(_) => Ok(Field::new("not", ArrowDataType::Boolean, true)),
            IsNull(_) => Ok(Field::new("is_null", ArrowDataType::Boolean, true)),
            IsNotNull(_) => Ok(Field::new("is_not_null", ArrowDataType::Boolean, true)),
            Sort { expr, .. } => expr.to_field(schema),
            AggMin(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::Min);
                Ok(rename_field(&field, &new_name))
            }
            AggMax(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::Max);
                Ok(rename_field(&field, &new_name))
            }
            AggMedian(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::Median);
                Ok(rename_field(&field, &new_name))
            }
            AggMean(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::Mean);
                Ok(rename_field(&field, &new_name))
            }
            AggFirst(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::First);
                Ok(rename_field(&field, &new_name))
            }
            AggLast(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::Last);
                Ok(rename_field(&field, &new_name))
            }
            AggNUnique(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::NUnique);
                let new_field = Field::new(&new_name, ArrowDataType::UInt32, field.is_nullable());
                Ok(new_field)
            }
            AggSum(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::Sum);
                Ok(rename_field(&field, &new_name))
            }
            AggGroups(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::Groups);
                let new_field = Field::new(&new_name, ArrowDataType::UInt32, field.is_nullable());
                Ok(new_field)
            }
            AggQuantile { expr, quantile } => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::Quantile(*quantile));
                Ok(rename_field(&field, &new_name))
            }
            Cast { expr, data_type } => {
                let field = expr.to_field(schema)?;
                Ok(Field::new(
                    field.name(),
                    data_type.clone(),
                    field.is_nullable(),
                ))
            }
            Ternary { truthy, .. } => truthy.to_field(schema),
        }
    }
/// Get Field result of the expression. The schema is the input data.
Get Field result of the expression. The schema is the input data.
Get Field result of the expression . The schema is the input data .
pub(crate) fn to_field(&self, schema: &Schema) -> Result<Field> {
        use Expr::*;
        match self {
            Alias(expr, name) => Ok(Field::new(name, expr.get_type(schema)?, true)),
            Column(name) => {
                let field = schema.field_with_name(name).map(|f| f.clone())?;
                Ok(field)
            }
            Literal(sv) => Ok(Field::new("lit", sv.get_datatype(), true)),
            BinaryExpr { left, right, .. } => {
                let left_type = left.get_type(schema)?;
                let right_type = right.get_type(schema)?;
                let expr_type = get_supertype(&left_type, &right_type)?;
                Ok(Field::new("binary_expr", expr_type, true))
            }
            Not(_) => Ok(Field::new("not", ArrowDataType::Boolean, true)),
            IsNull(_) => Ok(Field::new("is_null", ArrowDataType::Boolean, true)),
            IsNotNull(_) => Ok(Field::new("is_not_null", ArrowDataType::Boolean, true)),
            Sort { expr, .. } => expr.to_field(schema),
            AggMin(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::Min);
                Ok(rename_field(&field, &new_name))
            }
            AggMax(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::Max);
                Ok(rename_field(&field, &new_name))
            }
            AggMedian(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::Median);
                Ok(rename_field(&field, &new_name))
            }
            AggMean(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::Mean);
                Ok(rename_field(&field, &new_name))
            }
            AggFirst(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::First);
                Ok(rename_field(&field, &new_name))
            }
            AggLast(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::Last);
                Ok(rename_field(&field, &new_name))
            }
            AggNUnique(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::NUnique);
                let new_field = Field::new(&new_name, ArrowDataType::UInt32, field.is_nullable());
                Ok(new_field)
            }
            AggSum(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::Sum);
                Ok(rename_field(&field, &new_name))
            }
            AggGroups(expr) => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::Groups);
                let new_field = Field::new(&new_name, ArrowDataType::UInt32, field.is_nullable());
                Ok(new_field)
            }
            AggQuantile { expr, quantile } => {
                let field = expr.to_field(schema)?;
                let new_name = fmt_groupby_column(field.name(), GroupByMethod::Quantile(*quantile));
                Ok(rename_field(&field, &new_name))
            }
            Cast { expr, data_type } => {
                let field = expr.to_field(schema)?;
                Ok(Field::new(
                    field.name(),
                    data_type.clone(),
                    field.is_nullable(),
                ))
            }
            Ternary { truthy, .. } => truthy.to_field(schema),
        }
    }
pub ( crate ) fn to_field ( & self , schema : & Schema ) -> Result < Field > { use Expr :: * ; match self { Alias ( expr , name ) => Ok ( Field :: new ( name , expr . get_type ( schema ) ? , true ) ) , Column ( name ) => { let field = schema . field_with_name ( name ) . map ( | f | f . clone ( ) ) ? ; Ok ( field ) } Literal ( sv ) => Ok ( Field :: new ( " " , sv . get_datatype ( ) , true ) ) , BinaryExpr { left , right , .. } => { let left_type = left . get_type ( schema ) ? ; let right_type = right . get_type ( schema ) ? ; let expr_type = get_supertype ( & left_type , & right_type ) ? ; Ok ( Field :: new ( " " , expr_type , true ) ) } Not ( _ ) => Ok ( Field :: new ( " " , ArrowDataType :: Boolean , true ) ) , IsNull ( _ ) => Ok ( Field :: new ( " " , ArrowDataType :: Boolean , true ) ) , IsNotNull ( _ ) => Ok ( Field :: new ( " " , ArrowDataType :: Boolean , true ) ) , Sort { expr , .. } => expr . to_field ( schema ) , AggMin ( expr ) => { let field = expr . to_field ( schema ) ? ; let new_name = fmt_groupby_column ( field . name ( ) , GroupByMethod :: Min ) ; Ok ( rename_field ( & field , & new_name ) ) } AggMax ( expr ) => { let field = expr . to_field ( schema ) ? ; let new_name = fmt_groupby_column ( field . name ( ) , GroupByMethod :: Max ) ; Ok ( rename_field ( & field , & new_name ) ) } AggMedian ( expr ) => { let field = expr . to_field ( schema ) ? ; let new_name = fmt_groupby_column ( field . name ( ) , GroupByMethod :: Median ) ; Ok ( rename_field ( & field , & new_name ) ) } AggMean ( expr ) => { let field = expr . to_field ( schema ) ? ; let new_name = fmt_groupby_column ( field . name ( ) , GroupByMethod :: Mean ) ; Ok ( rename_field ( & field , & new_name ) ) } AggFirst ( expr ) => { let field = expr . to_field ( schema ) ? ; let new_name = fmt_groupby_column ( field . name ( ) , GroupByMethod :: First ) ; Ok ( rename_field ( & field , & new_name ) ) } AggLast ( expr ) => { let field = expr . to_field ( schema ) ? ; let new_name = fmt_groupby_column ( field . name ( ) , GroupByMethod :: Last ) ; Ok ( rename_field ( & field , & new_name ) ) } AggNUnique ( expr ) => { let field = expr . to_field ( schema ) ? ; let new_name = fmt_groupby_column ( field . name ( ) , GroupByMethod :: NUnique ) ; let new_field = Field :: new ( & new_name , ArrowDataType :: UInt32 , field . is_nullable ( ) ) ; Ok ( new_field ) } AggSum ( expr ) => { let field = expr . to_field ( schema ) ? ; let new_name = fmt_groupby_column ( field . name ( ) , GroupByMethod :: Sum ) ; Ok ( rename_field ( & field , & new_name ) ) } AggGroups ( expr ) => { let field = expr . to_field ( schema ) ? ; let new_name = fmt_groupby_column ( field . name ( ) , GroupByMethod :: Groups ) ; let new_field = Field :: new ( & new_name , ArrowDataType :: UInt32 , field . is_nullable ( ) ) ; Ok ( new_field ) } AggQuantile { expr , quantile } => { let field = expr . to_field ( schema ) ? ; let new_name = fmt_groupby_column ( field . name ( ) , GroupByMethod :: Quantile ( * quantile ) ) ; Ok ( rename_field ( & field , & new_name ) ) } Cast { expr , data_type } => { let field = expr . to_field ( schema ) ? ; Ok ( Field :: new ( field . name ( ) , data_type . clone ( ) , field . is_nullable ( ) , ) ) } Ternary { truthy , .. } => truthy . to_field ( schema ) , } }
Get Field result of the expression.
Get Field result of the expression .
&self
schema
&Schema
&self
schema
&Schema