-
- All Implemented Interfaces:
LogicalOperator
,PipelineOperator<RecordPort>
,RecordPipelineOperator
public class Rank extends AbstractExecutableRecordPipeline
Rank data using the given rank mode. The data is grouped by the given partition field(s) and is sorted within the grouping by the ranking field(s). An example is to rank employees by salary per department. To rank the highest to lowest salary within department: partition by the department and rank by the salary in descending sort order.Three different rank modes are supported:
- STANDARD: also known as competition ranking, items with the same ranking values have the same rank and then a gap is left in the ranking numbers; for example: 1224
- DENSE: items that compare equal receive the same ranking, items following receive the next ordinal ranking (i.e. ranks are not skipped); for example: 1223
- ORDINAL: each item receives a distinct ranking, starting at 1 and increasing by one producing essentially a row number within the partition; for example: 1234
A new output field is created to contain the result of the ranking. The field is named "rank" by default. The name of the rank field can be set using
setOutputField(String)
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Rank.RankMode
Definition of the supported rank modes.
-
Field Summary
-
Fields inherited from class com.pervasive.datarush.operators.AbstractExecutableRecordPipeline
input, output
-
-
Constructor Summary
Constructors Constructor Description Rank()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
computeMetadata(StreamingMetadataContext ctx)
Implementations must adhere to the following contractsprotected void
execute(ExecutionContext ctx)
Executes the operator.RecordPort
getInput()
Gets the record port providing the input data to the operation.Rank.RankMode
getMode()
Get the mode used for ranking.RecordPort
getOutput()
Gets the record port providing the output from the operation.String
getOutputField()
Get the name of the output ranking field.List<String>
getPartitionBy()
Get the list of fields used to partition the input data.List<SortKey>
getRankBy()
Get the list of fields used for ranking within each partition.void
setMode(Rank.RankMode mode)
Set the ranking mode.void
setOutputField(String outputField)
Set the name of the output field that will contain the ranking order for each record.void
setPartitionBy(String... partitionKeys)
Set the fields used for partitioning the input data.void
setPartitionBy(List<String> partitionKeys)
Set the fields used for partitioning the input data.void
setRankBy(SortKey... rankBy)
Set the list of fields to use for ranking.void
setRankBy(String... rankBy)
Set the list of fields to use for ranking.void
setRankBy(List<SortKey> rankBy)
Set the list of fields to use for ranking.-
Methods inherited from class com.pervasive.datarush.operators.ExecutableOperator
cloneForExecution, getNumInputCopies, getPortSettings, handleInactiveOutput
-
Methods inherited from class com.pervasive.datarush.operators.AbstractLogicalOperator
disableParallelism, getInputPorts, getOutputPorts, newInput, newInput, newOutput, newRecordInput, newRecordInput, newRecordOutput, notifyError
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.pervasive.datarush.operators.LogicalOperator
disableParallelism, getInputPorts, getOutputPorts
-
-
-
-
Method Detail
-
getInput
public RecordPort getInput()
Description copied from class:AbstractExecutableRecordPipeline
Gets the record port providing the input data to the operation.- Specified by:
getInput
in interfacePipelineOperator<RecordPort>
- Overrides:
getInput
in classAbstractExecutableRecordPipeline
- Returns:
- the input port for the operation
-
getOutput
public RecordPort getOutput()
Description copied from class:AbstractExecutableRecordPipeline
Gets the record port providing the output from the operation.- Specified by:
getOutput
in interfacePipelineOperator<RecordPort>
- Overrides:
getOutput
in classAbstractExecutableRecordPipeline
- Returns:
- the output port for the operation
-
setPartitionBy
public void setPartitionBy(List<String> partitionKeys)
Set the fields used for partitioning the input data.- Parameters:
partitionKeys
- list of fields to use for partitioning
-
setPartitionBy
public void setPartitionBy(String... partitionKeys)
Set the fields used for partitioning the input data.- Parameters:
partitionKeys
- list of fields to use for partitioning
-
getPartitionBy
public List<String> getPartitionBy()
Get the list of fields used to partition the input data.- Returns:
- list of fields to use for partitioning
-
setRankBy
public void setRankBy(SortKey... rankBy)
Set the list of fields to use for ranking. The data within each partition is sorted by the specified order. This specifies the set of fields used to calculate the rating within each partitioned group.- Parameters:
rankBy
- list of fields used to rank the data
-
setRankBy
public void setRankBy(String... rankBy)
Set the list of fields to use for ranking. The data within each partition is sorted by the specified order. This specifies the set of fields used to calculate the rating within each partitioned group. The rank order can be a list of fields with the sort order specified (optional) as 'asc' or 'desc'.- Parameters:
rankBy
- list of fields used to rank the data along with sort order
-
setRankBy
public void setRankBy(List<SortKey> rankBy)
Set the list of fields to use for ranking. The data within each partition is sorted by the specified order. This specifies the set of fields used to calculate the rating within each partitioned group.- Parameters:
rankBy
- list of fields used to rank the data
-
getRankBy
public List<SortKey> getRankBy()
Get the list of fields used for ranking within each partition.- Returns:
- list of ranking fields
-
setMode
public void setMode(Rank.RankMode mode)
Set the ranking mode. Ordinal ranking is used by default.- Parameters:
mode
- rank mode
-
getMode
public Rank.RankMode getMode()
Get the mode used for ranking.- Returns:
- rank mode
-
setOutputField
public void setOutputField(String outputField)
Set the name of the output field that will contain the ranking order for each record.- Parameters:
outputField
- name of the ranking results field
-
getOutputField
public String getOutputField()
Get the name of the output ranking field.- Returns:
- name of the ranking results field
-
computeMetadata
protected void computeMetadata(StreamingMetadataContext ctx)
Description copied from class:StreamingOperator
Implementations must adhere to the following contractsGeneral
Regardless of input ports/output port types, all implementations must do the following:- Validation. Validation of configuration should always be performed first.
- Declare parallelizability.. Implementations must declare parallelizability by calling
StreamingMetadataContext.parallelize(ParallelismStrategy)
.
Input record ports
Implementations with input record ports must declare the following:- Required data ordering: Implementations that have data ordering requirements must declare them by calling
- Required data distribution (only applies to parallelizable operators): Implementations that have data distribution requirements must declare them by calling
RecordPort#setRequiredDataOrdering
, otherwise data may arrive in any order.RecordPort#setRequiredDataDistribution
, otherwise data will arrive in anunspecified partial distribution
.RecordPort#getSourceDataDistribution
andRecordPort#getSourceDataOrdering
. These should be viewed as a hints to help chose a more efficient algorithm. In such cases, though, operators must still declare data ordering and data distribution requirements; otherwise there is no guarantee that data will arrive sorted/distributed as required.Output record ports
Implementations with output record ports must declare the following:- Type: Implementations must declare their output type by calling
RecordPort#setType
.
- Output data ordering: Implementations that can make guarantees as to their output
ordering may do so by calling
RecordPort#setOutputDataOrdering
- Output data distribution (only applies to parallelizable operators): Implementations that can make guarantees as to their output
distribution may do so by calling
RecordPort#setOutputDataDistribution
Input model ports
In general, there is nothing special to declare for input model ports. Models are implicitly duplicated to all partitions when going from non-parallel to parallel operators. The case of a model going from a parallel to a non-parallel node is a special case of a "model reducer" operator. In the case of a model reducer, the downstream operator, must declare the following:- Merge handler: Model reducers must declare a merge handler by
calling
AbstractModelPort#setMergeHandler
.
MergeModel
is a convenient, re-usable model reducer, parameterized with a merge-handler.Output model ports
SimpleModelPort
's have no associated metadata and therefore there is never any output metadata to declare.PMMLPort
's, on the other hand, do have associated metadata. For all PMMLPorts, implementations must declare the following:- pmmlModelSpec: Implementations must declare the PMML model spec
by calling
PMMLPort.setPMMLModelSpec
.
- Specified by:
computeMetadata
in classStreamingOperator
- Parameters:
ctx
- the context
-
execute
protected void execute(ExecutionContext ctx)
Description copied from class:ExecutableOperator
Executes the operator. Implementations should adhere to the following contracts:- Following execution, all input ports must be at end-of-data.
- Following execution, all output ports must be at end-of-data.
- Specified by:
execute
in classExecutableOperator
- Parameters:
ctx
- context in which to lookup physical ports bound to logical ports
-
-