org.apache.flink.api.java.typeutils.MissingTypeInfo Java Examples

The following examples show how to use org.apache.flink.api.java.typeutils.MissingTypeInfo. 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: StreamTransformation.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the output type of this {@code StreamTransformation} as a {@link TypeInformation}. Once
 * this is used once the output type cannot be changed anymore using {@link #setOutputType}.
 *
 * @return The output type of this {@code StreamTransformation}
 */
public TypeInformation<T> getOutputType() {
	if (outputType instanceof MissingTypeInfo) {
		MissingTypeInfo typeInfo = (MissingTypeInfo) this.outputType;
		throw new InvalidTypesException(
				"The return type of function '"
						+ typeInfo.getFunctionName()
						+ "' could not be determined automatically, due to type erasure. "
						+ "You can give type information hints by using the returns(...) "
						+ "method on the result of the transformation call, or by letting "
						+ "your function implement the 'ResultTypeQueryable' "
						+ "interface.", typeInfo.getTypeException());
	}
	typeUsed = true;
	return this.outputType;
}
 
Example #2
Source File: Transformation.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the output type of this {@code Transformation} as a {@link TypeInformation}. Once
 * this is used once the output type cannot be changed anymore using {@link #setOutputType}.
 *
 * @return The output type of this {@code Transformation}
 */
public TypeInformation<T> getOutputType() {
	if (outputType instanceof MissingTypeInfo) {
		MissingTypeInfo typeInfo = (MissingTypeInfo) this.outputType;
		throw new InvalidTypesException(
				"The return type of function '"
						+ typeInfo.getFunctionName()
						+ "' could not be determined automatically, due to type erasure. "
						+ "You can give type information hints by using the returns(...) "
						+ "method on the result of the transformation call, or by letting "
						+ "your function implement the 'ResultTypeQueryable' "
						+ "interface.", typeInfo.getTypeException());
	}
	typeUsed = true;
	return this.outputType;
}
 
Example #3
Source File: StreamExecutionEnvironment.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * 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 (function instanceof ResultTypeQueryable) {
		typeInfo = ((ResultTypeQueryable<OUT>) function).getProducedType();
	}
	if (typeInfo == null) {
		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);

	final StreamSource<OUT, ?> sourceOperator = new StreamSource<>(function);
	return new DataStreamSource<>(this, typeInfo, sourceOperator, isParallel, sourceName);
}
 
Example #4
Source File: Transformation.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the output type of this {@code Transformation} as a {@link TypeInformation}. Once
 * this is used once the output type cannot be changed anymore using {@link #setOutputType}.
 *
 * @return The output type of this {@code Transformation}
 */
public TypeInformation<T> getOutputType() {
	if (outputType instanceof MissingTypeInfo) {
		MissingTypeInfo typeInfo = (MissingTypeInfo) this.outputType;
		throw new InvalidTypesException(
				"The return type of function '"
						+ typeInfo.getFunctionName()
						+ "' could not be determined automatically, due to type erasure. "
						+ "You can give type information hints by using the returns(...) "
						+ "method on the result of the transformation call, or by letting "
						+ "your function implement the 'ResultTypeQueryable' "
						+ "interface.", typeInfo.getTypeException());
	}
	typeUsed = true;
	return this.outputType;
}
 
Example #5
Source File: StreamExecutionEnvironment.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private <OUT, T extends TypeInformation<OUT>> T getTypeInfo(
		Object source,
		String sourceName,
		Class<?> baseSourceClass,
		TypeInformation<OUT> typeInfo) {
	TypeInformation<OUT> resolvedTypeInfo = typeInfo;
	if (source instanceof ResultTypeQueryable) {
		resolvedTypeInfo = ((ResultTypeQueryable<OUT>) source).getProducedType();
	}
	if (resolvedTypeInfo == null) {
		try {
			resolvedTypeInfo = TypeExtractor.createTypeInfo(
					baseSourceClass,
					source.getClass(), 0, null, null);
		} catch (final InvalidTypesException e) {
			resolvedTypeInfo = (TypeInformation<OUT>) new MissingTypeInfo(sourceName, e);
		}
	}
	return (T) resolvedTypeInfo;
}
 
Example #6
Source File: DataSet.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the {@link TypeInformation} for the type of this DataSet.
 *
 * @return The TypeInformation for the type of this DataSet.
 *
 * @see TypeInformation
 */
public TypeInformation<T> getType() {
	if (type instanceof MissingTypeInfo) {
		MissingTypeInfo typeInfo = (MissingTypeInfo) type;
		throw new InvalidTypesException("The return type of function '" + typeInfo.getFunctionName()
				+ "' could not be determined automatically, due to type erasure. "
				+ "You can give type information hints by using the returns(...) method on the result of "
				+ "the transformation call, or by letting your function implement the 'ResultTypeQueryable' "
				+ "interface.", typeInfo.getTypeException());
	}
	typeUsed = true;
	return this.type;
}
 
Example #7
Source File: StreamExecutionEnvironment.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #8
Source File: StreamGraph.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public <IN, OUT> void addOperator(
		Integer vertexID,
		String slotSharingGroup,
		@Nullable String coLocationGroup,
		StreamOperator<OUT> operatorObject,
		TypeInformation<IN> inTypeInfo,
		TypeInformation<OUT> outTypeInfo,
		String operatorName) {

	if (operatorObject instanceof StoppableStreamSource) {
		addNode(vertexID, slotSharingGroup, coLocationGroup, StoppableSourceStreamTask.class, operatorObject, operatorName);
	} else if (operatorObject instanceof StreamSource) {
		addNode(vertexID, slotSharingGroup, coLocationGroup, SourceStreamTask.class, operatorObject, operatorName);
	} else {
		addNode(vertexID, slotSharingGroup, coLocationGroup, 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);
	}
}
 
Example #9
Source File: StreamGraph.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public <IN1, IN2, OUT> void addCoOperator(
		Integer vertexID,
		String slotSharingGroup,
		@Nullable String coLocationGroup,
		TwoInputStreamOperator<IN1, IN2, OUT> taskOperatorObject,
		TypeInformation<IN1> in1TypeInfo,
		TypeInformation<IN2> in2TypeInfo,
		TypeInformation<OUT> outTypeInfo,
		String operatorName) {

	addNode(vertexID, slotSharingGroup, coLocationGroup, TwoInputStreamTask.class, taskOperatorObject, operatorName);

	TypeSerializer<OUT> outSerializer = (outTypeInfo != null) && !(outTypeInfo instanceof MissingTypeInfo) ?
			outTypeInfo.createSerializer(executionConfig) : null;

	setSerializers(vertexID, in1TypeInfo.createSerializer(executionConfig), in2TypeInfo.createSerializer(executionConfig), outSerializer);

	if (taskOperatorObject instanceof OutputTypeConfigurable) {
		@SuppressWarnings("unchecked")
		OutputTypeConfigurable<OUT> outputTypeConfigurable = (OutputTypeConfigurable<OUT>) taskOperatorObject;
		// sets the output type which must be know at StreamGraph creation time
		outputTypeConfigurable.setOutputType(outTypeInfo, executionConfig);
	}

	if (LOG.isDebugEnabled()) {
		LOG.debug("CO-TASK: {}", vertexID);
	}
}
 
Example #10
Source File: DataSet.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the {@link TypeInformation} for the type of this DataSet.
 *
 * @return The TypeInformation for the type of this DataSet.
 *
 * @see TypeInformation
 */
public TypeInformation<T> getType() {
	if (type instanceof MissingTypeInfo) {
		MissingTypeInfo typeInfo = (MissingTypeInfo) type;
		throw new InvalidTypesException("The return type of function '" + typeInfo.getFunctionName()
				+ "' could not be determined automatically, due to type erasure. "
				+ "You can give type information hints by using the returns(...) method on the result of "
				+ "the transformation call, or by letting your function implement the 'ResultTypeQueryable' "
				+ "interface.", typeInfo.getTypeException());
	}
	typeUsed = true;
	return this.type;
}
 
Example #11
Source File: StreamGraph.java    From flink with Apache License 2.0 5 votes vote down vote up
public <IN, OUT> void addOperator(
		Integer vertexID,
		@Nullable String slotSharingGroup,
		@Nullable String coLocationGroup,
		StreamOperatorFactory<OUT> operatorFactory,
		TypeInformation<IN> inTypeInfo,
		TypeInformation<OUT> outTypeInfo,
		String operatorName) {

	if (operatorFactory.isStreamSource()) {
		addNode(vertexID, slotSharingGroup, coLocationGroup, SourceStreamTask.class, operatorFactory, operatorName);
	} else {
		addNode(vertexID, slotSharingGroup, coLocationGroup, OneInputStreamTask.class, operatorFactory, 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 (operatorFactory.isOutputTypeConfigurable() && outTypeInfo != null) {
		// sets the output type which must be know at StreamGraph creation time
		operatorFactory.setOutputType(outTypeInfo, executionConfig);
	}

	if (operatorFactory.isInputTypeConfigurable()) {
		operatorFactory.setInputType(inTypeInfo, executionConfig);
	}

	if (LOG.isDebugEnabled()) {
		LOG.debug("Vertex: {}", vertexID);
	}
}
 
Example #12
Source File: StreamGraph.java    From flink with Apache License 2.0 5 votes vote down vote up
public <IN1, IN2, OUT> void addCoOperator(
		Integer vertexID,
		String slotSharingGroup,
		@Nullable String coLocationGroup,
		StreamOperatorFactory<OUT> taskOperatorFactory,
		TypeInformation<IN1> in1TypeInfo,
		TypeInformation<IN2> in2TypeInfo,
		TypeInformation<OUT> outTypeInfo,
		String operatorName) {

	Class<? extends AbstractInvokable> vertexClass = taskOperatorFactory.isOperatorSelectiveReading() ?
		TwoInputSelectableStreamTask.class : TwoInputStreamTask.class;

	addNode(vertexID, slotSharingGroup, coLocationGroup, vertexClass, taskOperatorFactory, operatorName);

	TypeSerializer<OUT> outSerializer = (outTypeInfo != null) && !(outTypeInfo instanceof MissingTypeInfo) ?
			outTypeInfo.createSerializer(executionConfig) : null;

	setSerializers(vertexID, in1TypeInfo.createSerializer(executionConfig), in2TypeInfo.createSerializer(executionConfig), outSerializer);

	if (taskOperatorFactory.isOutputTypeConfigurable()) {
		// sets the output type which must be know at StreamGraph creation time
		taskOperatorFactory.setOutputType(outTypeInfo, executionConfig);
	}

	if (LOG.isDebugEnabled()) {
		LOG.debug("CO-TASK: {}", vertexID);
	}
}
 
Example #13
Source File: DataSet.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the {@link TypeInformation} for the type of this DataSet.
 *
 * @return The TypeInformation for the type of this DataSet.
 *
 * @see TypeInformation
 */
public TypeInformation<T> getType() {
	if (type instanceof MissingTypeInfo) {
		MissingTypeInfo typeInfo = (MissingTypeInfo) type;
		throw new InvalidTypesException("The return type of function '" + typeInfo.getFunctionName()
				+ "' could not be determined automatically, due to type erasure. "
				+ "You can give type information hints by using the returns(...) method on the result of "
				+ "the transformation call, or by letting your function implement the 'ResultTypeQueryable' "
				+ "interface.", typeInfo.getTypeException());
	}
	typeUsed = true;
	return this.type;
}
 
Example #14
Source File: StreamGraph.java    From flink with Apache License 2.0 4 votes vote down vote up
private <T> TypeSerializer<T> createSerializer(TypeInformation<T> typeInfo) {
	return typeInfo != null && !(typeInfo instanceof MissingTypeInfo) ?
		typeInfo.createSerializer(executionConfig) : null;
}