private DbIterator buildAggregator(DbIterator child, int afield, int gfield,Op op) 
    {
    	DbIterator aitr = new TupleArrayIterator(new ArrayList<Tuple>());
    	Type groupType;
    	if (gfield == Aggregator.NO_GROUPING)
    	{
    		groupType = Type.INT_TYPE;
    	}
    	else
    	{
    		groupType = child.getTupleDesc().getType(gfield);
    	}
    	try 
    	{
			child.open();
    		if(groupType == Type.INT_TYPE)
			{
				IntAggregator intAgg = new IntAggregator(gfield, Type.INT_TYPE, afield, op);
				
					for(;child.hasNext();)
					{
						Tuple tup = child.next();
						intAgg.merge(tup);
					}
				aitr = intAgg.iterator();	
			} 
			
			else if(groupType == Type.STRING_TYPE)
			{
				StringAggregator stringAgg = new StringAggregator(gfield, Type.STRING_TYPE, afield, op);
				
				for(;child.hasNext();)
				{
					Tuple tup = child.next();
					stringAgg.merge(tup);
				}
			aitr = stringAgg.iterator();	
			}
		}
		
		catch (NoSuchElementException e) 
		{
			System.out.println(e);
		} 
		catch (DbException e) 
		{
			System.out.println(e);
		} 
		catch (TransactionAbortedException e) 
		{
			System.out.println(e);
		}
    	finally
    	{
    		child.close();
    	}
		return aitr;
		
	}