//Also, we do not rewrite for cases when same query branch has multiple group-by constructs
if(canApplyCtx.getParseContext().getGroupOpToInputTables().containsKey(operator) &&
!canApplyCtx.isQueryHasGroupBy()){
canApplyCtx.setQueryHasGroupBy(true);
GroupByDesc conf = (GroupByDesc) operator.getConf();
List<AggregationDesc> aggrList = conf.getAggregators();
if(aggrList != null && aggrList.size() > 0){
for (AggregationDesc aggregationDesc : aggrList) {
canApplyCtx.setAggFuncCnt(canApplyCtx.getAggFuncCnt() + 1);
//In the current implementation, we do not support more than 1 agg funcs in group-by
if(canApplyCtx.getAggFuncCnt() > 1) {
return false;
}
String aggFunc = aggregationDesc.getGenericUDAFName();
if(!("count".equals(aggFunc))){
canApplyCtx.setAggFuncIsNotCount(true);
}else{
List<ExprNodeDesc> para = aggregationDesc.getParameters();
//for a valid aggregation, it needs to have non-null parameter list
if(para == null){
canApplyCtx.setAggFuncColsFetchException(true);
}else if(para.size() == 0){
//count(*) case
canApplyCtx.setCountOnAllCols(true);
canApplyCtx.setAggFunction("_count_of_all");
}else{
assert para.size()==1;
for(int i=0; i< para.size(); i++){
ExprNodeDesc expr = para.get(i);
if(expr instanceof ExprNodeColumnDesc){
//Add the columns to RewriteCanApplyCtx's selectColumnsList list
//to check later if index keys contain all select clause columns
//and vice-a-versa. We get the select column 'actual' names only here
//if we have a agg func along with group-by
//SelectOperator has internal names in its colList data structure
canApplyCtx.getSelectColumnsList().add(
((ExprNodeColumnDesc) expr).getColumn());
//Add the columns to RewriteCanApplyCtx's aggFuncColList list to check later
//if columns contained in agg func are index key columns
canApplyCtx.getAggFuncColList().add(
((ExprNodeColumnDesc) expr).getColumn());
canApplyCtx.setAggFunction("_count_of_" +
((ExprNodeColumnDesc) expr).getColumn() + "");
}else if(expr instanceof ExprNodeConstantDesc){
//count(1) case
canApplyCtx.setCountOfOne(true);
canApplyCtx.setAggFunction("_count_of_1");
}
}
}
}
}
}
//we need to have non-null group-by keys for a valid group-by operator
List<ExprNodeDesc> keyList = conf.getKeys();
if(keyList == null || keyList.size() == 0){
canApplyCtx.setGbyKeysFetchException(true);
}
for (ExprNodeDesc expr : keyList) {
checkExpression(expr);