* select expressions
* group
*/
// Preparation: sort SELECT clause into assignments and projects.
VarExprList projectVars = query.getProject() ;
VarExprList exprs = new VarExprList() ; // Assignments to be done.
List<Var> vars = new ArrayList<Var>() ; // projection variables
Op op = pattern ;
// ---- GROUP BY
if ( query.hasGroupBy() )
{
// When there is no GroupBy but there are some aggregates, it's a group of no variables.
op = new OpGroup(op, query.getGroupBy(), query.getAggregators()) ;
}
//---- Assignments from SELECT and other places (so available to ORDER and HAVING)
// Now do assignments from expressions
// Must be after "group by" has introduced it's variables.
// Look for assignments in SELECT expressions.
if ( ! projectVars.isEmpty() && ! query.isQueryResultStar())
{
// Don't project for QueryResultStar so initial bindings show
// through in SELECT *
if ( projectVars.size() == 0 && query.isSelectType() )
Log.warn(this,"No project variables") ;
// Separate assignments and variable projection.
for ( Var v : query.getProject().getVars() )
{
Expr e = query.getProject().getExpr(v) ;
if ( e != null )
{
Expr e2 = ExprLib.replaceAggregateByVariable(e) ;
exprs.add(v, e2) ;
}
// Include in project
vars.add(v) ;
}
}
// ---- Assignments from SELECT and other places (so available to ORDER and HAVING)
if ( ! exprs.isEmpty() )
// Potential rewrites based of assign introducing aliases.
op = OpExtend.extend(op, exprs) ;
// ---- HAVING
if ( query.hasHaving() )