Search in sources :

Example 1 with MissingTypeInfo

use of org.apache.flink.api.java.typeutils.MissingTypeInfo in project flink by apache.

the class StreamExecutionEnvironment method addSource.

/**
	 * Ads a data source with a custom type information thus opening a
	 * {@link DataStream}. Only in very special cases does the user need to
	 * support type information. Otherwise use
	 * {@link #addSource(org.apache.flink.streaming.api.functions.source.SourceFunction)}
	 *
	 * @param function
	 * 		the user defined function
	 * @param sourceName
	 * 		Name of the data source
	 * @param <OUT>
	 * 		type of the returned stream
	 * @param typeInfo
	 * 		the user defined type information for the stream
	 * @return the data stream constructed
	 */
@SuppressWarnings("unchecked")
public <OUT> DataStreamSource<OUT> addSource(SourceFunction<OUT> function, String sourceName, TypeInformation<OUT> typeInfo) {
    if (typeInfo == null) {
        if (function instanceof ResultTypeQueryable) {
            typeInfo = ((ResultTypeQueryable<OUT>) function).getProducedType();
        } else {
            try {
                typeInfo = TypeExtractor.createTypeInfo(SourceFunction.class, function.getClass(), 0, null, null);
            } catch (final InvalidTypesException e) {
                typeInfo = (TypeInformation<OUT>) new MissingTypeInfo(sourceName, e);
            }
        }
    }
    boolean isParallel = function instanceof ParallelSourceFunction;
    clean(function);
    StreamSource<OUT, ?> sourceOperator;
    if (function instanceof StoppableFunction) {
        sourceOperator = new StoppableStreamSource<>(cast2StoppableSourceFunction(function));
    } else {
        sourceOperator = new StreamSource<>(function);
    }
    return new DataStreamSource<>(this, typeInfo, sourceOperator, isParallel, sourceName);
}
Also used : ParallelSourceFunction(org.apache.flink.streaming.api.functions.source.ParallelSourceFunction) SourceFunction(org.apache.flink.streaming.api.functions.source.SourceFunction) InputFormatSourceFunction(org.apache.flink.streaming.api.functions.source.InputFormatSourceFunction) MissingTypeInfo(org.apache.flink.api.java.typeutils.MissingTypeInfo) ResultTypeQueryable(org.apache.flink.api.java.typeutils.ResultTypeQueryable) DataStreamSource(org.apache.flink.streaming.api.datastream.DataStreamSource) StoppableFunction(org.apache.flink.api.common.functions.StoppableFunction) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) ParallelSourceFunction(org.apache.flink.streaming.api.functions.source.ParallelSourceFunction) InvalidTypesException(org.apache.flink.api.common.functions.InvalidTypesException)

Example 2 with MissingTypeInfo

use of org.apache.flink.api.java.typeutils.MissingTypeInfo 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)

Aggregations

MissingTypeInfo (org.apache.flink.api.java.typeutils.MissingTypeInfo)2 InvalidTypesException (org.apache.flink.api.common.functions.InvalidTypesException)1 StoppableFunction (org.apache.flink.api.common.functions.StoppableFunction)1 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)1 InputTypeConfigurable (org.apache.flink.api.java.typeutils.InputTypeConfigurable)1 ResultTypeQueryable (org.apache.flink.api.java.typeutils.ResultTypeQueryable)1 DataStreamSource (org.apache.flink.streaming.api.datastream.DataStreamSource)1 InputFormatSourceFunction (org.apache.flink.streaming.api.functions.source.InputFormatSourceFunction)1 ParallelSourceFunction (org.apache.flink.streaming.api.functions.source.ParallelSourceFunction)1 SourceFunction (org.apache.flink.streaming.api.functions.source.SourceFunction)1 OutputTypeConfigurable (org.apache.flink.streaming.api.operators.OutputTypeConfigurable)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