A LagAnalytic is an AnalyticFunction that retrieves a property value from a different row behind the current row, returning the property value as a Object, e.g. "Lag(prop)". By default, it looks at the row immediately behind the curent row, but a different number of rows can be specified, e.g. "Lag(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. "Lag(prop, 2, 0)".
Create and use a LagAnalytic, with one of the following methods:
AnalyticAggregator ana = new AnalyticAggregator.Builder() .setAnalyticFunction(new LagAnalytic("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("Lag(value1, 2, 0) partitionBy(category1) orderBy(value2 DESC)");
LagAnalytic is an AbstractOffsetAnalytic. It does not take a user-given window clause.
Lag and Lead are opposite functions. That is, Lag(prop, n, def) is equivalent to Lead(prop, -n, def).