Search in sources :

Example 1 with OutputTypeConfigurable

use of org.apache.flink.streaming.api.operators.OutputTypeConfigurable in project flink by apache.

the class StreamGraph method addOperator.

public <IN, OUT> void addOperator(Integer vertexID, String slotSharingGroup, StreamOperator<OUT> operatorObject, TypeInformation<IN> inTypeInfo, TypeInformation<OUT> outTypeInfo, String operatorName) {
    if (operatorObject instanceof StoppableStreamSource) {
        addNode(vertexID, slotSharingGroup, StoppableSourceStreamTask.class, operatorObject, operatorName);
    } else if (operatorObject instanceof StreamSource) {
        addNode(vertexID, slotSharingGroup, SourceStreamTask.class, operatorObject, operatorName);
    } else {
        addNode(vertexID, slotSharingGroup, OneInputStreamTask.class, operatorObject, operatorName);
    }
    TypeSerializer<IN> inSerializer = inTypeInfo != null && !(inTypeInfo instanceof MissingTypeInfo) ? inTypeInfo.createSerializer(executionConfig) : null;
    TypeSerializer<OUT> outSerializer = outTypeInfo != null && !(outTypeInfo instanceof MissingTypeInfo) ? outTypeInfo.createSerializer(executionConfig) : null;
    setSerializers(vertexID, inSerializer, null, outSerializer);
    if (operatorObject instanceof OutputTypeConfigurable && outTypeInfo != null) {
        @SuppressWarnings("unchecked") OutputTypeConfigurable<OUT> outputTypeConfigurable = (OutputTypeConfigurable<OUT>) operatorObject;
        // sets the output type which must be know at StreamGraph creation time
        outputTypeConfigurable.setOutputType(outTypeInfo, executionConfig);
    }
    if (operatorObject instanceof InputTypeConfigurable) {
        InputTypeConfigurable inputTypeConfigurable = (InputTypeConfigurable) operatorObject;
        inputTypeConfigurable.setInputType(inTypeInfo, executionConfig);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Vertex: {}", vertexID);
    }
}
Also used : MissingTypeInfo(org.apache.flink.api.java.typeutils.MissingTypeInfo) OutputTypeConfigurable(org.apache.flink.streaming.api.operators.OutputTypeConfigurable) OneInputStreamTask(org.apache.flink.streaming.runtime.tasks.OneInputStreamTask) StoppableStreamSource(org.apache.flink.streaming.api.operators.StoppableStreamSource) StreamSource(org.apache.flink.streaming.api.operators.StreamSource) InputTypeConfigurable(org.apache.flink.api.java.typeutils.InputTypeConfigurable) StoppableSourceStreamTask(org.apache.flink.streaming.runtime.tasks.StoppableSourceStreamTask) SourceStreamTask(org.apache.flink.streaming.runtime.tasks.SourceStreamTask) StoppableStreamSource(org.apache.flink.streaming.api.operators.StoppableStreamSource)

Example 2 with OutputTypeConfigurable

use of org.apache.flink.streaming.api.operators.OutputTypeConfigurable in project flink by apache.

the class WindowTranslationTest method processElementAndEnsureOutput.

/**
 * Ensure that we get some output from the given operator when pushing in an element and setting
 * watermark and processing time to {@code Long.MAX_VALUE}.
 */
private static <K, IN, OUT> void processElementAndEnsureOutput(OneInputStreamOperator<IN, OUT> operator, KeySelector<IN, K> keySelector, TypeInformation<K> keyType, IN element) throws Exception {
    KeyedOneInputStreamOperatorTestHarness<K, IN, OUT> testHarness = new KeyedOneInputStreamOperatorTestHarness<>(operator, keySelector, keyType);
    if (operator instanceof OutputTypeConfigurable) {
        // use a dummy type since window functions just need the ExecutionConfig
        // this is also only needed for Fold, which we're getting rid off soon.
        ((OutputTypeConfigurable) operator).setOutputType(BasicTypeInfo.STRING_TYPE_INFO, new ExecutionConfig());
    }
    testHarness.open();
    testHarness.setProcessingTime(0);
    testHarness.processWatermark(Long.MIN_VALUE);
    testHarness.processElement(new StreamRecord<>(element, 0));
    // provoke any processing-time/event-time triggers
    testHarness.setProcessingTime(Long.MAX_VALUE);
    testHarness.processWatermark(Long.MAX_VALUE);
    // we at least get the two watermarks and should also see an output element
    assertTrue(testHarness.getOutput().size() >= 3);
    testHarness.close();
}
Also used : OutputTypeConfigurable(org.apache.flink.streaming.api.operators.OutputTypeConfigurable) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) KeyedOneInputStreamOperatorTestHarness(org.apache.flink.streaming.util.KeyedOneInputStreamOperatorTestHarness)

Aggregations

OutputTypeConfigurable (org.apache.flink.streaming.api.operators.OutputTypeConfigurable)2 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 InputTypeConfigurable (org.apache.flink.api.java.typeutils.InputTypeConfigurable)1 MissingTypeInfo (org.apache.flink.api.java.typeutils.MissingTypeInfo)1 StoppableStreamSource (org.apache.flink.streaming.api.operators.StoppableStreamSource)1 StreamSource (org.apache.flink.streaming.api.operators.StreamSource)1 OneInputStreamTask (org.apache.flink.streaming.runtime.tasks.OneInputStreamTask)1 SourceStreamTask (org.apache.flink.streaming.runtime.tasks.SourceStreamTask)1 StoppableSourceStreamTask (org.apache.flink.streaming.runtime.tasks.StoppableSourceStreamTask)1 KeyedOneInputStreamOperatorTestHarness (org.apache.flink.streaming.util.KeyedOneInputStreamOperatorTestHarness)1