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() )
{
for (Expr expr : query.getHavingExprs())
{
// HAVING expression to refer to the aggregate via the variable.
Expr expr2 = ExprLib.replaceAggregateByVariable(expr) ;
op = OpFilter.filter(expr2 , op) ;
}
}
// ---- BINDINGS
if ( query.hasBindings() )
{
Table table = TableFactory.create() ;
for ( Binding binding : query.getBindingValues() )
table.addBinding(binding) ;
OpTable opTable = OpTable.create(table) ;
op = OpJoin.create(op, opTable) ;
}
// ---- ToList
if ( context.isTrue(ARQ.generateToList) )
// Listify it.
op = new OpList(op) ;
// ---- ORDER BY
if ( query.getOrderBy() != null )
{
List<SortCondition> scList = new ArrayList<SortCondition>() ;
// Aggregates in ORDER BY
for ( SortCondition sc : query.getOrderBy() )
{
Expr e = sc.getExpression() ;
e = ExprLib.replaceAggregateByVariable(e) ;
scList.add(new SortCondition(e, sc.getDirection())) ;
}
op = new OpOrder(op, scList) ;