RankAnalytic

A RankAnalytic is an AnalyticFunction that determines the ranking over any values, returning the rank as a Long. Values range from 1 through a number less than or equal to the number of rows in the partition. Distinct order by values result in evenly spaced values, e.g. 1 2 3 4 5. If there are equivalent order by values, then all equivalent values receive the same value, and the next value will have a gap, e.g. 1 2 2 4 5.

Usage

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

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

RankAnalytic is a NoPropAnalytic, so it is an error to specify a property. It does not take a user-given window clause.

If every order by value is distinct, then this generates the same values as RowNumberAnalytic.