pub fn aggregate_expression_to_logical_plan(expr: &parser::Expression) -> (Aggregate, Box<Expression>) {
    match expr {
        parser::Expression::Variable(ident) => {
            (Aggregate::KeyPart, Box::new(Expression::Variable(identifier_to_logical_plan(&ident))))
        }
        parser::Expression::Function(name, args) => {
            match name {
                parser::Identifier::SimpleIdentifier(name) => {
                    match name.to_lowercase().as_str() {
                        "count" => {
                            (Aggregate::Count, expression_to_logical_plan(args[0].as_ref()))
                        }
                        "sum" => {
                            (Aggregate::Sum, expression_to_logical_plan(args[0].as_ref()))
                        }
                        _ => unimplemented!(),
                    }
                }
                _ => unimplemented!(),
            }
        }
        _ => {
            dbg!(expr);
            panic!("invalid aggregate expression")
        }
    }
}
// TODO: Maybe it should be Aggregate(Expr), this way the aggregate receives the record batch and calculates everything itself.
// Would be easier for stars and stuff I suppose.
// Think about it.
// The Cons is that each aggregate will have to define evaluating the underlying expression, which might be meh.
// Especially since star and star distinct can operate on some kind of tuple... maybe?
Maybe it should be Aggregate(Expr), this way the aggregate receives the record batch and calculates everything itself.
Would be easier for stars and stuff I suppose.
Think about it.
The Cons is that each aggregate will have to define evaluating the underlying expression, which might be meh.
Especially since star and star distinct can operate on some kind of tuple...
Maybe it should be Aggregate ( Expr ) this way the aggregate receives the record batch and calculates everything itself . Would be easier for stars and stuff I suppose . Think about it . The Cons is that each aggregate will have to define evaluating the underlying expression which might be meh . Especially since star and star distinct can operate on some kind of tuple ...
pub fn aggregate_expression_to_logical_plan(expr: &parser::Expression) -> (Aggregate, Box<Expression>) {
    match expr {
        parser::Expression::Variable(ident) => {
            (Aggregate::KeyPart, Box::new(Expression::Variable(identifier_to_logical_plan(&ident))))
        }
        parser::Expression::Function(name, args) => {
            match name {
                parser::Identifier::SimpleIdentifier(name) => {
                    match name.to_lowercase().as_str() {
                        "count" => {
                            (Aggregate::Count, expression_to_logical_plan(args[0].as_ref()))
                        }
                        "sum" => {
                            (Aggregate::Sum, expression_to_logical_plan(args[0].as_ref()))
                        }
                        _ => unimplemented!(),
                    }
                }
                _ => unimplemented!(),
            }
        }
        _ => {
            dbg!(expr);
            panic!("invalid aggregate expression")
        }
    }
}
pub fn aggregate_expression_to_logical_plan ( expr : & parser :: Expression ) -> ( Aggregate , Box < Expression > ) { match expr { parser :: Expression :: Variable ( ident ) => { ( Aggregate :: KeyPart , Box :: new ( Expression :: Variable ( identifier_to_logical_plan ( & ident ) ) ) ) } parser :: Expression :: Function ( name , args ) => { match name { parser :: Identifier :: SimpleIdentifier ( name ) => { match name . to_lowercase ( ) . as_str ( ) { " " => { ( Aggregate :: Count , expression_to_logical_plan ( args [ 0 ] . as_ref ( ) ) ) } " " => { ( Aggregate :: Sum , expression_to_logical_plan ( args [ 0 ] . as_ref ( ) ) ) } _ => unimplemented ! ( ) , } } _ => unimplemented ! ( ) , } } _ => { dbg ! ( expr ) ; panic ! ( " " ) } } }
TODO: Maybe it should be Aggregate(Expr), this way the aggregate receives the record batch and calculates everything itself.
TODO : Maybe it should be Aggregate ( Expr ) this way the aggregate receives the record batch and calculates everything itself .
expr
&parser::Expression
expr
&parser::Expression