Object aggregatedValue = foldLeftFn.apply(message, oldVal);
@Override protected void handleClose() { if (foldLeftFn != null) { foldLeftFn.close(); } if (timeSeriesStore != null) { timeSeriesStore.close(); } if (initializer != null) { initializer.close(); } if (keyFn != null) { keyFn.close(); } }
@Override protected void handleInit(Context context) { KeyValueStore<TimeSeriesKey<K>, Object> store = (KeyValueStore<TimeSeriesKey<K>, Object>) context.getTaskContext().getStore(windowOpSpec.getOpId()); if (initializer != null) { initializer.init(context); } if (keyFn != null) { keyFn.init(context); } // For aggregating windows, we use the store in over-write mode since we only retain the aggregated // value. Else, we use the store in append-mode. if (foldLeftFn != null) { foldLeftFn.init(context); timeSeriesStore = new TimeSeriesStoreImpl(store, false); } else { timeSeriesStore = new TimeSeriesStoreImpl(store, true); } }
@Override protected void handleInit(Context context) { KeyValueStore<TimeSeriesKey<K>, Object> store = (KeyValueStore<TimeSeriesKey<K>, Object>) context.getTaskContext().getStore(windowOpSpec.getOpId()); if (initializer != null) { initializer.init(context); } if (keyFn != null) { keyFn.init(context); } // For aggregating windows, we use the store in over-write mode since we only retain the aggregated // value. Else, we use the store in append-mode. if (foldLeftFn != null) { foldLeftFn.init(context); timeSeriesStore = new TimeSeriesStoreImpl(store, false); } else { timeSeriesStore = new TimeSeriesStoreImpl(store, true); } }
Object aggregatedValue = foldLeftFn.apply(message, oldVal);
@Override protected void handleClose() { if (foldLeftFn != null) { foldLeftFn.close(); } if (timeSeriesStore != null) { timeSeriesStore.close(); } if (initializer != null) { initializer.close(); } if (keyFn != null) { keyFn.close(); } }
@Override protected void handleInit(Context context) { KeyValueStore<TimeSeriesKey<K>, Object> store = (KeyValueStore<TimeSeriesKey<K>, Object>) context.getTaskContext().getStore(windowOpSpec.getOpId()); if (initializer != null) { initializer.init(context); } if (keyFn != null) { keyFn.init(context); } // For aggregating windows, we use the store in over-write mode since we only retain the aggregated // value. Else, we use the store in append-mode. if (foldLeftFn != null) { foldLeftFn.init(context); timeSeriesStore = new TimeSeriesStoreImpl(store, false); } else { timeSeriesStore = new TimeSeriesStoreImpl(store, true); } }
Object aggregatedValue = foldLeftFn.apply(message, oldVal);
@Override protected void handleClose() { if (foldLeftFn != null) { foldLeftFn.close(); } if (timeSeriesStore != null) { timeSeriesStore.close(); } if (initializer != null) { initializer.close(); } if (keyFn != null) { keyFn.close(); } }
@Override protected void handleInit(Context context) { KeyValueStore<TimeSeriesKey<K>, Object> store = (KeyValueStore<TimeSeriesKey<K>, Object>) context.getTaskContext().getStore(windowOpSpec.getOpId()); if (initializer != null) { initializer.init(context); } if (keyFn != null) { keyFn.init(context); } // For aggregating windows, we use the store in over-write mode since we only retain the aggregated // value. Else, we use the store in append-mode. if (foldLeftFn != null) { foldLeftFn.init(context); timeSeriesStore = new TimeSeriesStoreImpl(store, false); } else { timeSeriesStore = new TimeSeriesStoreImpl(store, true); } }
Object aggregatedValue = foldLeftFn.apply(message, oldVal);
@Override protected void handleClose() { if (foldLeftFn != null) { foldLeftFn.close(); } if (timeSeriesStore != null) { timeSeriesStore.close(); } if (initializer != null) { initializer.close(); } if (keyFn != null) { keyFn.close(); } }
@Override protected void handleInit(Context context) { KeyValueStore<TimeSeriesKey<K>, Object> store = (KeyValueStore<TimeSeriesKey<K>, Object>) context.getTaskContext().getStore(windowOpSpec.getOpId()); if (initializer != null) { initializer.init(context); } if (keyFn != null) { keyFn.init(context); } // For aggregating windows, we use the store in over-write mode since we only retain the aggregated // value. Else, we use the store in append-mode. if (foldLeftFn != null) { foldLeftFn.init(context); timeSeriesStore = new TimeSeriesStoreImpl(store, false); } else { timeSeriesStore = new TimeSeriesStoreImpl(store, true); } }
Object aggregatedValue = foldLeftFn.apply(message, oldVal);
@Override protected void handleClose() { if (foldLeftFn != null) { foldLeftFn.close(); } if (timeSeriesStore != null) { timeSeriesStore.close(); } if (initializer != null) { initializer.close(); } if (keyFn != null) { keyFn.close(); } }
@Test public void testCopy() { WindowInternal<Object, Object, Collection> window = new WindowInternal<Object, Object, Collection>( defaultTrigger, supplierFunction, foldFn, keyFn, timeFn, WindowType.SESSION, null, mock(Serde.class), mock(Serde.class)); window.setEarlyTrigger(earlyTrigger); WindowOperatorSpec<Object, Object, Collection> spec = new WindowOperatorSpec<>(window, "w0"); WindowOperatorSpec<Object, Object, Collection> copy = (WindowOperatorSpec<Object, Object, Collection>) OperatorSpecTestUtils.copyOpSpec(spec); Assert.assertNotEquals(spec, copy); Assert.assertTrue(spec.isClone(copy)); Assert.assertNotEquals(spec.getWindow(), copy.getWindow()); Assert.assertNotEquals(copy.getWindow().getInitializer(), supplierFunction); assertEquals(copy.getWindow().getInitializer().get(), supplierFunction.get()); Assert.assertNotEquals(copy.getWindow().getFoldLeftFunction(), foldFn); Object mockMsg = new Object(); assertEquals(copy.getWindow().getFoldLeftFunction().apply(mockMsg, new ArrayList<>()), foldFn.apply(mockMsg, new ArrayList<>())); Assert.assertNotEquals(copy.getWindow().getKeyExtractor(), keyFn); assertEquals(copy.getWindow().getKeyExtractor().apply(mockMsg), keyFn.apply(mockMsg)); Assert.assertNotEquals(copy.getWindow().getEventTimeExtractor(), timeFn); assertEquals(copy.getWindow().getEventTimeExtractor().apply(mockMsg), timeFn.apply(mockMsg)); assertEquals(copy.getDefaultTriggerMs(), 150); }