key.setSchema(this.getKeySchemaByDatasetID(datasetID));
}
Iterator<Tuple> tuples = values.next ();
Tuple combinedValue = new Tuple();
long progress = 0L;
while( tuples.hasNext() )
{
Tuple aTuple = tuples.next();
if( ++progress % 3000 ==0 )
{
reporter.progress();
}
aTuple.setSchema(this.getValueSchemaByDatasetID(datasetID));
for( Projectable p:this.dsToFuncsMapping.get(datasetID) )
{
if( p instanceof GroupFunction )
{
((GroupFunction) p).consume(aTuple);
}
else
{
ExtendFunction func = (ExtendFunction)p;
Tuple computedResult = func.getResult(aTuple);
String name = func.getInputColumns()[0].getInputColumnName();
combinedValue.insert(name, computedResult.get(0));
}
}
}
for( Projectable p:this.dsToFuncsMapping.get(datasetID) )
{
if( p instanceof GroupFunction )
{
BigTupleList aggregatedResult = ((GroupFunction)p).getResult();
if( aggregatedResult.size() ==1 )
{
Tuple aggResult = aggregatedResult.getFirst();
String name = p.getInputColumns()[0].getInputColumnName();
combinedValue.insert(name, aggResult.get(0));
}
else if( aggregatedResult.size()>1 )
throw new IllegalArgumentException(p.toString()+" is a group function that generates " +
"more than one rows ("+aggregatedResult.size()+") per key, so it is not combinable.");
}