org.apache.flink.streaming.api.windowing.windows.Window Java Examples
The following examples show how to use
org.apache.flink.streaming.api.windowing.windows.Window.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WindowOperatorContractTest.java From flink with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private static <T, W extends Window> void shouldMergeWindows(final MergingWindowAssigner<T, W> assigner, final Collection<? extends W> expectedWindows, final Collection<W> toMerge, final W mergeResult) { doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Exception { Collection<W> windows = (Collection<W>) invocation.getArguments()[0]; MergingWindowAssigner.MergeCallback callback = (MergingWindowAssigner.MergeCallback) invocation.getArguments()[1]; // verify the expected windows assertThat(windows, containsInAnyOrder(expectedWindows.toArray())); callback.merge(toMerge, mergeResult); return null; } }) .when(assigner).mergeWindows(anyCollection(), Matchers.<MergingWindowAssigner.MergeCallback>anyObject()); }
Example #2
Source File: WindowOperatorContractTest.java From flink with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private static <T, W extends Window> void shouldMergeWindows(final MergingWindowAssigner<T, W> assigner, final Collection<? extends W> expectedWindows, final Collection<W> toMerge, final W mergeResult) { doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Exception { Collection<W> windows = (Collection<W>) invocation.getArguments()[0]; MergingWindowAssigner.MergeCallback callback = (MergingWindowAssigner.MergeCallback) invocation.getArguments()[1]; // verify the expected windows assertThat(windows, containsInAnyOrder(expectedWindows.toArray())); callback.merge(toMerge, mergeResult); return null; } }) .when(assigner).mergeWindows(anyCollection(), Matchers.<MergingWindowAssigner.MergeCallback>anyObject()); }
Example #3
Source File: GroupedProcessingTimeWindowExample.java From flink with Apache License 2.0 | 5 votes |
@Override public void apply(Long key, Window window, Iterable<Tuple2<Long, Long>> values, Collector<Tuple2<Long, Long>> out) { long sum = 0L; for (Tuple2<Long, Long> value : values) { sum += value.f1; } out.collect(new Tuple2<>(key, sum)); }
Example #4
Source File: RegularWindowOperatorContractTest.java From flink with Apache License 2.0 | 5 votes |
@Override protected <W extends Window, OUT> KeyedOneInputStreamOperatorTestHarness<Integer, Integer, OUT> createWindowOperator( WindowAssigner<Integer, W> assigner, Trigger<Integer, W> trigger, long allowedLatenss, InternalWindowFunction<Iterable<Integer>, OUT, Integer, W> windowFunction, OutputTag<Integer> lateOutputTag) throws Exception { KeySelector<Integer, Integer> keySelector = new KeySelector<Integer, Integer>() { private static final long serialVersionUID = 1L; @Override public Integer getKey(Integer value) throws Exception { return value; } }; ListStateDescriptor<Integer> intListDescriptor = new ListStateDescriptor<>("int-list", IntSerializer.INSTANCE); @SuppressWarnings("unchecked") WindowOperator<Integer, Integer, Iterable<Integer>, OUT, W> operator = new WindowOperator<>( assigner, assigner.getWindowSerializer(new ExecutionConfig()), keySelector, IntSerializer.INSTANCE, intListDescriptor, windowFunction, trigger, allowedLatenss, lateOutputTag); return new KeyedOneInputStreamOperatorTestHarness<>( operator, keySelector, BasicTypeInfo.INT_TYPE_INFO); }
Example #5
Source File: RegularWindowOperatorContractTest.java From flink with Apache License 2.0 | 5 votes |
/** * Special method for creating a {@link WindowOperator} with a custom {@link StateDescriptor} * for the window contents state. */ private <W extends Window, ACC, OUT> KeyedOneInputStreamOperatorTestHarness<Integer, Integer, OUT> createWindowOperator( WindowAssigner<Integer, W> assigner, Trigger<Integer, W> trigger, long allowedLatenss, StateDescriptor<? extends AppendingState<Integer, ACC>, ?> stateDescriptor, InternalWindowFunction<ACC, OUT, Integer, W> windowFunction) throws Exception { KeySelector<Integer, Integer> keySelector = new KeySelector<Integer, Integer>() { private static final long serialVersionUID = 1L; @Override public Integer getKey(Integer value) throws Exception { return value; } }; @SuppressWarnings("unchecked") WindowOperator<Integer, Integer, ACC, OUT, W> operator = new WindowOperator<>( assigner, assigner.getWindowSerializer(new ExecutionConfig()), keySelector, IntSerializer.INSTANCE, stateDescriptor, windowFunction, trigger, allowedLatenss, null /* late output tag */); return new KeyedOneInputStreamOperatorTestHarness<>( operator, keySelector, BasicTypeInfo.INT_TYPE_INFO); }
Example #6
Source File: RegularWindowOperatorContractTest.java From flink with Apache License 2.0 | 5 votes |
@Override protected <W extends Window, OUT> KeyedOneInputStreamOperatorTestHarness<Integer, Integer, OUT> createWindowOperator( WindowAssigner<Integer, W> assigner, Trigger<Integer, W> trigger, long allowedLatenss, InternalWindowFunction<Iterable<Integer>, OUT, Integer, W> windowFunction) throws Exception { return createWindowOperator( assigner, trigger, allowedLatenss, windowFunction, null /* late output tag */); }
Example #7
Source File: RegularWindowOperatorContractTest.java From flink with Apache License 2.0 | 5 votes |
/** * Special method for creating a {@link WindowOperator} with a custom {@link StateDescriptor} * for the window contents state. */ private <W extends Window, ACC, OUT> KeyedOneInputStreamOperatorTestHarness<Integer, Integer, OUT> createWindowOperator( WindowAssigner<Integer, W> assigner, Trigger<Integer, W> trigger, long allowedLatenss, StateDescriptor<? extends AppendingState<Integer, ACC>, ?> stateDescriptor, InternalWindowFunction<ACC, OUT, Integer, W> windowFunction) throws Exception { KeySelector<Integer, Integer> keySelector = new KeySelector<Integer, Integer>() { private static final long serialVersionUID = 1L; @Override public Integer getKey(Integer value) throws Exception { return value; } }; @SuppressWarnings("unchecked") WindowOperator<Integer, Integer, ACC, OUT, W> operator = new WindowOperator<>( assigner, assigner.getWindowSerializer(new ExecutionConfig()), keySelector, IntSerializer.INSTANCE, stateDescriptor, windowFunction, trigger, allowedLatenss, null /* late output tag */); return new KeyedOneInputStreamOperatorTestHarness<>( operator, keySelector, BasicTypeInfo.INT_TYPE_INFO); }
Example #8
Source File: GroupedProcessingTimeWindowExample.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public void apply(Long key, Window window, Iterable<Tuple2<Long, Long>> values, Collector<Tuple2<Long, Long>> out) { long sum = 0L; for (Tuple2<Long, Long> value : values) { sum += value.f1; } out.collect(new Tuple2<>(key, sum)); }
Example #9
Source File: RegularWindowOperatorContractTest.java From flink with Apache License 2.0 | 5 votes |
@Override protected <W extends Window, OUT> KeyedOneInputStreamOperatorTestHarness<Integer, Integer, OUT> createWindowOperator( WindowAssigner<Integer, W> assigner, Trigger<Integer, W> trigger, long allowedLatenss, InternalWindowFunction<Iterable<Integer>, OUT, Integer, W> windowFunction, OutputTag<Integer> lateOutputTag) throws Exception { KeySelector<Integer, Integer> keySelector = new KeySelector<Integer, Integer>() { private static final long serialVersionUID = 1L; @Override public Integer getKey(Integer value) throws Exception { return value; } }; ListStateDescriptor<Integer> intListDescriptor = new ListStateDescriptor<>("int-list", IntSerializer.INSTANCE); @SuppressWarnings("unchecked") WindowOperator<Integer, Integer, Iterable<Integer>, OUT, W> operator = new WindowOperator<>( assigner, assigner.getWindowSerializer(new ExecutionConfig()), keySelector, IntSerializer.INSTANCE, intListDescriptor, windowFunction, trigger, allowedLatenss, lateOutputTag); return new KeyedOneInputStreamOperatorTestHarness<>( operator, keySelector, BasicTypeInfo.INT_TYPE_INFO); }
Example #10
Source File: EvictingWindowOperatorContractTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
protected <W extends Window, OUT> KeyedOneInputStreamOperatorTestHarness<Integer, Integer, OUT> createWindowOperator( WindowAssigner<Integer, W> assigner, Trigger<Integer, W> trigger, long allowedLatenss, InternalWindowFunction<Iterable<Integer>, OUT, Integer, W> windowFunction, OutputTag<Integer> lateOutputTag) throws Exception { KeySelector<Integer, Integer> keySelector = new KeySelector<Integer, Integer>() { private static final long serialVersionUID = 1L; @Override public Integer getKey(Integer value) throws Exception { return value; } }; ListStateDescriptor<StreamRecord<Integer>> intListDescriptor = new ListStateDescriptor<>( "int-list", (TypeSerializer<StreamRecord<Integer>>) new StreamElementSerializer(IntSerializer.INSTANCE)); @SuppressWarnings("unchecked") EvictingWindowOperator<Integer, Integer, OUT, W> operator = new EvictingWindowOperator<>( assigner, assigner.getWindowSerializer(new ExecutionConfig()), keySelector, IntSerializer.INSTANCE, intListDescriptor, windowFunction, trigger, CountEvictor.<W>of(100), allowedLatenss, lateOutputTag); return new KeyedOneInputStreamOperatorTestHarness<>( operator, keySelector, BasicTypeInfo.INT_TYPE_INFO); }
Example #11
Source File: RegularWindowOperatorContractTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Special method for creating a {@link WindowOperator} with a custom {@link StateDescriptor} * for the window contents state. */ private <W extends Window, ACC, OUT> KeyedOneInputStreamOperatorTestHarness<Integer, Integer, OUT> createWindowOperator( WindowAssigner<Integer, W> assigner, Trigger<Integer, W> trigger, long allowedLatenss, StateDescriptor<? extends AppendingState<Integer, ACC>, ?> stateDescriptor, InternalWindowFunction<ACC, OUT, Integer, W> windowFunction) throws Exception { KeySelector<Integer, Integer> keySelector = new KeySelector<Integer, Integer>() { private static final long serialVersionUID = 1L; @Override public Integer getKey(Integer value) throws Exception { return value; } }; @SuppressWarnings("unchecked") WindowOperator<Integer, Integer, ACC, OUT, W> operator = new WindowOperator<>( assigner, assigner.getWindowSerializer(new ExecutionConfig()), keySelector, IntSerializer.INSTANCE, stateDescriptor, windowFunction, trigger, allowedLatenss, null /* late output tag */); return new KeyedOneInputStreamOperatorTestHarness<>( operator, keySelector, BasicTypeInfo.INT_TYPE_INFO); }
Example #12
Source File: RegularWindowOperatorContractTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override protected <W extends Window, OUT> KeyedOneInputStreamOperatorTestHarness<Integer, Integer, OUT> createWindowOperator( WindowAssigner<Integer, W> assigner, Trigger<Integer, W> trigger, long allowedLatenss, InternalWindowFunction<Iterable<Integer>, OUT, Integer, W> windowFunction, OutputTag<Integer> lateOutputTag) throws Exception { KeySelector<Integer, Integer> keySelector = new KeySelector<Integer, Integer>() { private static final long serialVersionUID = 1L; @Override public Integer getKey(Integer value) throws Exception { return value; } }; ListStateDescriptor<Integer> intListDescriptor = new ListStateDescriptor<>("int-list", IntSerializer.INSTANCE); @SuppressWarnings("unchecked") WindowOperator<Integer, Integer, Iterable<Integer>, OUT, W> operator = new WindowOperator<>( assigner, assigner.getWindowSerializer(new ExecutionConfig()), keySelector, IntSerializer.INSTANCE, intListDescriptor, windowFunction, trigger, allowedLatenss, lateOutputTag); return new KeyedOneInputStreamOperatorTestHarness<>( operator, keySelector, BasicTypeInfo.INT_TYPE_INFO); }
Example #13
Source File: RegularWindowOperatorContractTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override protected <W extends Window, OUT> KeyedOneInputStreamOperatorTestHarness<Integer, Integer, OUT> createWindowOperator( WindowAssigner<Integer, W> assigner, Trigger<Integer, W> trigger, long allowedLatenss, InternalWindowFunction<Iterable<Integer>, OUT, Integer, W> windowFunction) throws Exception { return createWindowOperator( assigner, trigger, allowedLatenss, windowFunction, null /* late output tag */); }
Example #14
Source File: EvictingWindowOperatorContractTest.java From flink with Apache License 2.0 | 5 votes |
protected <W extends Window, OUT> KeyedOneInputStreamOperatorTestHarness<Integer, Integer, OUT> createWindowOperator( WindowAssigner<Integer, W> assigner, Trigger<Integer, W> trigger, long allowedLatenss, InternalWindowFunction<Iterable<Integer>, OUT, Integer, W> windowFunction, OutputTag<Integer> lateOutputTag) throws Exception { KeySelector<Integer, Integer> keySelector = new KeySelector<Integer, Integer>() { private static final long serialVersionUID = 1L; @Override public Integer getKey(Integer value) throws Exception { return value; } }; ListStateDescriptor<StreamRecord<Integer>> intListDescriptor = new ListStateDescriptor<>( "int-list", (TypeSerializer<StreamRecord<Integer>>) new StreamElementSerializer(IntSerializer.INSTANCE)); @SuppressWarnings("unchecked") EvictingWindowOperator<Integer, Integer, OUT, W> operator = new EvictingWindowOperator<>( assigner, assigner.getWindowSerializer(new ExecutionConfig()), keySelector, IntSerializer.INSTANCE, intListDescriptor, windowFunction, trigger, CountEvictor.<W>of(100), allowedLatenss, lateOutputTag); return new KeyedOneInputStreamOperatorTestHarness<>( operator, keySelector, BasicTypeInfo.INT_TYPE_INFO); }
Example #15
Source File: EvictingWindowOperatorContractTest.java From flink with Apache License 2.0 | 5 votes |
protected <W extends Window, OUT> KeyedOneInputStreamOperatorTestHarness<Integer, Integer, OUT> createWindowOperator( WindowAssigner<Integer, W> assigner, Trigger<Integer, W> trigger, long allowedLatenss, InternalWindowFunction<Iterable<Integer>, OUT, Integer, W> windowFunction) throws Exception { return createWindowOperator( assigner, trigger, allowedLatenss, windowFunction, null /* late output tag */); }
Example #16
Source File: EvictingWindowOperatorContractTest.java From flink with Apache License 2.0 | 5 votes |
protected <W extends Window, OUT> KeyedOneInputStreamOperatorTestHarness<Integer, Integer, OUT> createWindowOperator( WindowAssigner<Integer, W> assigner, Trigger<Integer, W> trigger, long allowedLatenss, InternalWindowFunction<Iterable<Integer>, OUT, Integer, W> windowFunction, OutputTag<Integer> lateOutputTag) throws Exception { KeySelector<Integer, Integer> keySelector = new KeySelector<Integer, Integer>() { private static final long serialVersionUID = 1L; @Override public Integer getKey(Integer value) throws Exception { return value; } }; ListStateDescriptor<StreamRecord<Integer>> intListDescriptor = new ListStateDescriptor<>( "int-list", (TypeSerializer<StreamRecord<Integer>>) new StreamElementSerializer(IntSerializer.INSTANCE)); @SuppressWarnings("unchecked") EvictingWindowOperator<Integer, Integer, OUT, W> operator = new EvictingWindowOperator<>( assigner, assigner.getWindowSerializer(new ExecutionConfig()), keySelector, IntSerializer.INSTANCE, intListDescriptor, windowFunction, trigger, CountEvictor.<W>of(100), allowedLatenss, lateOutputTag); return new KeyedOneInputStreamOperatorTestHarness<>( operator, keySelector, BasicTypeInfo.INT_TYPE_INFO); }
Example #17
Source File: GroupedProcessingTimeWindowExample.java From flink with Apache License 2.0 | 5 votes |
@Override public void apply(Long key, Window window, Iterable<Tuple2<Long, Long>> values, Collector<Tuple2<Long, Long>> out) { long sum = 0L; for (Tuple2<Long, Long> value : values) { sum += value.f1; } out.collect(new Tuple2<>(key, sum)); }
Example #18
Source File: IntLongApplications.java From flink-benchmarks with Apache License 2.0 | 5 votes |
public static <W extends Window> void reduceWithWindow( DataStreamSource<IntegerLongSource.Record> source, WindowAssigner<Object, W> windowAssigner) { source .map(new MultiplyIntLongByTwo()) .keyBy(record -> record.key) .window(windowAssigner) .reduce(new SumReduceIntLong()) .addSink(new CollectSink()); }
Example #19
Source File: StreamRecordMatchers.java From flink with Apache License 2.0 | 4 votes |
public static <T, W extends Window> Matcher<StreamRecord<? extends WindowedValue<? extends T, ? extends W>>> isWindowedValue( Matcher<? super T> valueMatcher, Matcher<? super Long> timestampMatcher) { return new WindowedValueMatcher<>(valueMatcher, timestampMatcher, Matchers.anything()); }
Example #20
Source File: WindowOperatorContractTest.java From flink with Apache License 2.0 | 4 votes |
protected abstract <W extends Window, OUT> KeyedOneInputStreamOperatorTestHarness<Integer, Integer, OUT> createWindowOperator( WindowAssigner<Integer, W> assigner, Trigger<Integer, W> trigger, long allowedLateness, InternalWindowFunction<Iterable<Integer>, OUT, Integer, W> windowFunction, OutputTag<Integer> lateOutputTag) throws Exception;
Example #21
Source File: StreamRecordMatchers.java From flink with Apache License 2.0 | 4 votes |
public static <T, W extends Window> Matcher<StreamRecord<? extends WindowedValue<? extends T, ? extends W>>> isWindowedValue( Matcher<? super T> valueMatcher, long timestamp) { return new WindowedValueMatcher<>(valueMatcher, Matchers.equalTo(timestamp), Matchers.anything()); }
Example #22
Source File: StreamRecordMatchers.java From flink with Apache License 2.0 | 4 votes |
public static <T, W extends Window> Matcher<StreamRecord<? extends WindowedValue<? extends T, ? extends W>>> isWindowedValue( Matcher<? super T> valueMatcher, Matcher<? super Long> timestampMatcher) { return new WindowedValueMatcher<>(valueMatcher, timestampMatcher, Matchers.anything()); }
Example #23
Source File: StreamRecordMatchers.java From flink with Apache License 2.0 | 4 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) @SafeVarargs public static <W extends Window> Matcher<Iterable<W>> ofWindows(Matcher<W>... windows) { return (Matcher) Matchers.containsInAnyOrder(windows); }
Example #24
Source File: StreamRecordMatchers.java From flink with Apache License 2.0 | 4 votes |
public static <T, W extends Window> Matcher<StreamRecord<? extends WindowedValue<? extends T, ? extends W>>> isWindowedValue( T value) { return isWindowedValue(Matchers.equalTo(value)); }
Example #25
Source File: JoinedStreams.java From flink with Apache License 2.0 | 4 votes |
/** * Specifies the window on which the join operation works. */ @PublicEvolving public <W extends Window> WithWindow<T1, T2, KEY, W> window(WindowAssigner<? super TaggedUnion<T1, T2>, W> assigner) { return new WithWindow<>(input1, input2, keySelector1, keySelector2, keyType, assigner, null, null, null); }
Example #26
Source File: CoGroupedStreams.java From flink with Apache License 2.0 | 4 votes |
/** * Specifies the window on which the co-group operation works. */ @PublicEvolving public <W extends Window> WithWindow<T1, T2, KEY, W> window(WindowAssigner<? super TaggedUnion<T1, T2>, W> assigner) { return new WithWindow<>(input1, input2, keySelector1, keySelector2, keyType, assigner, null, null, null); }
Example #27
Source File: JoinedStreams.java From flink with Apache License 2.0 | 4 votes |
/** * Specifies the window on which the join operation works. */ @PublicEvolving public <W extends Window> WithWindow<T1, T2, KEY, W> window(WindowAssigner<? super TaggedUnion<T1, T2>, W> assigner) { return new WithWindow<>(input1, input2, keySelector1, keySelector2, keyType, assigner, null, null, null); }
Example #28
Source File: StreamRecordMatchers.java From flink with Apache License 2.0 | 4 votes |
public static <T, W extends Window> Matcher<StreamRecord<? extends WindowedValue<? extends T, ? extends W>>> isWindowedValue( T value, long timestamp) { return isWindowedValue(Matchers.equalTo(value), Matchers.equalTo(timestamp)); }
Example #29
Source File: StreamRecordMatchers.java From flink with Apache License 2.0 | 4 votes |
public static <T, W extends Window> Matcher<StreamRecord<? extends WindowedValue<? extends T, ? extends W>>> isWindowedValue( Matcher<? super T> valueMatcher) { return new WindowedValueMatcher<>(valueMatcher, Matchers.anything(), Matchers.anything()); }
Example #30
Source File: StreamRecordMatchers.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
public static <T, W extends Window> Matcher<StreamRecord<? extends WindowedValue<? extends T, ? extends W>>> isWindowedValue( Matcher<? super T> valueMatcher, long timestamp, Matcher<? super W> windowMatcher) { return new WindowedValueMatcher<>(valueMatcher, Matchers.equalTo(timestamp), windowMatcher); }