// name and rate against others of same movie
pipe = new CoGroup( pipe, new Fields( "movie" ), 1, new Fields( "name1", "movie", "rate1", "name2", "movie2", "rate2" ) );
// remove useless fields
pipe = new Each( pipe, new Fields( "movie", "name1", "rate1", "name2", "rate2" ), new Identity() );
// remove lines if the names are the same
pipe = new Each( pipe, new RegexFilter( "^[^\\t]*\\t([^\\t]*)\\t[^\\t]*\\t\\1\\t.*", true ) );
// transpose values in fields by natural sort order
pipe = new Each( pipe, new SortElements( new Fields( "name1", "rate1" ), new Fields( "name2", "rate2" ) ) );
// unique the pipe
pipe = new GroupBy( pipe, Fields.ALL );
pipe = new Every( pipe, Fields.ALL, new First(), Fields.RESULTS );
// calculate square of diff
Function sqDiff = new Identity( new Fields( "score" ) )
{
public void operate( FlowProcess flowProcess, FunctionCall functionCall )
{
TupleEntry input = functionCall.getArguments();
functionCall.getOutputCollector().add( new Tuple( Math.pow( input.getTuple().getDouble( 0 ) - input.getTuple().getDouble( 1 ), 2 ) ) );