Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Example section provides code snippets that shows how to use AggregationCondition to define the aggregator of condition and filter the aggregation with the aggregator. For example, in the user transaction analysis  scenario: find order id with an order amount greater than 10 within 5 seconds. In the following example, we define OrderSumCondition which extends AggregationCondition to express that the accumulative order sum is greater than 10.


Code Block
languagejava
titleOrderSumCondition
public class OrderSumCondition extends AggregationCondition<Event, Double> {

    @Override
    public boolean filter(Event value, Context<Event> ctx) throws Exception {
        return ctx.getAggregate("start") > 10.0;     
    }

     @Override
     public Tuple2<Aggregator<Double>, TypeSerializer<Double>> getAggregator() throws Exception {
        return new Tuple2(new DoubleSumAggregator(), DoubleSerializer.INSTANCE);
    }
}

...