Program: 95905
Project: 95905
Buggy source:
/** 
 * Adds tier expressions to the end of the select list; and to the group-by list.
 * @param query
 * @param newSelectList
 * @param scrambleMetaSet
 */
private Map<ScrambleMeta,String> addTierColumnToSelectListAndGroupBy(SelectQuery query,List<SelectItem> newSelectList,ScrambleMetaSet scrambleMetaSet,List<ProjectionNode> projectionNodeSources){
  Map<ScrambleMeta,String> scrambleMetaAnditsAlias=new HashMap<>();
  for (  AbstractRelation table : query.getFromList()) {
    if (table instanceof BaseTable) {
      String schemaName=((BaseTable)table).getSchemaName();
      String tableName=((BaseTable)table).getTableName();
      if (scrambleMetaSet.isScrambled(schemaName,tableName)) {
        ScrambleMeta singleMeta=scrambleMetaSet.getSingleMeta(schemaName,tableName);
        String tierColumnName=scrambleMetaSet.getTierColumn(schemaName,tableName);
        String newTierColumnAlias=generateTierColumnAliasName();
        BaseColumn tierColumn=new BaseColumn(schemaName,tableName,table.getAliasName().get(),tierColumnName);
        newSelectList.add(new AliasedColumn(tierColumn,newTierColumnAlias));
        query.addGroupby(tierColumn);
        scrambleMetaAnditsAlias.put(singleMeta,newTierColumnAlias);
      }
    }
 else     if (table instanceof JoinTable) {
      for (      AbstractRelation jointable : ((JoinTable)table).getJoinList()) {
        if (jointable instanceof BaseTable) {
          String schemaName=((BaseTable)jointable).getSchemaName();
          String tableName=((BaseTable)jointable).getTableName();
          if (scrambleMetaSet.isScrambled(schemaName,tableName)) {
            ScrambleMeta singleMeta=scrambleMetaSet.getSingleMeta(schemaName,tableName);
            String tierColumnName=scrambleMetaSet.getTierColumn(schemaName,tableName);
            String newTierColumnAlias=generateTierColumnAliasName();
            BaseColumn tierColumn=new BaseColumn(schemaName,tableName,jointable.getAliasName().get(),tierColumnName);
            newSelectList.add(new AliasedColumn(tierColumn,newTierColumnAlias));
            query.addGroupby(tierColumn);
            scrambleMetaAnditsAlias.put(singleMeta,newTierColumnAlias);
          }
        }
      }
    }
  }
  for (  ProjectionNode source : projectionNodeSources) {
    for (    Map.Entry<ScrambleMeta,String> entry : source.getAggMeta().getTierColumnForScramble().entrySet()) {
      ScrambleMeta singleMeta=entry.getKey();
      String oldtierAlias=entry.getValue();
      SelectItem selectItem;
      String newTierColumnAlias=generateTierColumnAliasName();
      if (source.getSelectQuery().getAliasName().isPresent()) {
        String sourceAlias=source.getSelectQuery().getAliasName().get();
        selectItem=new AliasedColumn(new BaseColumn(sourceAlias,oldtierAlias),newTierColumnAlias);
      }
 else {
        selectItem=new AliasedColumn(new BaseColumn(oldtierAlias),newTierColumnAlias);
      }
      newSelectList.add(selectItem);
      query.addGroupby(new AliasReference(newTierColumnAlias));
      scrambleMetaAnditsAlias.put(singleMeta,newTierColumnAlias);
    }
  }
  return scrambleMetaAnditsAlias;
}

Fixed version (ground truth):
/** 
 * Adds tier expressions to the end of the select list; and to the group-by list.
 * @param query
 * @param newSelectList
 * @param scrambleMetaSet
 */
private Map<ScrambleMeta,String> addTierColumnToSelectListAndGroupBy(SelectQuery query,List<SelectItem> newSelectList,ScrambleMetaSet scrambleMetaSet,List<ProjectionNode> projectionNodeSources){
  Map<ScrambleMeta,String> scrambleMetaAnditsAlias=new HashMap<>();
  for (  AbstractRelation table : query.getFromList()) {
    if (table instanceof BaseTable) {
      String schemaName=((BaseTable)table).getSchemaName();
      String tableName=((BaseTable)table).getTableName();
      if (scrambleMetaSet.isScrambled(schemaName,tableName)) {
        ScrambleMeta singleMeta=scrambleMetaSet.getSingleMeta(schemaName,tableName);
        String tierColumnName=scrambleMetaSet.getTierColumn(schemaName,tableName);
        String newTierColumnAlias=generateTierColumnAliasName();
        BaseColumn tierColumn=new BaseColumn(schemaName,tableName,table.getAliasName().get(),tierColumnName);
        newSelectList.add(new AliasedColumn(tierColumn,newTierColumnAlias));
        query.addGroupby(tierColumn);
        scrambleMetaAnditsAlias.put(singleMeta,newTierColumnAlias);
      }
    }
 else     if (table instanceof JoinTable) {
      for (      AbstractRelation jointable : ((JoinTable)table).getJoinList()) {
        if (jointable instanceof BaseTable) {
          String schemaName=((BaseTable)jointable).getSchemaName();
          String tableName=((BaseTable)jointable).getTableName();
          if (scrambleMetaSet.isScrambled(schemaName,tableName)) {
            ScrambleMeta singleMeta=scrambleMetaSet.getSingleMeta(schemaName,tableName);
            String tierColumnName=scrambleMetaSet.getTierColumn(schemaName,tableName);
            String newTierColumnAlias=generateTierColumnAliasName();
            BaseColumn tierColumn=new BaseColumn(schemaName,tableName,jointable.getAliasName().get(),tierColumnName);
            newSelectList.add(new AliasedColumn(tierColumn,newTierColumnAlias));
            query.addGroupby(tierColumn);
            scrambleMetaAnditsAlias.put(singleMeta,newTierColumnAlias);
          }
        }
      }
    }
  }
  for (  ProjectionNode source : projectionNodeSources) {
    for (    Map.Entry<ScrambleMeta,String> entry : source.getAggMeta().getTierColumnForScramble().entrySet()) {
      ScrambleMeta singleMeta=entry.getKey();
      String oldtierAlias=entry.getValue();
      SelectItem selectItem;
      String newTierColumnAlias=generateTierColumnAliasName();
      UnnamedColumn column;
      if (source.getSelectQuery().getAliasName().isPresent()) {
        String sourceAlias=source.getSelectQuery().getAliasName().get();
        column=new BaseColumn(sourceAlias,oldtierAlias);
        selectItem=new AliasedColumn(column,newTierColumnAlias);
      }
 else {
        column=new BaseColumn(oldtierAlias);
        selectItem=new AliasedColumn(column,newTierColumnAlias);
      }
      newSelectList.add(selectItem);
      query.addGroupby(column);
      scrambleMetaAnditsAlias.put(singleMeta,newTierColumnAlias);
    }
  }
  return scrambleMetaAnditsAlias;
}