use of org.apache.flink.streaming.api.transformations.SourceTransformation in project flink by apache.
the class UpsertKafkaDynamicTableFactoryTest method assertKafkaSource.
private void assertKafkaSource(ScanTableSource.ScanRuntimeProvider provider) {
assertThat(provider, instanceOf(DataStreamScanProvider.class));
final DataStreamScanProvider dataStreamScanProvider = (DataStreamScanProvider) provider;
final Transformation<RowData> transformation = dataStreamScanProvider.produceDataStream(n -> Optional.empty(), StreamExecutionEnvironment.createLocalEnvironment()).getTransformation();
assertThat(transformation, instanceOf(SourceTransformation.class));
SourceTransformation<RowData, KafkaPartitionSplit, KafkaSourceEnumState> sourceTransformation = (SourceTransformation<RowData, KafkaPartitionSplit, KafkaSourceEnumState>) transformation;
assertThat(sourceTransformation.getSource(), instanceOf(KafkaSource.class));
}
use of org.apache.flink.streaming.api.transformations.SourceTransformation in project flink by apache.
the class StreamGraphGeneratorBatchExecutionTest method testFeedbackThrowsExceptionInBatch.
@Test
public void testFeedbackThrowsExceptionInBatch() {
final SourceTransformation<Integer, ?, ?> bounded = new SourceTransformation<>("Bounded Source", new MockSource(Boundedness.BOUNDED, 100), WatermarkStrategy.noWatermarks(), IntegerTypeInfo.of(Integer.class), 1);
final FeedbackTransformation<Integer> feedbackTransformation = new FeedbackTransformation<>(bounded, 5L);
testNoSupportForIterationsInBatchHelper(bounded, feedbackTransformation);
}
use of org.apache.flink.streaming.api.transformations.SourceTransformation in project flink by apache.
the class FoldApplyProcessWindowFunctionTest method testFoldWindowFunctionOutputTypeConfigurable.
/**
* Tests that the FoldWindowFunction gets the output type serializer set by the
* StreamGraphGenerator and checks that the FoldWindowFunction computes the correct result.
*/
@Test
public void testFoldWindowFunctionOutputTypeConfigurable() throws Exception {
StreamExecutionEnvironment env = new DummyStreamExecutionEnvironment();
List<StreamTransformation<?>> transformations = new ArrayList<>();
int initValue = 1;
FoldApplyProcessWindowFunction<Integer, TimeWindow, Integer, Integer, Integer> foldWindowFunction = new FoldApplyProcessWindowFunction<>(initValue, new FoldFunction<Integer, Integer>() {
@Override
public Integer fold(Integer accumulator, Integer value) throws Exception {
return accumulator + value;
}
}, new ProcessWindowFunction<Integer, Integer, Integer, TimeWindow>() {
@Override
public void process(Integer integer, Context context, Iterable<Integer> input, Collector<Integer> out) throws Exception {
for (Integer in : input) {
out.collect(in);
}
}
}, BasicTypeInfo.INT_TYPE_INFO);
AccumulatingProcessingTimeWindowOperator<Integer, Integer, Integer> windowOperator = new AccumulatingProcessingTimeWindowOperator<>(new InternalIterableProcessWindowFunction<>(foldWindowFunction), new KeySelector<Integer, Integer>() {
private static final long serialVersionUID = -7951310554369722809L;
@Override
public Integer getKey(Integer value) throws Exception {
return value;
}
}, IntSerializer.INSTANCE, IntSerializer.INSTANCE, 3000, 3000);
SourceFunction<Integer> sourceFunction = new SourceFunction<Integer>() {
private static final long serialVersionUID = 8297735565464653028L;
@Override
public void run(SourceContext<Integer> ctx) throws Exception {
}
@Override
public void cancel() {
}
};
SourceTransformation<Integer> source = new SourceTransformation<>("", new StreamSource<>(sourceFunction), BasicTypeInfo.INT_TYPE_INFO, 1);
transformations.add(new OneInputTransformation<>(source, "test", windowOperator, BasicTypeInfo.INT_TYPE_INFO, 1));
StreamGraph streamGraph = StreamGraphGenerator.generate(env, transformations, 1);
List<Integer> result = new ArrayList<>();
List<Integer> input = new ArrayList<>();
List<Integer> expected = new ArrayList<>();
input.add(1);
input.add(2);
input.add(3);
for (int value : input) {
initValue += value;
}
expected.add(initValue);
foldWindowFunction.process(0, foldWindowFunction.new Context() {
@Override
public TimeWindow window() {
return new TimeWindow(0, 1);
}
}, input, new ListCollector<>(result));
Assert.assertEquals(expected, result);
}
use of org.apache.flink.streaming.api.transformations.SourceTransformation in project flink by apache.
the class KafkaDynamicTableFactoryTest method assertKafkaSource.
private KafkaSource<?> assertKafkaSource(ScanTableSource.ScanRuntimeProvider provider) {
assertThat(provider).isInstanceOf(DataStreamScanProvider.class);
final DataStreamScanProvider dataStreamScanProvider = (DataStreamScanProvider) provider;
final Transformation<RowData> transformation = dataStreamScanProvider.produceDataStream(n -> Optional.empty(), StreamExecutionEnvironment.createLocalEnvironment()).getTransformation();
assertThat(transformation).isInstanceOf(SourceTransformation.class);
SourceTransformation<RowData, KafkaPartitionSplit, KafkaSourceEnumState> sourceTransformation = (SourceTransformation<RowData, KafkaPartitionSplit, KafkaSourceEnumState>) transformation;
assertThat(sourceTransformation.getSource()).isInstanceOf(KafkaSource.class);
return (KafkaSource<?>) sourceTransformation.getSource();
}
use of org.apache.flink.streaming.api.transformations.SourceTransformation in project flink by apache.
the class PythonOperatorChainingOptimizerTest method testChainingNonKeyedOperators.
@Test
public void testChainingNonKeyedOperators() {
PythonProcessOperator<?, ?> processOperator1 = createProcessOperator("f1", new RowTypeInfo(Types.INT(), Types.INT()), Types.STRING());
PythonProcessOperator<?, ?> processOperator2 = createProcessOperator("f2", Types.STRING(), Types.INT());
Transformation<?> sourceTransformation = mock(SourceTransformation.class);
OneInputTransformation<?, ?> processTransformation1 = new OneInputTransformation(sourceTransformation, "Process1", processOperator1, processOperator1.getProducedType(), 2);
Transformation<?> processTransformation2 = new OneInputTransformation(processTransformation1, "process2", processOperator2, processOperator2.getProducedType(), 2);
List<Transformation<?>> transformations = new ArrayList<>();
transformations.add(sourceTransformation);
transformations.add(processTransformation1);
transformations.add(processTransformation2);
List<Transformation<?>> optimized = PythonOperatorChainingOptimizer.optimize(transformations);
assertEquals(2, optimized.size());
OneInputTransformation<?, ?> chainedTransformation = (OneInputTransformation<?, ?>) optimized.get(1);
assertEquals(sourceTransformation.getOutputType(), chainedTransformation.getInputType());
assertEquals(processOperator2.getProducedType(), chainedTransformation.getOutputType());
OneInputStreamOperator<?, ?> chainedOperator = chainedTransformation.getOperator();
assertTrue(chainedOperator instanceof PythonProcessOperator);
validateChainedPythonFunctions(((PythonProcessOperator<?, ?>) chainedOperator).getPythonFunctionInfo(), "f2", "f1");
}
Aggregations