pub(crate) fn expr_to_root_column(expr: &Expr) -> Result<Arc<String>> {
    match expr {
        Expr::Duplicated(expr) => expr_to_root_column(expr),
        Expr::Unique(expr) => expr_to_root_column(expr),
        Expr::Reverse(expr) => expr_to_root_column(expr),
        Expr::Column(name) => Ok(name.clone()),
        Expr::Alias(expr, _) => expr_to_root_column(expr),
        Expr::Not(expr) => expr_to_root_column(expr),
        Expr::IsNull(expr) => expr_to_root_column(expr),
        Expr::IsNotNull(expr) => expr_to_root_column(expr),
        Expr::BinaryExpr { left, right, .. } => {
            let mut left = expr_to_root_column(left);
            let mut right = expr_to_root_column(right);

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