Program: 67278
Project: 67278
Buggy source:
private void testNestAggregation(IDocumentManager documentManager) throws IOException, BirtException, DataException {
  Dimension[] dimensions=new Dimension[3];
  String[] levelNames=new String[3];
  levelNames[0]="String_Node_Str";
  levelNames[1]="String_Node_Str";
  levelNames[2]="String_Node_Str";
  DimensionForTest iterator=new DimensionForTest(levelNames);
  iterator.setLevelMember(0,FactTable2.L1Col);
  iterator.setLevelMember(1,FactTable2.L2Col);
  iterator.setLevelMember(2,FactTable2.L3Col);
  ILevelDefn[] levelDefs=new ILevelDefn[3];
  levelDefs[0]=new LevelDefinition("String_Node_Str",new String[]{"String_Node_Str"},null);
  levelDefs[1]=new LevelDefinition("String_Node_Str",new String[]{"String_Node_Str"},null);
  levelDefs[2]=new LevelDefinition("String_Node_Str",new String[]{"String_Node_Str"},null);
  dimensions[0]=(Dimension)DimensionFactory.createDimension("String_Node_Str",documentManager,iterator,levelDefs,false,new StopSign());
  IHierarchy hierarchy=dimensions[0].getHierarchy();
  assertEquals(hierarchy.getName(),"String_Node_Str");
  assertEquals(dimensions[0].length(),FactTable2.L3Col.length);
  levelNames=new String[1];
  levelNames[0]="String_Node_Str";
  iterator=new DimensionForTest(levelNames);
  iterator.setLevelMember(0,distinct(FactTable2.L1Col));
  levelDefs=new ILevelDefn[1];
  levelDefs[0]=new LevelDefinition("String_Node_Str",new String[]{"String_Node_Str"},null);
  dimensions[1]=(Dimension)DimensionFactory.createDimension("String_Node_Str",documentManager,iterator,levelDefs,false,new StopSign());
  hierarchy=dimensions[1].getHierarchy();
  assertEquals(hierarchy.getName(),"String_Node_Str");
  assertEquals(dimensions[1].length(),3);
  levelNames=new String[1];
  levelNames[0]="String_Node_Str";
  iterator=new DimensionForTest(levelNames);
  iterator.setLevelMember(0,FactTable2.L3Col);
  levelDefs=new ILevelDefn[1];
  levelDefs[0]=new LevelDefinition("String_Node_Str",new String[]{"String_Node_Str"},null);
  dimensions[2]=(Dimension)DimensionFactory.createDimension("String_Node_Str",documentManager,iterator,levelDefs,false,new StopSign());
  hierarchy=dimensions[2].getHierarchy();
  assertEquals(hierarchy.getName(),"String_Node_Str");
  assertEquals(dimensions[2].length(),12);
  FactTable2 factTable2=new FactTable2();
  String[] measureColumnName=new String[2];
  measureColumnName[0]="String_Node_Str";
  measureColumnName[1]="String_Node_Str";
  FactTableAccessor factTableConstructor=new FactTableAccessor(documentManager);
  FactTable factTable=factTableConstructor.saveFactTable(NamingUtil.getFactTableName("String_Node_Str"),CubeUtility.getKeyColNames(dimensions),CubeUtility.getKeyColNames(dimensions),factTable2,dimensions,measureColumnName,new StopSign());
  factTable=factTableConstructor.load(NamingUtil.getFactTableName("String_Node_Str"),new StopSign());
  String[] dimensionNames=new String[3];
  dimensionNames[0]="String_Node_Str";
  dimensionNames[1]="String_Node_Str";
  dimensionNames[2]="String_Node_Str";
  DimensionResultIterator[] dimesionResultSets=new DimensionResultIterator[1];
  IDiskArray positionArray=dimensions[0].findAll();
  dimesionResultSets[0]=new DimensionResultIterator(dimensions[0],positionArray,new StopSign());
  String[] dimensionNamesForFilter=new String[1];
  dimensionNamesForFilter[0]="String_Node_Str";
  IDiskArray[] positionsForFilter=new IDiskArray[1];
  positionsForFilter[0]=positionArray;
  FactTableRowIterator facttableRowIterator=new FactTableRowIterator(factTable,dimensionNamesForFilter,positionsForFilter,new StopSign());
  assertTrue(facttableRowIterator != null);
  AggregationDefinition[] aggregations=new AggregationDefinition[1];
  int[] sortType=new int[2];
  sortType[0]=IDimensionSortDefn.SORT_ASC;
  sortType[1]=IDimensionSortDefn.SORT_ASC;
  DimLevel[] levelsForFilter=new DimLevel[]{dimLevel11,dimLevel12};
  AggregationFunctionDefinition[] funcitons=new AggregationFunctionDefinition[1];
  funcitons[0]=new AggregationFunctionDefinition("String_Node_Str","String_Node_Str",IBuildInAggregation.TOTAL_SUM_FUNC);
  aggregations[0]=new AggregationDefinition(levelsForFilter,sortType,funcitons);
  IDataSet4Aggregation dataSet4Aggregation=new DataSetFromOriginalCube(facttableRowIterator,dimesionResultSets,null);
  AggregationExecutor aggregationCalculatorExecutor=new AggregationExecutor(null,dataSet4Aggregation,aggregations);
  IAggregationResultSet[] resultSet=aggregationCalculatorExecutor.execute(new StopSign());
  assertEquals(resultSet[0].length(),6);
  assertEquals(resultSet[0].getAggregationDataType(0),DataType.DOUBLE_TYPE);
  assertEquals(resultSet[0].getLevelIndex(dimLevel11),0);
  assertEquals(resultSet[0].getLevelIndex(dimLevel12),1);
  resultSet[0].seek(0);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(1));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(1));
  resultSet[0].seek(1);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(1));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(5));
  resultSet[0].seek(2);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(2));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(9));
  resultSet[0].seek(3);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(2));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(13));
  resultSet[0].seek(4);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(3));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(17));
  resultSet[0].seek(5);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(3));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(21));
  IAggregationResultSet sourceAggrResultSet=resultSet[0];
  aggregations=new AggregationDefinition[1];
  funcitons=new AggregationFunctionDefinition[1];
  funcitons[0]=new AggregationFunctionDefinition("String_Node_Str","String_Node_Str",IBuildInAggregation.TOTAL_MAX_FUNC);
  aggregations[0]=new AggregationDefinition(null,null,funcitons);
  Context context=Context.enter();
  ScriptableObject scope=context.initStandardObjects();
  ScriptContext cx=new ScriptContext();
  IAggregationResultSet ars=new AggregationResultSetWithOneMoreDummyAggr(sourceAggrResultSet,"String_Node_Str",new ScriptExpression("String_Node_Str"),scope,cx);
  resultSet=AggregationHelper.execute(ars,aggregations,new StopSign());
  assertEquals(resultSet[0].length(),1);
  resultSet[0].seek(0);
  assertEquals(resultSet[0].getAggregationValue(0),new Double(21));
  aggregations=new AggregationDefinition[1];
  sortType=new int[1];
  sortType[0]=IDimensionSortDefn.SORT_ASC;
  levelsForFilter=new DimLevel[]{dimLevel11};
  funcitons=new AggregationFunctionDefinition[1];
  funcitons[0]=new AggregationFunctionDefinition("String_Node_Str","String_Node_Str",IBuildInAggregation.TOTAL_SUM_FUNC);
  aggregations[0]=new AggregationDefinition(levelsForFilter,sortType,funcitons);
  ars=new AggregationResultSetWithOneMoreDummyAggr(sourceAggrResultSet,"String_Node_Str",new ScriptExpression("String_Node_Str"),scope,cx);
  resultSet=AggregationHelper.execute(ars,aggregations,new StopSign());
  assertEquals(resultSet[0].length(),3);
  assertEquals(resultSet[0].getAggregationDataType(0),DataType.DOUBLE_TYPE);
  assertEquals(resultSet[0].getLevelIndex(dimLevel11),0);
  resultSet[0].seek(0);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(1));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(6));
  resultSet[0].seek(1);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(2));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(22));
  resultSet[0].seek(2);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(3));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(38));
  closeResultSets(resultSet);
  Context.exit();
  cx.close();
}

Fixed version (ground truth):
private void testNestAggregation(IDocumentManager documentManager) throws IOException, BirtException, DataException {
  Dimension[] dimensions=new Dimension[3];
  String[] levelNames=new String[3];
  levelNames[0]="String_Node_Str";
  levelNames[1]="String_Node_Str";
  levelNames[2]="String_Node_Str";
  DimensionForTest iterator=new DimensionForTest(levelNames);
  iterator.setLevelMember(0,FactTable2.L1Col);
  iterator.setLevelMember(1,FactTable2.L2Col);
  iterator.setLevelMember(2,FactTable2.L3Col);
  ILevelDefn[] levelDefs=new ILevelDefn[3];
  levelDefs[0]=new LevelDefinition("String_Node_Str",new String[]{"String_Node_Str"},null);
  levelDefs[1]=new LevelDefinition("String_Node_Str",new String[]{"String_Node_Str"},null);
  levelDefs[2]=new LevelDefinition("String_Node_Str",new String[]{"String_Node_Str"},null);
  dimensions[0]=(Dimension)DimensionFactory.createDimension("String_Node_Str",documentManager,iterator,levelDefs,false,new StopSign());
  IHierarchy hierarchy=dimensions[0].getHierarchy();
  assertEquals(hierarchy.getName(),"String_Node_Str");
  assertEquals(dimensions[0].length(),FactTable2.L3Col.length);
  levelNames=new String[1];
  levelNames[0]="String_Node_Str";
  iterator=new DimensionForTest(levelNames);
  iterator.setLevelMember(0,distinct(FactTable2.L1Col));
  levelDefs=new ILevelDefn[1];
  levelDefs[0]=new LevelDefinition("String_Node_Str",new String[]{"String_Node_Str"},null);
  dimensions[1]=(Dimension)DimensionFactory.createDimension("String_Node_Str",documentManager,iterator,levelDefs,false,new StopSign());
  hierarchy=dimensions[1].getHierarchy();
  assertEquals(hierarchy.getName(),"String_Node_Str");
  assertEquals(dimensions[1].length(),3);
  levelNames=new String[1];
  levelNames[0]="String_Node_Str";
  iterator=new DimensionForTest(levelNames);
  iterator.setLevelMember(0,FactTable2.L3Col);
  levelDefs=new ILevelDefn[1];
  levelDefs[0]=new LevelDefinition("String_Node_Str",new String[]{"String_Node_Str"},null);
  dimensions[2]=(Dimension)DimensionFactory.createDimension("String_Node_Str",documentManager,iterator,levelDefs,false,new StopSign());
  hierarchy=dimensions[2].getHierarchy();
  assertEquals(hierarchy.getName(),"String_Node_Str");
  assertEquals(dimensions[2].length(),12);
  FactTable2 factTable2=new FactTable2();
  String[] measureColumnName=new String[2];
  measureColumnName[0]="String_Node_Str";
  measureColumnName[1]="String_Node_Str";
  FactTableAccessor factTableConstructor=new FactTableAccessor(documentManager);
  FactTable factTable=factTableConstructor.saveFactTable(NamingUtil.getFactTableName("String_Node_Str"),CubeUtility.getKeyColNames(dimensions),CubeUtility.getKeyColNames(dimensions),factTable2,dimensions,measureColumnName,new StopSign(),false);
  factTable=factTableConstructor.load(NamingUtil.getFactTableName("String_Node_Str"),new StopSign());
  String[] dimensionNames=new String[3];
  dimensionNames[0]="String_Node_Str";
  dimensionNames[1]="String_Node_Str";
  dimensionNames[2]="String_Node_Str";
  DimensionResultIterator[] dimesionResultSets=new DimensionResultIterator[1];
  IDiskArray positionArray=dimensions[0].findAll();
  dimesionResultSets[0]=new DimensionResultIterator(dimensions[0],positionArray,new StopSign());
  String[] dimensionNamesForFilter=new String[1];
  dimensionNamesForFilter[0]="String_Node_Str";
  IDiskArray[] positionsForFilter=new IDiskArray[1];
  positionsForFilter[0]=positionArray;
  FactTableRowIterator facttableRowIterator=new FactTableRowIterator(factTable,dimensionNamesForFilter,positionsForFilter,new StopSign());
  assertTrue(facttableRowIterator != null);
  AggregationDefinition[] aggregations=new AggregationDefinition[1];
  int[] sortType=new int[2];
  sortType[0]=IDimensionSortDefn.SORT_ASC;
  sortType[1]=IDimensionSortDefn.SORT_ASC;
  DimLevel[] levelsForFilter=new DimLevel[]{dimLevel11,dimLevel12};
  AggregationFunctionDefinition[] funcitons=new AggregationFunctionDefinition[1];
  funcitons[0]=new AggregationFunctionDefinition("String_Node_Str","String_Node_Str",IBuildInAggregation.TOTAL_SUM_FUNC);
  aggregations[0]=new AggregationDefinition(levelsForFilter,sortType,funcitons);
  IDataSet4Aggregation dataSet4Aggregation=new DataSetFromOriginalCube(facttableRowIterator,dimesionResultSets,null);
  AggregationExecutor aggregationCalculatorExecutor=new AggregationExecutor(null,dataSet4Aggregation,aggregations);
  IAggregationResultSet[] resultSet=aggregationCalculatorExecutor.execute(new StopSign());
  assertEquals(resultSet[0].length(),6);
  assertEquals(resultSet[0].getAggregationDataType(0),DataType.DOUBLE_TYPE);
  assertEquals(resultSet[0].getLevelIndex(dimLevel11),0);
  assertEquals(resultSet[0].getLevelIndex(dimLevel12),1);
  resultSet[0].seek(0);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(1));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(1));
  resultSet[0].seek(1);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(1));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(5));
  resultSet[0].seek(2);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(2));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(9));
  resultSet[0].seek(3);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(2));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(13));
  resultSet[0].seek(4);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(3));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(17));
  resultSet[0].seek(5);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(3));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(21));
  IAggregationResultSet sourceAggrResultSet=resultSet[0];
  aggregations=new AggregationDefinition[1];
  funcitons=new AggregationFunctionDefinition[1];
  funcitons[0]=new AggregationFunctionDefinition("String_Node_Str","String_Node_Str",IBuildInAggregation.TOTAL_MAX_FUNC);
  aggregations[0]=new AggregationDefinition(null,null,funcitons);
  Context context=Context.enter();
  ScriptableObject scope=context.initStandardObjects();
  ScriptContext cx=new ScriptContext();
  IAggregationResultSet ars=new AggregationResultSetWithOneMoreDummyAggr(sourceAggrResultSet,"String_Node_Str",new ScriptExpression("String_Node_Str"),scope,cx);
  resultSet=AggregationHelper.execute(ars,aggregations,new StopSign());
  assertEquals(resultSet[0].length(),1);
  resultSet[0].seek(0);
  assertEquals(resultSet[0].getAggregationValue(0),new Double(21));
  aggregations=new AggregationDefinition[1];
  sortType=new int[1];
  sortType[0]=IDimensionSortDefn.SORT_ASC;
  levelsForFilter=new DimLevel[]{dimLevel11};
  funcitons=new AggregationFunctionDefinition[1];
  funcitons[0]=new AggregationFunctionDefinition("String_Node_Str","String_Node_Str",IBuildInAggregation.TOTAL_SUM_FUNC);
  aggregations[0]=new AggregationDefinition(levelsForFilter,sortType,funcitons);
  ars=new AggregationResultSetWithOneMoreDummyAggr(sourceAggrResultSet,"String_Node_Str",new ScriptExpression("String_Node_Str"),scope,cx);
  resultSet=AggregationHelper.execute(ars,aggregations,new StopSign());
  assertEquals(resultSet[0].length(),3);
  assertEquals(resultSet[0].getAggregationDataType(0),DataType.DOUBLE_TYPE);
  assertEquals(resultSet[0].getLevelIndex(dimLevel11),0);
  resultSet[0].seek(0);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(1));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(6));
  resultSet[0].seek(1);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(2));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(22));
  resultSet[0].seek(2);
  assertEquals(resultSet[0].getLevelKeyValue(0)[0],new Integer(3));
  assertEquals(resultSet[0].getAggregationValue(0),new Double(38));
  closeResultSets(resultSet);
  Context.exit();
  cx.close();
}