Search in sources :

Example 1 with FeedbackTransformation

use of org.apache.flink.streaming.api.transformations.FeedbackTransformation 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);
}
Also used : MockSource(org.apache.flink.api.connector.source.mocks.MockSource) SourceTransformation(org.apache.flink.streaming.api.transformations.SourceTransformation) FeedbackTransformation(org.apache.flink.streaming.api.transformations.FeedbackTransformation) CoFeedbackTransformation(org.apache.flink.streaming.api.transformations.CoFeedbackTransformation) Test(org.junit.Test)

Example 2 with FeedbackTransformation

use of org.apache.flink.streaming.api.transformations.FeedbackTransformation in project flink by apache.

the class PythonOperatorChainingOptimizer method replaceInput.

private static void replaceInput(Transformation<?> transformation, Transformation<?> oldInput, Transformation<?> newInput) {
    try {
        if (transformation instanceof OneInputTransformation || transformation instanceof FeedbackTransformation || transformation instanceof SideOutputTransformation || transformation instanceof ReduceTransformation || transformation instanceof SinkTransformation || transformation instanceof LegacySinkTransformation || transformation instanceof TimestampsAndWatermarksTransformation || transformation instanceof PartitionTransformation) {
            final Field inputField = transformation.getClass().getDeclaredField("input");
            inputField.setAccessible(true);
            inputField.set(transformation, newInput);
        } else if (transformation instanceof TwoInputTransformation) {
            final Field inputField;
            if (((TwoInputTransformation<?, ?, ?>) transformation).getInput1() == oldInput) {
                inputField = transformation.getClass().getDeclaredField("input1");
            } else {
                inputField = transformation.getClass().getDeclaredField("input2");
            }
            inputField.setAccessible(true);
            inputField.set(transformation, newInput);
        } else if (transformation instanceof UnionTransformation || transformation instanceof AbstractMultipleInputTransformation) {
            final Field inputsField = transformation.getClass().getDeclaredField("inputs");
            inputsField.setAccessible(true);
            List<Transformation<?>> newInputs = Lists.newArrayList();
            newInputs.addAll(transformation.getInputs());
            newInputs.remove(oldInput);
            newInputs.add(newInput);
            inputsField.set(transformation, newInputs);
        } else if (transformation instanceof AbstractBroadcastStateTransformation) {
            final Field inputField;
            if (((AbstractBroadcastStateTransformation<?, ?, ?>) transformation).getRegularInput() == oldInput) {
                inputField = transformation.getClass().getDeclaredField("regularInput");
            } else {
                inputField = transformation.getClass().getDeclaredField("broadcastInput");
            }
            inputField.setAccessible(true);
            inputField.set(transformation, newInput);
        } else {
            throw new RuntimeException("Unsupported transformation: " + transformation);
        }
    } catch (NoSuchFieldException | IllegalAccessException e) {
        // This should never happen
        throw new RuntimeException(e);
    }
}
Also used : FeedbackTransformation(org.apache.flink.streaming.api.transformations.FeedbackTransformation) ReduceTransformation(org.apache.flink.streaming.api.transformations.ReduceTransformation) TimestampsAndWatermarksTransformation(org.apache.flink.streaming.api.transformations.TimestampsAndWatermarksTransformation) AbstractMultipleInputTransformation(org.apache.flink.streaming.api.transformations.AbstractMultipleInputTransformation) PhysicalTransformation(org.apache.flink.streaming.api.transformations.PhysicalTransformation) SinkTransformation(org.apache.flink.streaming.api.transformations.SinkTransformation) PartitionTransformation(org.apache.flink.streaming.api.transformations.PartitionTransformation) TwoInputTransformation(org.apache.flink.streaming.api.transformations.TwoInputTransformation) UnionTransformation(org.apache.flink.streaming.api.transformations.UnionTransformation) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) SideOutputTransformation(org.apache.flink.streaming.api.transformations.SideOutputTransformation) LegacySinkTransformation(org.apache.flink.streaming.api.transformations.LegacySinkTransformation) Transformation(org.apache.flink.api.dag.Transformation) AbstractBroadcastStateTransformation(org.apache.flink.streaming.api.transformations.AbstractBroadcastStateTransformation) AbstractMultipleInputTransformation(org.apache.flink.streaming.api.transformations.AbstractMultipleInputTransformation) PartitionTransformation(org.apache.flink.streaming.api.transformations.PartitionTransformation) SideOutputTransformation(org.apache.flink.streaming.api.transformations.SideOutputTransformation) Field(java.lang.reflect.Field) TimestampsAndWatermarksTransformation(org.apache.flink.streaming.api.transformations.TimestampsAndWatermarksTransformation) AbstractBroadcastStateTransformation(org.apache.flink.streaming.api.transformations.AbstractBroadcastStateTransformation) LegacySinkTransformation(org.apache.flink.streaming.api.transformations.LegacySinkTransformation) TwoInputTransformation(org.apache.flink.streaming.api.transformations.TwoInputTransformation) UnionTransformation(org.apache.flink.streaming.api.transformations.UnionTransformation) SinkTransformation(org.apache.flink.streaming.api.transformations.SinkTransformation) LegacySinkTransformation(org.apache.flink.streaming.api.transformations.LegacySinkTransformation) ReduceTransformation(org.apache.flink.streaming.api.transformations.ReduceTransformation) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) FeedbackTransformation(org.apache.flink.streaming.api.transformations.FeedbackTransformation)

Aggregations

FeedbackTransformation (org.apache.flink.streaming.api.transformations.FeedbackTransformation)2 Field (java.lang.reflect.Field)1 MockSource (org.apache.flink.api.connector.source.mocks.MockSource)1 Transformation (org.apache.flink.api.dag.Transformation)1 AbstractBroadcastStateTransformation (org.apache.flink.streaming.api.transformations.AbstractBroadcastStateTransformation)1 AbstractMultipleInputTransformation (org.apache.flink.streaming.api.transformations.AbstractMultipleInputTransformation)1 CoFeedbackTransformation (org.apache.flink.streaming.api.transformations.CoFeedbackTransformation)1 LegacySinkTransformation (org.apache.flink.streaming.api.transformations.LegacySinkTransformation)1 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)1 PartitionTransformation (org.apache.flink.streaming.api.transformations.PartitionTransformation)1 PhysicalTransformation (org.apache.flink.streaming.api.transformations.PhysicalTransformation)1 ReduceTransformation (org.apache.flink.streaming.api.transformations.ReduceTransformation)1 SideOutputTransformation (org.apache.flink.streaming.api.transformations.SideOutputTransformation)1 SinkTransformation (org.apache.flink.streaming.api.transformations.SinkTransformation)1 SourceTransformation (org.apache.flink.streaming.api.transformations.SourceTransformation)1 TimestampsAndWatermarksTransformation (org.apache.flink.streaming.api.transformations.TimestampsAndWatermarksTransformation)1 TwoInputTransformation (org.apache.flink.streaming.api.transformations.TwoInputTransformation)1 UnionTransformation (org.apache.flink.streaming.api.transformations.UnionTransformation)1 Test (org.junit.Test)1