rewritten.firstStageEvals[0] = createCountRowFunction(function.getArgs());
} else {
rewritten.firstStageEvals[0] = createCountFunction(function.getArgs());
}
String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]);
FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType());
rewritten.firstStageTargets[0] = new Target(fieldEval);
rewritten.secondStageEvals = createSumFunction(new EvalNode[] {fieldEval});
} else if (function.getName().equalsIgnoreCase("sum")) {
rewritten = new RewrittenFunctions(1);
rewritten.firstStageEvals[0] = createSumFunction(function.getArgs());
String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]);
FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType());
rewritten.firstStageTargets[0] = new Target(fieldEval);
rewritten.secondStageEvals = createSumFunction(new EvalNode[] {fieldEval});
} else if (function.getName().equals("max")) {
rewritten = new RewrittenFunctions(1);
rewritten.firstStageEvals[0] = createMaxFunction(function.getArgs());
String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]);
FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType());
rewritten.firstStageTargets[0] = new Target(fieldEval);
rewritten.secondStageEvals = createMaxFunction(new EvalNode[]{fieldEval});
} else if (function.getName().equals("min")) {
rewritten = new RewrittenFunctions(1);
rewritten.firstStageEvals[0] = createMinFunction(function.getArgs());
String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]);
FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType());
rewritten.firstStageTargets[0] = new Target(fieldEval);
rewritten.secondStageEvals = createMinFunction(new EvalNode[]{fieldEval});
} else {
throw new PlanningException("Cannot support a mix of other functions");