Program: 65484
Project: 65484
Buggy source:
private IAggregationResultSet[] processOperationOnQuery(CubeQueryExecutor executor,BirtCubeView view,StopSign stopSign,IAggregationResultSet[] resultSet,AggregationDefinition[] aggrDefns,IBindingValueFetcher fetcher) throws DataException, IOException, BirtException {
  IAggregationResultSet[] rs=new IAggregationResultSet[aggrDefns.length];
  System.arraycopy(resultSet,0,rs,0,aggrDefns.length);
  IAggregationResultSet[] drillRs=new IAggregationResultSet[resultSet.length - aggrDefns.length];
  System.arraycopy(resultSet,aggrDefns.length,drillRs,0,drillRs.length);
  CubeOperationsExecutor coe=new CubeOperationsExecutor(view.getCubeQueryDefinition(),view.getPreparedCubeOperations(),view.getCubeQueryExecutor().getScope(),view.getCubeQueryExecutor().getSession().getEngineContext().getScriptContext());
  int rsLenBefore=rs.length;
  rs=coe.execute(rs,stopSign);
  int rsLenAfter=rs.length;
  List noAggrUpdateFilters=getNoAggrUpdateFilters(executor.getCubeQueryDefinition().getFilters());
  if (noAggrUpdateFilters.size() > 0) {
    IAggregationResultSet[] result=null;
    if (rsLenBefore < rsLenAfter) {
      result=new IAggregationResultSet[rsLenAfter - rsLenBefore];
      for (int i=0; i < result.length; i++) {
        result[i]=rs[rsLenBefore + i];
      }
      result=applyNoAggrUpdateFilters(noAggrUpdateFilters,executor,result,view.getCube(),fetcher,true);
      for (int i=0; i < result.length; i++) {
        rs[i + rsLenBefore]=result[i];
      }
    }
 else     if (rsLenBefore == rsLenAfter) {
      List<IAggregationResultSet> mergedResult=new ArrayList<IAggregationResultSet>();
      for (int i=0; i < rs.length; i++) {
        if (rs[i].getAggregationDefinition().getAggregationFunctions() != null && rs[i] instanceof MergedAggregationResultSet) {
          IAggregationResultSet[] applyResults=applyNoAggrUpdateFilters(noAggrUpdateFilters,executor,new IAggregationResultSet[]{rs[i]},view.getCube(),fetcher,true);
          rs[i]=applyResults[0];
          mergedResult.add(rs[i]);
        }
      }
      result=mergedResult.toArray(new IAggregationResultSet[0]);
    }
    List<IAggregationResultSet> edgeResultSet=populateAndFilterEdgeResultSet(rs,null);
    for (int i=0; i < edgeResultSet.size(); i++) {
      for (int j=0; j < result.length; j++) {
        this.applyJoin(edgeResultSet.get(i),result[j]);
      }
    }
  }
  if (drillRs.length > 0) {
    IPreparedCubeOperation[] ops=view.getPreparedCubeOperations();
    List<PreparedAddingNestAggregations> operations=new ArrayList<PreparedAddingNestAggregations>();
    List<CubeNestAggrDefn> nestedAggr=new ArrayList<CubeNestAggrDefn>();
    List<AggregationDefinition> aggregations=new ArrayList<AggregationDefinition>();
    for (int i=0; i < ops.length; i++) {
      List<AggregationDefinition> nested_aggregation=ops[i].getAggregationDefintions();
      for (int k=0; k < nested_aggregation.size(); k++) {
        AggregationDefinition[] drilled_nested_aggregation=DrillFilterHelper.preparedDrillForNestedAggregation(executor.getCubeQueryDefinition(),new CubeAggrDefn[]{ops[i].getNewCubeAggrDefns()[k]},new AggregationDefinition[]{nested_aggregation.get(k)});
        for (        AggregationDefinition aggregation : drilled_nested_aggregation) {
          CubeNestAggrDefn defn=(CubeNestAggrDefn)(ops[i].getNewCubeAggrDefns()[k]);
          nestedAggr.add(new CubeNestAggrDefn(defn.getName(),defn.getBasedExpression(),Arrays.asList(ops[i].getNewCubeAggrDefns()[k]),defn.getAggrName(),defn.getArguments(),defn.getFilter()));
          aggregations.add(aggregation);
        }
      }
      if (!nestedAggr.isEmpty()) {
        PreparedAddingNestAggregations drill_coe=new PreparedAddingNestAggregations();
        drill_coe.prepare(executor.getScope(),view.getCubeQueryExecutor().getSession().getEngineContext().getScriptContext(),view.getAggregationRegisterTable(),nestedAggr.toArray(new CubeNestAggrDefn[0]),aggregations);
        operations.add(drill_coe);
      }
    }
    if (!operations.isEmpty()) {
      coe=new CubeOperationsExecutor(view.getCubeQueryDefinition(),operations.toArray(new PreparedAddingNestAggregations[0]),view.getCubeQueryExecutor().getScope(),view.getCubeQueryExecutor().getSession().getEngineContext().getScriptContext());
      drillRs=coe.execute(drillRs,stopSign);
    }
    DrillOperationExecutor drillOp=new DrillOperationExecutor();
    rs=drillOp.execute(rs,drillRs,view.getCubeQueryDefinition());
  }
  return rs;
}

Fixed version (ground truth):
private IAggregationResultSet[] processOperationOnQuery(CubeQueryExecutor executor,BirtCubeView view,StopSign stopSign,IAggregationResultSet[] resultSet,AggregationDefinition[] aggrDefns,IBindingValueFetcher fetcher) throws DataException, IOException, BirtException {
  IAggregationResultSet[] rs=new IAggregationResultSet[aggrDefns.length];
  System.arraycopy(resultSet,0,rs,0,aggrDefns.length);
  IAggregationResultSet[] drillRs=new IAggregationResultSet[resultSet.length - aggrDefns.length];
  System.arraycopy(resultSet,aggrDefns.length,drillRs,0,drillRs.length);
  CubeOperationsExecutor coe=new CubeOperationsExecutor(view.getCubeQueryDefinition(),view.getPreparedCubeOperations(),view.getCubeQueryExecutor().getScope(),view.getCubeQueryExecutor().getSession().getEngineContext().getScriptContext());
  int rsLenBefore=rs.length;
  rs=coe.execute(rs,stopSign);
  int rsLenAfter=rs.length;
  List noAggrUpdateFilters=getNoAggrUpdateFilters(executor.getCubeQueryDefinition().getFilters());
  if (noAggrUpdateFilters.size() > 0) {
    IAggregationResultSet[] result=null;
    if (rsLenBefore < rsLenAfter) {
      result=new IAggregationResultSet[rsLenAfter - rsLenBefore];
      for (int i=0; i < result.length; i++) {
        result[i]=rs[rsLenBefore + i];
      }
      result=applyNoAggrUpdateFilters(noAggrUpdateFilters,executor,result,view.getCube(),fetcher,true);
      for (int i=0; i < result.length; i++) {
        rs[i + rsLenBefore]=result[i];
      }
    }
 else     if (rsLenBefore == rsLenAfter) {
      List<IAggregationResultSet> mergedResult=new ArrayList<IAggregationResultSet>();
      for (int i=0; i < rs.length; i++) {
        if (rs[i].getAggregationDefinition().getAggregationFunctions() != null && rs[i] instanceof MergedAggregationResultSet) {
          IAggregationResultSet[] applyResults=applyNoAggrUpdateFilters(noAggrUpdateFilters,executor,new IAggregationResultSet[]{rs[i]},view.getCube(),fetcher,true);
          rs[i]=applyResults[0];
          mergedResult.add(rs[i]);
        }
      }
      result=mergedResult.toArray(new IAggregationResultSet[0]);
    }
    List<IAggregationResultSet> edgeResultSet=populateAndFilterEdgeResultSet(rs,null);
    for (int i=0; i < edgeResultSet.size(); i++) {
      for (int j=0; j < result.length; j++) {
        this.applyJoin(edgeResultSet.get(i),result[j]);
      }
    }
  }
  if (DrillFilterHelper.containsDrillFilter(view.getCubeQueryDefinition())) {
    IPreparedCubeOperation[] ops=view.getPreparedCubeOperations();
    List<PreparedAddingNestAggregations> operations=new ArrayList<PreparedAddingNestAggregations>();
    List<CubeNestAggrDefn> nestedAggr=new ArrayList<CubeNestAggrDefn>();
    List<AggregationDefinition> aggregations=new ArrayList<AggregationDefinition>();
    for (int i=0; i < ops.length; i++) {
      List<AggregationDefinition> nested_aggregation=ops[i].getAggregationDefintions();
      for (int k=0; k < nested_aggregation.size(); k++) {
        AggregationDefinition[] drilled_nested_aggregation=DrillFilterHelper.preparedDrillForNestedAggregation(executor.getCubeQueryDefinition(),new CubeAggrDefn[]{ops[i].getNewCubeAggrDefns()[k]},new AggregationDefinition[]{nested_aggregation.get(k)});
        for (        AggregationDefinition aggregation : drilled_nested_aggregation) {
          CubeNestAggrDefn defn=(CubeNestAggrDefn)(ops[i].getNewCubeAggrDefns()[k]);
          nestedAggr.add(new CubeNestAggrDefn(defn.getName(),defn.getBasedExpression(),Arrays.asList(ops[i].getNewCubeAggrDefns()[k]),defn.getAggrName(),defn.getArguments(),defn.getFilter()));
          aggregations.add(aggregation);
        }
      }
      if (!nestedAggr.isEmpty()) {
        PreparedAddingNestAggregations drill_coe=new PreparedAddingNestAggregations();
        drill_coe.prepare(executor.getScope(),view.getCubeQueryExecutor().getSession().getEngineContext().getScriptContext(),view.getAggregationRegisterTable(),nestedAggr.toArray(new CubeNestAggrDefn[0]),aggregations);
        operations.add(drill_coe);
      }
    }
    if (!operations.isEmpty()) {
      coe=new CubeOperationsExecutor(view.getCubeQueryDefinition(),operations.toArray(new PreparedAddingNestAggregations[0]),view.getCubeQueryExecutor().getScope(),view.getCubeQueryExecutor().getSession().getEngineContext().getScriptContext());
      drillRs=coe.execute(drillRs,stopSign);
    }
    DrillOperationExecutor drillOp=new DrillOperationExecutor();
    rs=drillOp.execute(rs,drillRs,view.getCubeQueryDefinition());
  }
  return rs;
}