* new Aggregation Desc of the new GroupByOperator.
*/
private static class NewQueryGroupbySchemaProc implements NodeProcessor {
public Object process(Node nd, Stack<Node> stack, NodeProcessorCtx ctx,
Object... nodeOutputs) throws SemanticException {
GroupByOperator operator = (GroupByOperator)nd;
rewriteQueryCtx = (RewriteQueryUsingAggregateIndexCtx)ctx;
//We need to replace the GroupByOperator which is in
//groupOpToInputTables map with the new GroupByOperator
if(rewriteQueryCtx.getParseContext().getGroupOpToInputTables().containsKey(operator)){
List<ExprNodeDesc> gbyKeyList = operator.getConf().getKeys();
String gbyKeys = null;
Iterator<ExprNodeDesc> gbyKeyListItr = gbyKeyList.iterator();
while(gbyKeyListItr.hasNext()){
ExprNodeDesc expr = gbyKeyListItr.next().clone();
if(expr instanceof ExprNodeColumnDesc){
ExprNodeColumnDesc colExpr = (ExprNodeColumnDesc)expr;
gbyKeys = colExpr.getColumn();
if(gbyKeyListItr.hasNext()){
gbyKeys = gbyKeys + ",";
}
}
}
//the query contains the sum aggregation GenericUDAF
String selReplacementCommand = "select sum(`"
+ rewriteQueryCtx.getAggregateFunction() + "`)"
+ " from " + rewriteQueryCtx.getIndexName()
+ " group by " + gbyKeys + " ";
//create a new ParseContext for the query to retrieve its operator tree,
//and the required GroupByOperator from it
ParseContext newDAGContext = RewriteParseContextGenerator.generateOperatorTree(
rewriteQueryCtx.getParseContext().getConf(),
selReplacementCommand);
//we get our new GroupByOperator here
Map<GroupByOperator, Set<String>> newGbyOpMap = newDAGContext.getGroupOpToInputTables();
GroupByOperator newGbyOperator = newGbyOpMap.keySet().iterator().next();
GroupByDesc oldConf = operator.getConf();
//we need this information to set the correct colList, outputColumnNames in SelectOperator
ExprNodeColumnDesc aggrExprNode = null;
//Construct the new AggregationDesc to get rid of the current
//internal names and replace them with new internal names
//as required by the operator tree
GroupByDesc newConf = newGbyOperator.getConf();
List<AggregationDesc> newAggrList = newConf.getAggregators();
if(newAggrList != null && newAggrList.size() > 0){
for (AggregationDesc aggregationDesc : newAggrList) {
rewriteQueryCtx.setEval(aggregationDesc.getGenericUDAFEvaluator());
aggrExprNode = (ExprNodeColumnDesc)aggregationDesc.getParameters().get(0);