public Aggregate(Window<T,K, ? extends List<T>> window, BiFunction<List<T>,K, U> aggregator){ this.aggregator = aggregator; BiConsumer<List<T>, K> partProcessor = (tuples, key) -> { U aggregateTuple = aggregator.apply(tuples, key); if (aggregateTuple != null) submit(aggregateTuple); }; window.registerPartitionProcessor(partProcessor); this.window=window; }
public Aggregate(Window<T,K, ? extends List<T>> window, BiFunction<List<T>,K, U> aggregator){ this.aggregator = aggregator; BiConsumer<List<T>, K> partProcessor = (tuples, key) -> { U aggregateTuple = aggregator.apply(tuples, key); if (aggregateTuple != null) submit(aggregateTuple); }; window.registerPartitionProcessor(partProcessor); this.window=window; }
/** * Pressure reliever that maintains up to {@code count} most recent tuples per key. * * @param count Number of tuples to maintain where downstream processing cannot keep up. * @param keyFunction Key function for tuples. */ public PressureReliever(int count, Function<T, K> keyFunction) { window = Windows.window( Policies.alwaysInsert(), Policies.countContentsPolicy(count), Policies.evictOldest(), new FirstSubmitter(), keyFunction, () -> new LinkedList<T>()); // No processing of the window takes place window.registerPartitionProcessor((tuples, k) -> { }); }
/** * Pressure reliever that maintains up to {@code count} most recent tuples per key. * * @param count Number of tuples to maintain where downstream processing cannot keep up. * @param keyFunction Key function for tuples. */ public PressureReliever(int count, Function<T, K> keyFunction) { window = Windows.window( Policies.alwaysInsert(), Policies.countContentsPolicy(count), Policies.evictOldest(), new FirstSubmitter(), keyFunction, () -> new LinkedList<T>()); // No processing of the window takes place window.registerPartitionProcessor((tuples, k) -> { }); }
@Test public void noWaitConcurrentWindowAccessTest() throws InterruptedException { Window<Integer, Integer, ? extends List<Integer>> window = Windows.lastNProcessOnInsert(100, tuple -> 0); window.registerPartitionProcessor((tuples, key) -> {}); long finishTime = System.currentTimeMillis() + 3000;
incrementalWindowStates.addLast(new LinkedList<Integer>(tuples)); }; window.registerPartitionProcessor(wp);
window.registerPartitionProcessor((tuples, key) -> {
incrementalWindowStates.addLast(new LinkedList<Integer>(tuples)); }; window.registerPartitionProcessor(wp);
() -> new ArrayList<Integer>()); window.registerPartitionProcessor(new BiConsumer<List<Integer>, Integer>() { @Override public void accept(List<Integer> t, Integer u) {
() -> new ArrayList<Integer>()); window.registerPartitionProcessor(new BiConsumer<List<Integer>, Integer>() { @Override public void accept(List<Integer> t, Integer u) {
incrementalWindowStates.addLast(new LinkedList<Integer>(tuples)); }; window.registerPartitionProcessor(wp);
() -> new InsertionTimeList<Long>()); window.registerPartitionProcessor((tuples, key) -> { if(tuples.size() > 1) diffs.add(tuples.get(tuples.size()-1) - tuples.get(0));
() -> new ArrayList<Integer>()); window.registerPartitionProcessor(new BiConsumer<List<Integer>, Integer>() { @Override public void accept(List<Integer> t, Integer u) {
@SuppressWarnings("serial") @Test public void countBatchWindowTest(){ List<Integer> numBatches = new LinkedList<>(); Window<Integer, Integer, List<Integer>> window = Windows.window( alwaysInsert(), Policies.doNothing(), Policies.evictAll(), Policies.processWhenFullAndEvict(113), tuple -> 0, () -> new ArrayList<Integer>()); window.registerPartitionProcessor(new BiConsumer<List<Integer>, Integer>() { @Override public void accept(List<Integer> t, Integer u) { numBatches.add(1); } }); for(int i = 0; i < 1000; i++){ window.insert(i); } assertTrue(numBatches.size() == 8); }