// but it's certainly pleasant to have the final result grouped
// on nodes by group by columns.
final boolean newLevel = !(_it.isHashedBy(lastComponent, groupByColumns));
if (newLevel) {
lastComponent.setHashIndexes(groupByColumns);
new OperatorComponent(lastComponent, ParserUtil.generateUniqueName("OPERATOR"),
_cg.getQueryPlan()).addOperator(firstAgg);
} else
lastComponent.addOperator(firstAgg);
} else {
// Sometimes groupByVEs contains other functions, so we have to
// use projections instead of simple groupBy
// always new level
// WARNING: groupByVEs cannot be used on two places: that's why
// we do deep copy
final ProjectOperator groupByProj = new ProjectOperator(
(List<ValueExpression>) DeepCopy.copy(groupByVEs));
if (!(groupByProj.getExpressions() == null || groupByProj.getExpressions()
.isEmpty()))
firstAgg.setGroupByProjection(groupByProj);
// current component
lastComponent.setHashExpressions((List<ValueExpression>) DeepCopy.copy(groupByVEs));
new OperatorComponent(lastComponent, ParserUtil.generateUniqueName("OPERATOR"),
_cg.getQueryPlan()).addOperator(firstAgg);
}
} else
throw new RuntimeException("For now only one aggregate function supported!");
}