pub(crate) fn expr_to_root_column_expr(expr: &Expr) -> Result<&Expr> {
    match expr {
        Expr::Column(_) => Ok(expr),
        Expr::Duplicated(expr) => expr_to_root_column_expr(expr),
        Expr::Unique(expr) => expr_to_root_column_expr(expr),
        Expr::Reverse(expr) => expr_to_root_column_expr(expr),
        Expr::Alias(expr, _) => expr_to_root_column_expr(expr),
        Expr::Not(expr) => expr_to_root_column_expr(expr),
        Expr::IsNull(expr) => expr_to_root_column_expr(expr),
        Expr::IsNotNull(expr) => expr_to_root_column_expr(expr),
        Expr::AggFirst(expr) => expr_to_root_column_expr(expr),
        Expr::AggLast(expr) => expr_to_root_column_expr(expr),
        Expr::AggGroups(expr) => expr_to_root_column_expr(expr),
        Expr::AggNUnique(expr) => expr_to_root_column_expr(expr),
        Expr::AggQuantile { expr, .. } => expr_to_root_column_expr(expr),
        Expr::AggSum(expr) => expr_to_root_column_expr(expr),
        Expr::AggMin(expr) => expr_to_root_column_expr(expr),
        Expr::AggMax(expr) => expr_to_root_column_expr(expr),
        Expr::AggMedian(expr) => expr_to_root_column_expr(expr),
        Expr::AggMean(expr) => expr_to_root_column_expr(expr),
        Expr::AggCount(expr) => expr_to_root_column_expr(expr),
        Expr::BinaryExpr { left, right, .. } => match expr_to_root_column_expr(left) {
            Err(_) => expr_to_root_column_expr(right),
            Ok(expr) => match expr_to_root_column_expr(right) {
                Ok(_) => Err(PolarsError::Other(
                    format!(
                        "cannot find root column expr for binary expression {:?}, {:?}",
                        left, right
                    )
                    .into(),
                )),
                Err(_) => Ok(expr),
            },
        },
        Expr::Sort { expr, .. } => expr_to_root_column_expr(expr),
        Expr::Shift { input, .. } => expr_to_root_column_expr(input),
        Expr::Apply { input, .. } => expr_to_root_column_expr(input),
        Expr::Cast { expr, .. } => expr_to_root_column_expr(expr),
        Expr::Ternary { predicate, .. } => expr_to_root_column_expr(predicate),
        Expr::Wildcard => Ok(expr),
        a => Err(PolarsError::Other(
            format!("No root column expr could be found for {:?}", a).into(),
        )),
    }
}
// unpack alias(col) to name of the root column name
unpack alias(col) to name of the root column name
unpack alias ( col ) to name of the root column name
pub(crate) fn expr_to_root_column_expr(expr: &Expr) -> Result<&Expr> {
    match expr {
        Expr::Column(_) => Ok(expr),
        Expr::Duplicated(expr) => expr_to_root_column_expr(expr),
        Expr::Unique(expr) => expr_to_root_column_expr(expr),
        Expr::Reverse(expr) => expr_to_root_column_expr(expr),
        Expr::Alias(expr, _) => expr_to_root_column_expr(expr),
        Expr::Not(expr) => expr_to_root_column_expr(expr),
        Expr::IsNull(expr) => expr_to_root_column_expr(expr),
        Expr::IsNotNull(expr) => expr_to_root_column_expr(expr),
        Expr::AggFirst(expr) => expr_to_root_column_expr(expr),
        Expr::AggLast(expr) => expr_to_root_column_expr(expr),
        Expr::AggGroups(expr) => expr_to_root_column_expr(expr),
        Expr::AggNUnique(expr) => expr_to_root_column_expr(expr),
        Expr::AggQuantile { expr, .. } => expr_to_root_column_expr(expr),
        Expr::AggSum(expr) => expr_to_root_column_expr(expr),
        Expr::AggMin(expr) => expr_to_root_column_expr(expr),
        Expr::AggMax(expr) => expr_to_root_column_expr(expr),
        Expr::AggMedian(expr) => expr_to_root_column_expr(expr),
        Expr::AggMean(expr) => expr_to_root_column_expr(expr),
        Expr::AggCount(expr) => expr_to_root_column_expr(expr),
        Expr::BinaryExpr { left, right, .. } => match expr_to_root_column_expr(left) {
            Err(_) => expr_to_root_column_expr(right),
            Ok(expr) => match expr_to_root_column_expr(right) {
                Ok(_) => Err(PolarsError::Other(
                    format!(
                        "cannot find root column expr for binary expression {:?}, {:?}",
                        left, right
                    )
                    .into(),
                )),
                Err(_) => Ok(expr),
            },
        },
        Expr::Sort { expr, .. } => expr_to_root_column_expr(expr),
        Expr::Shift { input, .. } => expr_to_root_column_expr(input),
        Expr::Apply { input, .. } => expr_to_root_column_expr(input),
        Expr::Cast { expr, .. } => expr_to_root_column_expr(expr),
        Expr::Ternary { predicate, .. } => expr_to_root_column_expr(predicate),
        Expr::Wildcard => Ok(expr),
        a => Err(PolarsError::Other(
            format!("No root column expr could be found for {:?}", a).into(),
        )),
    }
}
pub ( crate ) fn expr_to_root_column_expr ( expr : & Expr ) -> Result < & Expr > { match expr { Expr :: Column ( _ ) => Ok ( expr ) , Expr :: Duplicated ( expr ) => expr_to_root_column_expr ( expr ) , Expr :: Unique ( expr ) => expr_to_root_column_expr ( expr ) , Expr :: Reverse ( expr ) => expr_to_root_column_expr ( expr ) , Expr :: Alias ( expr , _ ) => expr_to_root_column_expr ( expr ) , Expr :: Not ( expr ) => expr_to_root_column_expr ( expr ) , Expr :: IsNull ( expr ) => expr_to_root_column_expr ( expr ) , Expr :: IsNotNull ( expr ) => expr_to_root_column_expr ( expr ) , Expr :: AggFirst ( expr ) => expr_to_root_column_expr ( expr ) , Expr :: AggLast ( expr ) => expr_to_root_column_expr ( expr ) , Expr :: AggGroups ( expr ) => expr_to_root_column_expr ( expr ) , Expr :: AggNUnique ( expr ) => expr_to_root_column_expr ( expr ) , Expr :: AggQuantile { expr , .. } => expr_to_root_column_expr ( expr ) , Expr :: AggSum ( expr ) => expr_to_root_column_expr ( expr ) , Expr :: AggMin ( expr ) => expr_to_root_column_expr ( expr ) , Expr :: AggMax ( expr ) => expr_to_root_column_expr ( expr ) , Expr :: AggMedian ( expr ) => expr_to_root_column_expr ( expr ) , Expr :: AggMean ( expr ) => expr_to_root_column_expr ( expr ) , Expr :: AggCount ( expr ) => expr_to_root_column_expr ( expr ) , Expr :: BinaryExpr { left , right , .. } => match expr_to_root_column_expr ( left ) { Err ( _ ) => expr_to_root_column_expr ( right ) , Ok ( expr ) => match expr_to_root_column_expr ( right ) { Ok ( _ ) => Err ( PolarsError :: Other ( format ! ( " " left right ) . into ( ) , ) ) , Err ( _ ) => Ok ( expr ) , } , } , Expr :: Sort { expr , .. } => expr_to_root_column_expr ( expr ) , Expr :: Shift { input , .. } => expr_to_root_column_expr ( input ) , Expr :: Apply { input , .. } => expr_to_root_column_expr ( input ) , Expr :: Cast { expr , .. } => expr_to_root_column_expr ( expr ) , Expr :: Ternary { predicate , .. } => expr_to_root_column_expr ( predicate ) , Expr :: Wildcard => Ok ( expr ) , a => Err ( PolarsError :: Other ( format ! ( " " a ) . into ( ) , ) ) , } }
unpack alias(col) to name of the root column name
unpack alias ( col ) to name of the root column name
expr
&Expr
expr
&Expr