Program: 65473
Project: 65473
Buggy source:
private IAggregationResultSet[] applyNoAggrUpdateFilters(List finalFilters,CubeQueryExecutor executor,IAggregationResultSet[] rs,ICube cube,IBindingValueFetcher fetcher,boolean fromCubeOperation) throws DataException, IOException {
  if (!finalFilters.isEmpty()) {
    List aggrEvalList=new ArrayList<AggrMeasureFilterEvalHelper>();
    List dimEvalList=new ArrayList<IJSFilterHelper>();
    List<IFilterDefinition> drillFilterList=new ArrayList<IFilterDefinition>();
    for (int i=0; i < finalFilters.size(); i++) {
      IFilterDefinition filter=(IFilterDefinition)finalFilters.get(i);
      boolean find=false;
      String bindingName=OlapExpressionCompiler.getReferencedScriptObject(filter.getExpression(),ScriptConstants.DATA_BINDING_SCRIPTABLE);
      if (executor.getCubeQueryDefinition().getCubeOperations().length > 0) {
        ICubeOperation[] operations=executor.getCubeQueryDefinition().getCubeOperations();
        for (int j=0; j < operations.length; j++) {
          if (operations[j] instanceof AddingNestAggregations) {
            AddingNestAggregations aggr=(AddingNestAggregations)operations[i];
            IBinding[] bindings=aggr.getNewBindings();
            for (int k=0; k < bindings.length; k++) {
              if (bindings[k].getBindingName().equals(bindingName)) {
                find=true;
                break;
              }
            }
          }
        }
      }
      if (find != fromCubeOperation)       continue;
      int type=executor.getFilterType(filter,executor.getDimLevelsDefinedInCubeQuery());
      if (type == executor.DIMENSION_FILTER) {
        dimEvalList.add(BaseDimensionFilterEvalHelper.createFilterHelper(executor.getOuterResults(),executor.getScope(),executor.getCubeQueryDefinition(),filter,executor.getSession().getEngineContext().getScriptContext()));
      }
 else       if (type == executor.AGGR_MEASURE_FILTER) {
        aggrEvalList.add(new AggrMeasureFilterEvalHelper(executor.getOuterResults(),executor.getScope(),executor.getCubeQueryDefinition(),filter,executor.getSession().getEngineContext().getScriptContext()));
      }
 else       if (type == executor.FACTTABLE_FILTER) {
        drillFilterList.add(filter);
      }
    }
    List<Integer> affectedAggrResultSetIndex=new ArrayList<Integer>();
    if (aggrEvalList.size() > 0) {
      AggrMeasureFilterHelper aggrFilterHelper=new AggrMeasureFilterHelper(cube,rs);
      aggrFilterHelper.setQueryExecutor(executor);
      aggrFilterHelper.setBindingValueFetcher(fetcher);
      rs=aggrFilterHelper.removeInvalidAggrRows(aggrEvalList,affectedAggrResultSetIndex);
    }
    if (dimEvalList.size() > 0) {
      AggregationFilterHelper helper=new AggregationFilterHelper((Cube)cube,dimEvalList,fetcher);
      rs=helper.generateFilteredAggregationResultSet(rs,affectedAggrResultSetIndex);
    }
    Map<DimLevel,IJSFacttableFilterEvalHelper> edgeDrillFilterMap=populateEdgeDrillFilterMap(executor,drillFilterList);
    List<IAggregationResultSet> edgeResultSet=populateAndFilterEdgeResultSet(rs,edgeDrillFilterMap);
    for (int i=0; i < edgeResultSet.size(); i++) {
      for (int j=0; j < affectedAggrResultSetIndex.size(); j++) {
        this.applyJoin(edgeResultSet.get(i),rs[affectedAggrResultSetIndex.get(j).intValue()]);
      }
    }
    if (edgeResultSet.size() > 1) {
      combineEdgeResultSetsInfo(edgeResultSet);
    }
  }
  return rs;
}

Fixed version (ground truth):
private IAggregationResultSet[] applyNoAggrUpdateFilters(List finalFilters,CubeQueryExecutor executor,IAggregationResultSet[] rs,ICube cube,IBindingValueFetcher fetcher,boolean fromCubeOperation) throws DataException, IOException {
  if (!finalFilters.isEmpty()) {
    List aggrEvalList=new ArrayList<AggrMeasureFilterEvalHelper>();
    List dimEvalList=new ArrayList<IJSFilterHelper>();
    List<IFilterDefinition> drillFilterList=new ArrayList<IFilterDefinition>();
    for (int i=0; i < finalFilters.size(); i++) {
      IFilterDefinition filter=(IFilterDefinition)finalFilters.get(i);
      boolean find=false;
      String bindingName=OlapExpressionCompiler.getReferencedScriptObject(filter.getExpression(),ScriptConstants.DATA_BINDING_SCRIPTABLE);
      if (executor.getCubeQueryDefinition().getCubeOperations().length > 0) {
        ICubeOperation[] operations=executor.getCubeQueryDefinition().getCubeOperations();
        for (int j=0; j < operations.length; j++) {
          if (operations[j] instanceof AddingNestAggregations) {
            AddingNestAggregations aggr=(AddingNestAggregations)operations[j];
            IBinding[] bindings=aggr.getNewBindings();
            for (int k=0; k < bindings.length; k++) {
              if (bindings[k].getBindingName().equals(bindingName)) {
                find=true;
                break;
              }
            }
          }
        }
      }
      if (find != fromCubeOperation)       continue;
      int type=executor.getFilterType(filter,executor.getDimLevelsDefinedInCubeQuery());
      if (type == executor.DIMENSION_FILTER) {
        dimEvalList.add(BaseDimensionFilterEvalHelper.createFilterHelper(executor.getOuterResults(),executor.getScope(),executor.getCubeQueryDefinition(),filter,executor.getSession().getEngineContext().getScriptContext()));
      }
 else       if (type == executor.AGGR_MEASURE_FILTER) {
        aggrEvalList.add(new AggrMeasureFilterEvalHelper(executor.getOuterResults(),executor.getScope(),executor.getCubeQueryDefinition(),filter,executor.getSession().getEngineContext().getScriptContext()));
      }
 else       if (type == executor.FACTTABLE_FILTER) {
        drillFilterList.add(filter);
      }
    }
    List<Integer> affectedAggrResultSetIndex=new ArrayList<Integer>();
    if (aggrEvalList.size() > 0) {
      AggrMeasureFilterHelper aggrFilterHelper=new AggrMeasureFilterHelper(cube,rs);
      aggrFilterHelper.setQueryExecutor(executor);
      aggrFilterHelper.setBindingValueFetcher(fetcher);
      rs=aggrFilterHelper.removeInvalidAggrRows(aggrEvalList,affectedAggrResultSetIndex);
    }
    if (dimEvalList.size() > 0) {
      AggregationFilterHelper helper=new AggregationFilterHelper((Cube)cube,dimEvalList,fetcher);
      rs=helper.generateFilteredAggregationResultSet(rs,affectedAggrResultSetIndex);
    }
    Map<DimLevel,IJSFacttableFilterEvalHelper> edgeDrillFilterMap=populateEdgeDrillFilterMap(executor,drillFilterList);
    List<IAggregationResultSet> edgeResultSet=populateAndFilterEdgeResultSet(rs,edgeDrillFilterMap);
    for (int i=0; i < edgeResultSet.size(); i++) {
      for (int j=0; j < affectedAggrResultSetIndex.size(); j++) {
        this.applyJoin(edgeResultSet.get(i),rs[affectedAggrResultSetIndex.get(j).intValue()]);
      }
    }
    if (edgeResultSet.size() > 1) {
      combineEdgeResultSetsInfo(edgeResultSet);
    }
  }
  return rs;
}