Java Code Examples for org.apache.flink.api.common.state.FoldingStateDescriptor#initializeSerializerUnlessSet()
The following examples show how to use
org.apache.flink.api.common.state.FoldingStateDescriptor#initializeSerializerUnlessSet() .
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: KeyedStream.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Publishes the keyed stream as a queryable FoldingState instance. * * @param queryableStateName Name under which to the publish the queryable state instance * @param stateDescriptor State descriptor to create state instance from * @return Queryable state instance * * @deprecated will be removed in a future version */ @PublicEvolving @Deprecated public <ACC> QueryableStateStream<KEY, ACC> asQueryableState( String queryableStateName, FoldingStateDescriptor<T, ACC> stateDescriptor) { transform("Queryable state: " + queryableStateName, getType(), new QueryableAppendingStateOperator<>(queryableStateName, stateDescriptor)); stateDescriptor.initializeSerializerUnlessSet(getExecutionConfig()); return new QueryableStateStream<>( queryableStateName, stateDescriptor, getKeyType().createSerializer(getExecutionConfig())); }
Example 2
Source File: KeyedStream.java From flink with Apache License 2.0 | 6 votes |
/** * Publishes the keyed stream as a queryable FoldingState instance. * * @param queryableStateName Name under which to the publish the queryable state instance * @param stateDescriptor State descriptor to create state instance from * @return Queryable state instance * * @deprecated will be removed in a future version */ @PublicEvolving @Deprecated public <ACC> QueryableStateStream<KEY, ACC> asQueryableState( String queryableStateName, FoldingStateDescriptor<T, ACC> stateDescriptor) { transform("Queryable state: " + queryableStateName, getType(), new QueryableAppendingStateOperator<>(queryableStateName, stateDescriptor)); stateDescriptor.initializeSerializerUnlessSet(getExecutionConfig()); return new QueryableStateStream<>( queryableStateName, stateDescriptor, getKeyType().createSerializer(getExecutionConfig())); }
Example 3
Source File: KeyedStream.java From flink with Apache License 2.0 | 6 votes |
/** * Publishes the keyed stream as a queryable FoldingState instance. * * @param queryableStateName Name under which to the publish the queryable state instance * @param stateDescriptor State descriptor to create state instance from * @return Queryable state instance * * @deprecated will be removed in a future version */ @PublicEvolving @Deprecated public <ACC> QueryableStateStream<KEY, ACC> asQueryableState( String queryableStateName, FoldingStateDescriptor<T, ACC> stateDescriptor) { transform("Queryable state: " + queryableStateName, getType(), new QueryableAppendingStateOperator<>(queryableStateName, stateDescriptor)); stateDescriptor.initializeSerializerUnlessSet(getExecutionConfig()); return new QueryableStateStream<>( queryableStateName, stateDescriptor, getKeyType().createSerializer(getExecutionConfig())); }
Example 4
Source File: DefaultKeyedStateStore.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) { requireNonNull(stateProperties, "The state properties must not be null"); try { stateProperties.initializeSerializerUnlessSet(executionConfig); return getPartitionedState(stateProperties); } catch (Exception e) { throw new RuntimeException("Error while getting state", e); } }
Example 5
Source File: DefaultKeyedStateStore.java From flink with Apache License 2.0 | 5 votes |
@Override public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) { requireNonNull(stateProperties, "The state properties must not be null"); try { stateProperties.initializeSerializerUnlessSet(executionConfig); return getPartitionedState(stateProperties); } catch (Exception e) { throw new RuntimeException("Error while getting state", e); } }
Example 6
Source File: DefaultKeyedStateStore.java From flink with Apache License 2.0 | 5 votes |
@Override public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) { requireNonNull(stateProperties, "The state properties must not be null"); try { stateProperties.initializeSerializerUnlessSet(executionConfig); return getPartitionedState(stateProperties); } catch (Exception e) { throw new RuntimeException("Error while getting state", e); } }
Example 7
Source File: StreamingRuntimeContext.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Override public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) { KeyedStateStore keyedStateStore = checkPreconditionsAndGetKeyedStateStore(stateProperties); stateProperties.initializeSerializerUnlessSet(getExecutionConfig()); return keyedStateStore.getFoldingState(stateProperties); }
Example 8
Source File: WindowOperatorTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testCleanupTimerWithEmptyFoldingStateForTumblingWindows() throws Exception { final int windowSize = 2; final long lateness = 1; FoldingStateDescriptor<Tuple2<String, Integer>, Tuple2<String, Integer>> windowStateDesc = new FoldingStateDescriptor<>( "window-contents", new Tuple2<>((String) null, 0), new FoldFunction<Tuple2<String, Integer>, Tuple2<String, Integer>>() { private static final long serialVersionUID = 1L; @Override public Tuple2<String, Integer> fold(Tuple2<String, Integer> accumulator, Tuple2<String, Integer> value) throws Exception { return new Tuple2<>(value.f0, accumulator.f1 + value.f1); } }, STRING_INT_TUPLE); windowStateDesc.initializeSerializerUnlessSet(new ExecutionConfig()); WindowOperator<String, Tuple2<String, Integer>, Tuple2<String, Integer>, Tuple2<String, Integer>, TimeWindow> operator = new WindowOperator<>( TumblingEventTimeWindows.of(Time.of(windowSize, TimeUnit.SECONDS)), new TimeWindow.Serializer(), new TupleKeySelector(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()), windowStateDesc, new InternalSingleValueWindowFunction<>(new PassThroughFunction()), EventTimeTrigger.create(), lateness, null /* late data output tag */); OneInputStreamOperatorTestHarness<Tuple2<String, Integer>, Tuple2<String, Integer>> testHarness = createTestHarness(operator); testHarness.open(); ConcurrentLinkedQueue<Object> expected = new ConcurrentLinkedQueue<>(); // normal element testHarness.processElement(new StreamRecord<>(new Tuple2<>("key2", 1), 1000)); testHarness.processWatermark(new Watermark(1599)); testHarness.processWatermark(new Watermark(1999)); testHarness.processWatermark(new Watermark(2000)); testHarness.processWatermark(new Watermark(5000)); expected.add(new Watermark(1599)); expected.add(new StreamRecord<>(new Tuple2<>("key2", 1), 1999)); expected.add(new Watermark(1999)); // here it fires and purges expected.add(new Watermark(2000)); // here is the cleanup timer expected.add(new Watermark(5000)); TestHarnessUtil.assertOutputEqualsSorted("Output was not correct.", expected, testHarness.getOutput(), new Tuple2ResultSortComparator()); testHarness.close(); }
Example 9
Source File: WindowOperatorTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testCleanupTimerWithEmptyFoldingStateForSessionWindows() throws Exception { final int gapSize = 3; final long lateness = 10; FoldingStateDescriptor<Tuple2<String, Integer>, Tuple2<String, Integer>> windowStateDesc = new FoldingStateDescriptor<>( "window-contents", new Tuple2<>((String) null, 0), new FoldFunction<Tuple2<String, Integer>, Tuple2<String, Integer>>() { private static final long serialVersionUID = 1L; @Override public Tuple2<String, Integer> fold(Tuple2<String, Integer> accumulator, Tuple2<String, Integer> value) throws Exception { return new Tuple2<>(value.f0, accumulator.f1 + value.f1); } }, STRING_INT_TUPLE); windowStateDesc.initializeSerializerUnlessSet(new ExecutionConfig()); WindowOperator<String, Tuple2<String, Integer>, Tuple2<String, Integer>, Tuple2<String, Integer>, TimeWindow> operator = new WindowOperator<>( EventTimeSessionWindows.withGap(Time.seconds(gapSize)), new TimeWindow.Serializer(), new TupleKeySelector(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()), windowStateDesc, new InternalSingleValueWindowFunction<>(new PassThroughFunction()), EventTimeTrigger.create(), lateness, null /* late data output tag */); OneInputStreamOperatorTestHarness<Tuple2<String, Integer>, Tuple2<String, Integer>> testHarness = createTestHarness(operator); testHarness.open(); ConcurrentLinkedQueue<Object> expected = new ConcurrentLinkedQueue<>(); testHarness.processElement(new StreamRecord<>(new Tuple2<>("key2", 1), 1000)); testHarness.processWatermark(new Watermark(4998)); expected.add(new StreamRecord<>(new Tuple2<>("key2", 1), 3999)); expected.add(new Watermark(4998)); testHarness.processWatermark(new Watermark(14600)); expected.add(new Watermark(14600)); ConcurrentLinkedQueue<Object> actual = testHarness.getOutput(); TestHarnessUtil.assertOutputEqualsSorted("Output was not correct.", expected, actual, new Tuple2ResultSortComparator()); testHarness.close(); }
Example 10
Source File: StreamingRuntimeContext.java From flink with Apache License 2.0 | 4 votes |
@Override public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) { KeyedStateStore keyedStateStore = checkPreconditionsAndGetKeyedStateStore(stateProperties); stateProperties.initializeSerializerUnlessSet(getExecutionConfig()); return keyedStateStore.getFoldingState(stateProperties); }
Example 11
Source File: WindowOperatorTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testCleanupTimerWithEmptyFoldingStateForTumblingWindows() throws Exception { final int windowSize = 2; final long lateness = 1; FoldingStateDescriptor<Tuple2<String, Integer>, Tuple2<String, Integer>> windowStateDesc = new FoldingStateDescriptor<>( "window-contents", new Tuple2<>((String) null, 0), new FoldFunction<Tuple2<String, Integer>, Tuple2<String, Integer>>() { private static final long serialVersionUID = 1L; @Override public Tuple2<String, Integer> fold(Tuple2<String, Integer> accumulator, Tuple2<String, Integer> value) throws Exception { return new Tuple2<>(value.f0, accumulator.f1 + value.f1); } }, STRING_INT_TUPLE); windowStateDesc.initializeSerializerUnlessSet(new ExecutionConfig()); WindowOperator<String, Tuple2<String, Integer>, Tuple2<String, Integer>, Tuple2<String, Integer>, TimeWindow> operator = new WindowOperator<>( TumblingEventTimeWindows.of(Time.of(windowSize, TimeUnit.SECONDS)), new TimeWindow.Serializer(), new TupleKeySelector(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()), windowStateDesc, new InternalSingleValueWindowFunction<>(new PassThroughFunction()), EventTimeTrigger.create(), lateness, null /* late data output tag */); OneInputStreamOperatorTestHarness<Tuple2<String, Integer>, Tuple2<String, Integer>> testHarness = createTestHarness(operator); testHarness.open(); ConcurrentLinkedQueue<Object> expected = new ConcurrentLinkedQueue<>(); // normal element testHarness.processElement(new StreamRecord<>(new Tuple2<>("key2", 1), 1000)); testHarness.processWatermark(new Watermark(1599)); testHarness.processWatermark(new Watermark(1999)); testHarness.processWatermark(new Watermark(2000)); testHarness.processWatermark(new Watermark(5000)); expected.add(new Watermark(1599)); expected.add(new StreamRecord<>(new Tuple2<>("key2", 1), 1999)); expected.add(new Watermark(1999)); // here it fires and purges expected.add(new Watermark(2000)); // here is the cleanup timer expected.add(new Watermark(5000)); TestHarnessUtil.assertOutputEqualsSorted("Output was not correct.", expected, testHarness.getOutput(), new Tuple2ResultSortComparator()); testHarness.close(); }
Example 12
Source File: WindowOperatorTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testCleanupTimerWithEmptyFoldingStateForSessionWindows() throws Exception { final int gapSize = 3; final long lateness = 10; FoldingStateDescriptor<Tuple2<String, Integer>, Tuple2<String, Integer>> windowStateDesc = new FoldingStateDescriptor<>( "window-contents", new Tuple2<>((String) null, 0), new FoldFunction<Tuple2<String, Integer>, Tuple2<String, Integer>>() { private static final long serialVersionUID = 1L; @Override public Tuple2<String, Integer> fold(Tuple2<String, Integer> accumulator, Tuple2<String, Integer> value) throws Exception { return new Tuple2<>(value.f0, accumulator.f1 + value.f1); } }, STRING_INT_TUPLE); windowStateDesc.initializeSerializerUnlessSet(new ExecutionConfig()); WindowOperator<String, Tuple2<String, Integer>, Tuple2<String, Integer>, Tuple2<String, Integer>, TimeWindow> operator = new WindowOperator<>( EventTimeSessionWindows.withGap(Time.seconds(gapSize)), new TimeWindow.Serializer(), new TupleKeySelector(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()), windowStateDesc, new InternalSingleValueWindowFunction<>(new PassThroughFunction()), EventTimeTrigger.create(), lateness, null /* late data output tag */); OneInputStreamOperatorTestHarness<Tuple2<String, Integer>, Tuple2<String, Integer>> testHarness = createTestHarness(operator); testHarness.open(); ConcurrentLinkedQueue<Object> expected = new ConcurrentLinkedQueue<>(); testHarness.processElement(new StreamRecord<>(new Tuple2<>("key2", 1), 1000)); testHarness.processWatermark(new Watermark(4998)); expected.add(new StreamRecord<>(new Tuple2<>("key2", 1), 3999)); expected.add(new Watermark(4998)); testHarness.processWatermark(new Watermark(14600)); expected.add(new Watermark(14600)); ConcurrentLinkedQueue<Object> actual = testHarness.getOutput(); TestHarnessUtil.assertOutputEqualsSorted("Output was not correct.", expected, actual, new Tuple2ResultSortComparator()); testHarness.close(); }
Example 13
Source File: WindowOperatorTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testCleanupTimerWithEmptyFoldingStateForTumblingWindows() throws Exception { final int windowSize = 2; final long lateness = 1; FoldingStateDescriptor<Tuple2<String, Integer>, Tuple2<String, Integer>> windowStateDesc = new FoldingStateDescriptor<>( "window-contents", new Tuple2<>((String) null, 0), new FoldFunction<Tuple2<String, Integer>, Tuple2<String, Integer>>() { private static final long serialVersionUID = 1L; @Override public Tuple2<String, Integer> fold(Tuple2<String, Integer> accumulator, Tuple2<String, Integer> value) throws Exception { return new Tuple2<>(value.f0, accumulator.f1 + value.f1); } }, STRING_INT_TUPLE); windowStateDesc.initializeSerializerUnlessSet(new ExecutionConfig()); WindowOperator<String, Tuple2<String, Integer>, Tuple2<String, Integer>, Tuple2<String, Integer>, TimeWindow> operator = new WindowOperator<>( TumblingEventTimeWindows.of(Time.of(windowSize, TimeUnit.SECONDS)), new TimeWindow.Serializer(), new TupleKeySelector(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()), windowStateDesc, new InternalSingleValueWindowFunction<>(new PassThroughFunction()), EventTimeTrigger.create(), lateness, null /* late data output tag */); OneInputStreamOperatorTestHarness<Tuple2<String, Integer>, Tuple2<String, Integer>> testHarness = createTestHarness(operator); testHarness.open(); ConcurrentLinkedQueue<Object> expected = new ConcurrentLinkedQueue<>(); // normal element testHarness.processElement(new StreamRecord<>(new Tuple2<>("key2", 1), 1000)); testHarness.processWatermark(new Watermark(1599)); testHarness.processWatermark(new Watermark(1999)); testHarness.processWatermark(new Watermark(2000)); testHarness.processWatermark(new Watermark(5000)); expected.add(new Watermark(1599)); expected.add(new StreamRecord<>(new Tuple2<>("key2", 1), 1999)); expected.add(new Watermark(1999)); // here it fires and purges expected.add(new Watermark(2000)); // here is the cleanup timer expected.add(new Watermark(5000)); TestHarnessUtil.assertOutputEqualsSorted("Output was not correct.", expected, testHarness.getOutput(), new Tuple2ResultSortComparator()); testHarness.close(); }
Example 14
Source File: WindowOperatorTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testCleanupTimerWithEmptyFoldingStateForSessionWindows() throws Exception { final int gapSize = 3; final long lateness = 10; FoldingStateDescriptor<Tuple2<String, Integer>, Tuple2<String, Integer>> windowStateDesc = new FoldingStateDescriptor<>( "window-contents", new Tuple2<>((String) null, 0), new FoldFunction<Tuple2<String, Integer>, Tuple2<String, Integer>>() { private static final long serialVersionUID = 1L; @Override public Tuple2<String, Integer> fold(Tuple2<String, Integer> accumulator, Tuple2<String, Integer> value) throws Exception { return new Tuple2<>(value.f0, accumulator.f1 + value.f1); } }, STRING_INT_TUPLE); windowStateDesc.initializeSerializerUnlessSet(new ExecutionConfig()); WindowOperator<String, Tuple2<String, Integer>, Tuple2<String, Integer>, Tuple2<String, Integer>, TimeWindow> operator = new WindowOperator<>( EventTimeSessionWindows.withGap(Time.seconds(gapSize)), new TimeWindow.Serializer(), new TupleKeySelector(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()), windowStateDesc, new InternalSingleValueWindowFunction<>(new PassThroughFunction()), EventTimeTrigger.create(), lateness, null /* late data output tag */); OneInputStreamOperatorTestHarness<Tuple2<String, Integer>, Tuple2<String, Integer>> testHarness = createTestHarness(operator); testHarness.open(); ConcurrentLinkedQueue<Object> expected = new ConcurrentLinkedQueue<>(); testHarness.processElement(new StreamRecord<>(new Tuple2<>("key2", 1), 1000)); testHarness.processWatermark(new Watermark(4998)); expected.add(new StreamRecord<>(new Tuple2<>("key2", 1), 3999)); expected.add(new Watermark(4998)); testHarness.processWatermark(new Watermark(14600)); expected.add(new Watermark(14600)); ConcurrentLinkedQueue<Object> actual = testHarness.getOutput(); TestHarnessUtil.assertOutputEqualsSorted("Output was not correct.", expected, actual, new Tuple2ResultSortComparator()); testHarness.close(); }