Program: 25188
Project: 25188
Buggy source:
private ASTNode getOuterAST(ASTNode astNode,ASTNode innerSelectAST,AliasDecider aliasDecider,StorageCandidate sc,boolean isSelectAst,Set<String> dimensionSet) throws LensException {
  if (astNode == null) {
    return null;
  }
  Set<String> msrCols=new HashSet<>();
  getAllColumnsOfNode(astNode,msrCols);
  msrCols.removeAll(dimensionSet);
  if (isAggregateAST(astNode) && sc.getColumns().containsAll(msrCols)) {
    return processAggregate(astNode,innerSelectAST,aliasDecider,isSelectAst);
  }
 else   if (isAggregateAST(astNode) && !sc.getColumns().containsAll(msrCols)) {
    ASTNode outerAST=new ASTNode(new CommonToken(HiveParser.TOK_SELEXPR,"String_Node_Str"));
    ASTNode exprCopy=MetastoreUtil.copyAST(astNode);
    setDefaultValueInExprForAggregateNodes(exprCopy,sc);
    outerAST.addChild(getOuterAST(getSelectExpr(exprCopy,null,true),innerSelectAST,aliasDecider,sc,isSelectAst,dimensionSet));
    return outerAST;
  }
 else {
    if (hasAggregate(astNode)) {
      ASTNode outerAST=new ASTNode(astNode);
      for (      Node child : astNode.getChildren()) {
        ASTNode childAST=(ASTNode)child;
        if (hasAggregate(childAST) && sc.getColumns().containsAll(msrCols)) {
          outerAST.addChild(getOuterAST(childAST,innerSelectAST,aliasDecider,sc,isSelectAst,dimensionSet));
        }
 else         if (hasAggregate(childAST) && !sc.getColumns().containsAll(msrCols)) {
          childAST.replaceChildren(1,1,getSelectExpr(null,null,true));
          outerAST.addChild(getOuterAST(childAST,innerSelectAST,aliasDecider,sc,isSelectAst,dimensionSet));
        }
 else {
          outerAST.addChild(childAST);
        }
      }
      return outerAST;
    }
 else {
      ASTNode innerSelectASTWithoutAlias=MetastoreUtil.copyAST(astNode);
      ASTNode innerSelectExprAST=new ASTNode(new CommonToken(HiveParser.TOK_SELEXPR,"String_Node_Str"));
      innerSelectExprAST.addChild(innerSelectASTWithoutAlias);
      String alias=aliasDecider.decideAlias(astNode);
      ASTNode aliasNode=new ASTNode(new CommonToken(Identifier,alias));
      innerSelectExprAST.addChild(aliasNode);
      innerSelectAST.addChild(innerSelectExprAST);
      if (astNode.getText().equals(DEFAULT_MEASURE)) {
        ASTNode outerAST=new ASTNode(new CommonToken(HiveParser.TOK_SELEXPR,"String_Node_Str"));
        outerAST.addChild(astNode);
        return outerAST;
      }
 else {
        ASTNode outerAST=getDotAST(cubeql.getCube().getName(),alias);
        (isSelectAst ? innerToOuterSelectASTs : innerToOuterHavingASTs).put(new HashableASTNode(innerSelectASTWithoutAlias),outerAST);
        return outerAST;
      }
    }
  }
}

Fixed version (ground truth):
private ASTNode getOuterAST(ASTNode astNode,ASTNode innerSelectAST,AliasDecider aliasDecider,StorageCandidate sc,boolean isSelectAst,Set<String> dimensionSet) throws LensException {
  if (astNode == null) {
    return null;
  }
  Set<String> msrCols=new HashSet<>();
  getAllColumnsOfNode(astNode,msrCols);
  msrCols.removeAll(dimensionSet);
  if (isAggregateAST(astNode) && sc.getColumns().containsAll(msrCols)) {
    return processAggregate(astNode,innerSelectAST,aliasDecider,isSelectAst);
  }
 else   if (isAggregateAST(astNode) && !sc.getColumns().containsAll(msrCols)) {
    ASTNode outerAST=new ASTNode(new CommonToken(HiveParser.TOK_SELEXPR,"String_Node_Str"));
    ASTNode exprCopy=MetastoreUtil.copyAST(astNode);
    setDefaultValueInExprForAggregateNodes(exprCopy,sc);
    outerAST.addChild(getOuterAST(getSelectExpr(exprCopy,null,true),innerSelectAST,aliasDecider,sc,isSelectAst,dimensionSet));
    return outerAST;
  }
 else {
    if (hasAggregate(astNode)) {
      ASTNode outerAST=new ASTNode(astNode);
      for (      Node child : astNode.getChildren()) {
        ASTNode childAST=(ASTNode)child;
        if (hasAggregate(childAST) && sc.getColumns().containsAll(msrCols)) {
          outerAST.addChild(getOuterAST(childAST,innerSelectAST,aliasDecider,sc,isSelectAst,dimensionSet));
        }
 else         if (hasAggregate(childAST) && !sc.getColumns().containsAll(msrCols)) {
          childAST.replaceChildren(1,1,getSelectExpr(null,null,true));
          outerAST.addChild(getOuterAST(childAST,innerSelectAST,aliasDecider,sc,isSelectAst,dimensionSet));
        }
 else {
          outerAST.addChild(childAST);
        }
      }
      return outerAST;
    }
 else {
      ASTNode innerSelectASTWithoutAlias=MetastoreUtil.copyAST(astNode);
      ASTNode innerSelectExprAST=new ASTNode(new CommonToken(HiveParser.TOK_SELEXPR,"String_Node_Str"));
      innerSelectExprAST.addChild(innerSelectASTWithoutAlias);
      String alias=aliasDecider.decideAlias(astNode);
      ASTNode aliasNode=new ASTNode(new CommonToken(Identifier,alias));
      innerSelectExprAST.addChild(aliasNode);
      innerSelectAST.addChild(innerSelectExprAST);
      if (astNode.getText().equals(DEFAULT_MEASURE)) {
        ASTNode outerAST=new ASTNode(new CommonToken(HiveParser.TOK_SELEXPR,"String_Node_Str"));
        outerAST.addChild(astNode);
        return outerAST;
      }
 else {
        ASTNode outerAST=getDotAST(cubeql.getCube().getName(),alias);
        HashableASTNode innerAST=new HashableASTNode(innerSelectASTWithoutAlias);
        if (isSelectAst && !innerToOuterSelectASTs.containsKey(innerAST)) {
          innerToOuterSelectASTs.put(innerAST,outerAST);
        }
 else         if (!isSelectAst && !innerToOuterHavingASTs.containsKey(innerAST)) {
          innerToOuterHavingASTs.put(innerAST,outerAST);
        }
        return outerAST;
      }
    }
  }
}