use of org.apache.beam.sdk.transforms.windowing.GlobalWindow in project beam by apache.
the class ProcessFnRunner method checkTrivialOuterWindows.
private static <T> void checkTrivialOuterWindows(WindowedValue<KeyedWorkItem<String, T>> windowedKWI) {
// In practice it will be in 0 or 1 windows (ValueInEmptyWindows or ValueInGlobalWindow)
Collection<? extends BoundedWindow> outerWindows = windowedKWI.getWindows();
if (!outerWindows.isEmpty()) {
checkArgument(outerWindows.size() == 1, "The KeyedWorkItem itself must not be in multiple windows, but was in: %s", outerWindows);
BoundedWindow onlyWindow = Iterables.getOnlyElement(outerWindows);
checkArgument(onlyWindow instanceof GlobalWindow, "KeyedWorkItem must be in the Global window, but was in: %s", onlyWindow);
}
}
use of org.apache.beam.sdk.transforms.windowing.GlobalWindow in project beam by apache.
the class TimestampPrefixingWindowCoderTest method testEncodeAndDecode.
@Test
public void testEncodeAndDecode() throws Exception {
List<IntervalWindow> intervalWindowsToTest = Lists.newArrayList(new IntervalWindow(new Instant(0L), new Instant(1L)), new IntervalWindow(new Instant(100L), new Instant(200L)), new IntervalWindow(new Instant(0L), BoundedWindow.TIMESTAMP_MAX_VALUE));
TimestampPrefixingWindowCoder<IntervalWindow> coder1 = TimestampPrefixingWindowCoder.of(IntervalWindow.getCoder());
for (IntervalWindow window : intervalWindowsToTest) {
CoderProperties.coderDecodeEncodeEqual(coder1, window);
}
GlobalWindow globalWindow = GlobalWindow.INSTANCE;
TimestampPrefixingWindowCoder<GlobalWindow> coder2 = TimestampPrefixingWindowCoder.of(GlobalWindow.Coder.INSTANCE);
CoderProperties.coderDecodeEncodeEqual(coder2, globalWindow);
TimestampPrefixingWindowCoder<CustomWindow> coder3 = TimestampPrefixingWindowCoder.of(CustomWindowCoder.of(true, true));
for (CustomWindow window : CUSTOM_WINDOW_LIST) {
CoderProperties.coderDecodeEncodeEqual(coder3, window);
}
}
use of org.apache.beam.sdk.transforms.windowing.GlobalWindow in project beam by apache.
the class TransformTranslatorTest method testSplitBySameKey.
@Test
public void testSplitBySameKey() {
VarIntCoder coder = VarIntCoder.of();
WindowedValue.WindowedValueCoder<Integer> wvCoder = WindowedValue.FullWindowedValueCoder.of(coder, GlobalWindow.Coder.INSTANCE);
Instant now = Instant.now();
List<GlobalWindow> window = Arrays.asList(GlobalWindow.INSTANCE);
PaneInfo paneInfo = PaneInfo.NO_FIRING;
List<Tuple2<ByteArray, byte[]>> firstKey = Arrays.asList(new Tuple2(new ByteArray(CoderHelpers.toByteArrayWithTs(1, coder, now)), CoderHelpers.toByteArray(WindowedValue.of(1, now, window, paneInfo), wvCoder)), new Tuple2(new ByteArray(CoderHelpers.toByteArrayWithTs(1, coder, now.plus(Duration.millis(1)))), CoderHelpers.toByteArray(WindowedValue.of(2, now.plus(Duration.millis(1)), window, paneInfo), wvCoder)));
List<Tuple2<ByteArray, byte[]>> secondKey = Arrays.asList(new Tuple2(new ByteArray(CoderHelpers.toByteArrayWithTs(2, coder, now)), CoderHelpers.toByteArray(WindowedValue.of(3, now, window, paneInfo), wvCoder)), new Tuple2(new ByteArray(CoderHelpers.toByteArrayWithTs(2, coder, now.plus(Duration.millis(2)))), CoderHelpers.toByteArray(WindowedValue.of(4, now.plus(Duration.millis(2)), window, paneInfo), wvCoder)));
Iterable<Tuple2<ByteArray, byte[]>> concat = Iterables.concat(firstKey, secondKey);
Iterator<Iterator<WindowedValue<KV<Integer, Integer>>>> keySplit;
keySplit = TransformTranslator.splitBySameKey(concat.iterator(), coder, wvCoder);
for (int i = 0; i < 2; i++) {
Iterator<WindowedValue<KV<Integer, Integer>>> iter = keySplit.next();
List<WindowedValue<KV<Integer, Integer>>> list = new ArrayList<>();
Iterators.addAll(list, iter);
if (i == 0) {
// first key
assertEquals(Arrays.asList(WindowedValue.of(KV.of(1, 1), now, window, paneInfo), WindowedValue.of(KV.of(1, 2), now.plus(Duration.millis(1)), window, paneInfo)), list);
} else {
// second key
assertEquals(Arrays.asList(WindowedValue.of(KV.of(2, 3), now, window, paneInfo), WindowedValue.of(KV.of(2, 4), now.plus(Duration.millis(2)), window, paneInfo)), list);
}
}
}
use of org.apache.beam.sdk.transforms.windowing.GlobalWindow in project beam by apache.
the class RepeatedlyStateMachineTest method testRepeatedlyElementCount.
@Test
public void testRepeatedlyElementCount() throws Exception {
SimpleTriggerStateMachineTester<GlobalWindow> tester = TriggerStateMachineTester.forTrigger(RepeatedlyStateMachine.forever(AfterPaneStateMachine.elementCountAtLeast(5)), new GlobalWindows());
GlobalWindow window = GlobalWindow.INSTANCE;
tester.injectElements(1);
assertFalse(tester.shouldFire(window));
tester.injectElements(2, 3, 4, 5);
assertTrue(tester.shouldFire(window));
tester.fireIfShouldFire(window);
assertFalse(tester.shouldFire(window));
}
use of org.apache.beam.sdk.transforms.windowing.GlobalWindow in project beam by apache.
the class RepeatedlyStateMachineTest method testRepeatedlyProcessingTime.
@Test
public void testRepeatedlyProcessingTime() throws Exception {
SimpleTriggerStateMachineTester<GlobalWindow> tester = TriggerStateMachineTester.forTrigger(RepeatedlyStateMachine.forever(AfterProcessingTimeStateMachine.pastFirstElementInPane().plusDelayOf(Duration.standardMinutes(15))), new GlobalWindows());
GlobalWindow window = GlobalWindow.INSTANCE;
tester.injectElements(1);
assertFalse(tester.shouldFire(window));
tester.advanceProcessingTime(new Instant(0).plus(Duration.standardMinutes(15)));
assertTrue(tester.shouldFire(window));
tester.fireIfShouldFire(window);
assertFalse(tester.shouldFire(window));
}
Aggregations