com.ebay.erl.mobius.core.function
Class Top

java.lang.Object
  extended by com.ebay.erl.mobius.core.function.base.Projectable
      extended by com.ebay.erl.mobius.core.function.base.GroupFunction
          extended by com.ebay.erl.mobius.core.function.Top
All Implemented Interfaces:
java.io.Serializable, org.apache.hadoop.conf.Configurable

public class Top
extends GroupFunction

Returns up to topX Tuple in a group.

Natural ordering is used by default. Users can override the ordering by providing a customized comparator in Top(Dataset, String[], int, Class).

The output result is sorted in the reversed order of the provided comparator.

This product is licensed under the Apache License, Version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0. This product contains portions derived from Apache hadoop which is licensed under the Apache License, Version 2.0, available at http://hadoop.apache.org. © 2007 – 2012 eBay Inc., Evan Chiu, Woody Zhou, Neel Sundaresan

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.ebay.erl.mobius.core.function.base.GroupFunction
rowsToBeOutputted
 
Fields inherited from class com.ebay.erl.mobius.core.function.base.Projectable
conf, hashCode, inputs, outputSchema, reporter, requireDataFromMultiDatasets
 
Constructor Summary
Top(Dataset ds, java.lang.String[] inputColumns, int topX)
          Create a Top operation that emit up to topX rows from the given dataset ds.
Top(Dataset ds, java.lang.String[] inputColumns, int topX, java.lang.Class<? extends java.util.Comparator<Tuple>> comparator)
          Create a Top operation that emit up to topX rows from the given dataset ds.
 
Method Summary
 void consume(Tuple tuple)
          Put the tuple into a min heap, once the heap size is greater than the specified topX, the smallest element (head of the heap) is poll out from the heap.
 BigTupleList getResult()
          Get the computed result.
 void reset()
          Empty previous result (rowsToBeOutputted), reset is called when the values within a group have been all iterated.
 
Methods inherited from class com.ebay.erl.mobius.core.function.base.GroupFunction
getNoMatchResult, getRowsToBeOutputted, output
 
Methods inherited from class com.ebay.erl.mobius.core.function.base.Projectable
calledByCombiner, equals, getConf, getInputColumns, getOutputSchema, getParticipatedDataset, hashCode, init, isCombinable, requireDataFromMultiDatasets, setCalledByCombiner, setConf, setOutputSchema, setReporter, toString, useGroupKeyOnly
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Top

public Top(Dataset ds,
           java.lang.String[] inputColumns,
           int topX)
Create a Top operation that emit up to topX rows from the given dataset ds.

The ordering is natural ordering by comparing the value of inputColumns, in sequence.


Top

public Top(Dataset ds,
           java.lang.String[] inputColumns,
           int topX,
           java.lang.Class<? extends java.util.Comparator<Tuple>> comparator)
Create a Top operation that emit up to topX rows from the given dataset ds.

The ordering is defined by the specified comparator, note that, the comparator can only access columns in inputColumns.

Method Detail

consume

public void consume(Tuple tuple)
Put the tuple into a min heap, once the heap size is greater than the specified topX, the smallest element (head of the heap) is poll out from the heap.

Specified by:
consume in class GroupFunction

getResult

public BigTupleList getResult()
Description copied from class: GroupFunction
Get the computed result.

The computed result will be cross-product with results from other functions ( if any).

Overrides:
getResult in class GroupFunction

reset

public void reset()
Description copied from class: GroupFunction
Empty previous result (rowsToBeOutputted), reset is called when the values within a group have been all iterated.

It is important to call super.reset() when override this method in a sub-class, fail to do so, will result in wrong result.

Overrides:
reset in class GroupFunction