// boolean has_count = (clone_types.contains(ExpressionType.AGGREGATE_COUNT) ||
// clone_types.contains(ExpressionType.AGGREGATE_COUNT_STAR));
int orig_cnt = clone_types.size();
for (int i = 0; i < orig_cnt; i++) {
ExpressionType cloneType = clone_types.get(i);
// Ok, strap on your helmets boys, here's what we got going on here...
// In order to do a distributed average, we need to send the average
// AND the count (in order to compute the weight average at the base partition).
// We need check whether we already have a count already in our list
// If not, then we'll want to insert it here.
if (cloneType == ExpressionType.AGGREGATE_AVG) {
if (has_count == false) {
// But now because we add a new output column that we're going to use internally,
// we need to make sure that our output columns reflect this.
clone_types.add(ExpressionType.AGGREGATE_COUNT_STAR);
has_count = true;
// Aggregate Input Column
// We just need to do it against the first column in the child's output
// Picking the column that we want to use doesn't matter even if there is a GROUP BY
clone_agg.getAggregateColumnGuids().add(node.getChild(0).getOutputColumnGUID(0));
// Aggregate Output Column
TupleValueExpression exp = new TupleValueExpression();
exp.setValueType(VoltType.BIGINT);
exp.setValueSize(VoltType.BIGINT.getLengthInBytesForFixedTypes());
exp.setTableName(PlanAssembler.AGGREGATE_TEMP_TABLE);
exp.setColumnName("");
exp.setColumnAlias("_DTXN_COUNT");
exp.setColumnIndex(clone_agg.getOutputColumnGUIDCount());
PlanColumn new_pc = state.plannerContext.getPlanColumn(exp, exp.getColumnAlias());
clone_agg.getAggregateOutputColumns().add(clone_agg.getOutputColumnGUIDCount());
clone_agg.getAggregateColumnNames().add(new_pc.getDisplayName());
clone_agg.getOutputColumnGUIDs().add(new_pc.guid());
}
}
} // FOR
// Now go through the original AggregateNode (the one at the top of tree)
// and change the ExpressiontTypes for the aggregates to handle ahat we're
// doing down below in the distributed query
List<ExpressionType> exp_types = node.getAggregateTypes();
exp_types.clear();
for (int i = 0; i < orig_cnt; i++) {
ExpressionType cloneType = clone_types.get(i);
switch (cloneType) {
case AGGREGATE_COUNT:
case AGGREGATE_COUNT_STAR:
case AGGREGATE_SUM:
exp_types.add(ExpressionType.AGGREGATE_SUM);