// times.
if( valuesFromLastDataset!=null )
{
while( valuesFromLastDataset.hasNext() )
{
Tuple aRow = valuesFromLastDataset.next();
this.rememberTuple(_lastDatasetID, aRow, reporter);
}
Iterable<Tuple> preCrossProduct = Util.crossProduct(conf, reporter, this.valuesForAllDatasets.values().toArray(new BigTupleList[0]));
BigTupleList btl = new BigTupleList(reporter);
for( Tuple aRow:preCrossProduct )
{
this.computeExtendFunctions(aRow, btl, this.multiDatasetExtendFunction);
this.computeGroupFunctions(aRow, this.multiDatasetGroupFunction);
}
if( btl.size()>0 )
toBeCrossProduct.add(btl);
for(GroupFunction fun:this.multiDatasetGroupFunction )
toBeCrossProduct.add(fun.getResult());
valuesFromLastDataset = this.valuesForAllDatasets.get(_lastDatasetID).iterator();
}
else
{
if( this.multiDatasetExtendFunction.size()>0 )
{
BigTupleList btl = new BigTupleList(reporter);
this.computeExtendFunctions(null, btl, this.multiDatasetExtendFunction);
toBeCrossProduct.add(btl);
}
for(GroupFunction fun:this.multiDatasetGroupFunction )
toBeCrossProduct.add(fun.getNoMatchResult(nullReplacement));
}
}
// finished the computation of multi-dataset functions, start
// to compute the projectable funcitons results for last
// dataset
//
// first compute the cross product of all other functions
Iterable<Tuple> others = null;
if( toBeCrossProduct.size()>0 )
{
Iterable<Tuple>[] array = new Iterable[toBeCrossProduct.size()];
for( int i=0;i<toBeCrossProduct.size();i++ )
{
array[i] = toBeCrossProduct.get(i);
}
others = Util.crossProduct(conf, reporter, array);
}
if( valuesFromLastDataset==null )
{// outer-join, so <code>others</code> is always not null.
List<BigTupleList> nullResult = new ArrayList<BigTupleList>();
if( this.singleDatasetExtendFunction.get(_lastDatasetID)!=null )
{
BigTupleList btl = new BigTupleList(reporter);
this.computeExtendFunctions(null, btl, this.singleDatasetExtendFunction.get(_lastDatasetID));
nullResult.add(btl);
}
if( this.singleDatasetGroupFunction.get(_lastDatasetID)!=null )
{
for(GroupFunction fun:this.singleDatasetGroupFunction.get(_lastDatasetID) )
nullResult.add(fun.getNoMatchResult(nullReplacement));
}
for( Tuple t1:Util.crossProduct(conf, reporter, nullResult) )
{
for( Tuple t2:others )
{
this.output(Tuple.merge(t1, t2), output, reporter);
}
}
}
else
{
boolean hasNoGroupFunctionForLastDS = this.singleDatasetGroupFunction.get(this._lastDatasetID)==null;
while( valuesFromLastDataset.hasNext() )
{
Tuple aRow = valuesFromLastDataset.next();
aRow.setSchema(this.getSchemaByDatasetID(_lastDatasetID));
if(hasNoGroupFunctionForLastDS)
{
// there is no group function from the last DS, we can
// do some optimization here: as we streaming over the
// values of last dataset, we also emit outputs.
Tuple merged = new Tuple();
for( ExtendFunction func:this.singleDatasetExtendFunction.get(_lastDatasetID) )
{
merged = Tuple.merge(merged, func.getResult(aRow));
}