}
if (!hasExpression) {
return query;
}
Select select = query.getSelect();
GroupBy groupBy = query.getGroupBy();
query.setGroupBy(null);
Criteria having = query.getHaving();
query.setHaving(null);
OrderBy orderBy = query.getOrderBy();
query.setOrderBy(null);
Limit limit = query.getLimit();
query.setLimit(null);
Into into = query.getInto();
query.setInto(null);
Set<Expression> newSelectColumns = new HashSet<Expression>();
for (final Iterator iterator = groupBy.getSymbols().iterator(); iterator.hasNext();) {
newSelectColumns.add(SymbolMap.getExpression((SingleElementSymbol)iterator.next()));
}
Set<AggregateSymbol> aggs = new HashSet<AggregateSymbol>();
aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(select, true));
if (having != null) {