PercentRankAnalytic

A PercentRankAnalytic is an AnalyticFunction that determines the percent ranking over any values, returning the percent ranking as a Double. Values range from 0.0 to 1.0 (exclusive). The percent ranking is the percentage of "order by" values that this value ranks lower than, according to the order by clause. Values that are equivalent don't rank lower than each other, so they are assigned the same value, e.g. 0.0 0.2 0.2 0.6 0.8.

Usage

Create and use a PercentRankAnalytic, with one of the following methods:

  • AnalyticAggregator ana = new AnalyticAggregator.Builder()
        .setAnalyticFunction(new PercentRankAnalytic())
        .setPartition(new PartitionClause(Arrays.asList("category1")))
        .setOrderBy(new OrderByClause(Arrays.asList(new OrderByElement("value2", OrderByElement.SortDir.DESC))))
        .build();
    
  • AnalyticAggregator agg = AnalyticAggregator.getAnalytic("PercentRankAnalytic() partitionBy(category1) orderBy(value2 DESC)");
    

PercentRankAnalytic ignores any property passed in.

No row will receive a value of 1.0, but all values that compare equal to the first row according to the order by clause will receive 0.0.

PercentRankAnalytic is a DependentAnalyticFunction that computes the percent ranking with Rank() / Count(*) range(), and it does not take a user-given window clause.