LeadAnalytic

A LeadAnalytic is an AnalyticFunction that retrieves a property value from a different row ahead of the current row, returning the property value as a Object, e.g. "Lead(prop)". By default, it looks at the row immediately ahead of the curent row, but a different number of rows can be specified, e.g. "Lead(prop, 2)". If there is no such row in the partition, then the default value of null is returned. This default value can also be changed. e.g. "Lead(prop, 2, 0)".

Usage

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

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

LeadAnalytic is an AbstractOffsetAnalytic. It does not take a user-given window clause.

Lead and Lag are opposite functions. That is, Lead(prop, n, def) is equivalent to Lag(prop, -n, def).