org.apache.flink.api.common.functions.CombineFunction Java Examples

The following examples show how to use org.apache.flink.api.common.functions.CombineFunction. 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: GroupReduceOperator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private boolean checkCombinability() {
	if (function instanceof GroupCombineFunction || function instanceof CombineFunction) {

		// check if the generic types of GroupCombineFunction and GroupReduceFunction match, i.e.,
		//   GroupCombineFunction<IN, IN> and GroupReduceFunction<IN, OUT>.
		// This is a best effort check. If the check cannot be done, we might fail at runtime.
		Type[] reduceTypes = null;
		Type[] combineTypes = null;

		Type[] genInterfaces = function.getClass().getGenericInterfaces();
		for (Type genInterface : genInterfaces) {
			if (genInterface instanceof ParameterizedType) {
				// get parameters of GroupReduceFunction
				if (((ParameterizedType) genInterface).getRawType().equals(GroupReduceFunction.class)) {
					reduceTypes = ((ParameterizedType) genInterface).getActualTypeArguments();
				// get parameters of GroupCombineFunction
				} else if ((((ParameterizedType) genInterface).getRawType().equals(GroupCombineFunction.class)) ||
					(((ParameterizedType) genInterface).getRawType().equals(CombineFunction.class))) {

					combineTypes = ((ParameterizedType) genInterface).getActualTypeArguments();
				}
			}
		}

		if (reduceTypes != null && reduceTypes.length == 2 &&
			combineTypes != null && combineTypes.length == 2) {

			if (reduceTypes[0].equals(combineTypes[0]) && reduceTypes[0].equals(combineTypes[1])) {
				return true;
			} else {
				LOG.warn("GroupCombineFunction cannot be used as combiner for GroupReduceFunction. " +
					"Generic types are incompatible.");
				return false;
			}
		}
		else if (reduceTypes == null || reduceTypes.length != 2) {
			LOG.warn("Cannot check generic types of GroupReduceFunction. " +
				"Enabling combiner but combine function might fail at runtime.");
			return true;
		}
		else {
			LOG.warn("Cannot check generic types of GroupCombineFunction. " +
				"Enabling combiner but combine function might fail at runtime.");
			return true;
		}
	}
	return false;
}
 
Example #2
Source File: GroupReduceOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
private boolean checkCombinability() {
	if (function instanceof GroupCombineFunction || function instanceof CombineFunction) {

		// check if the generic types of GroupCombineFunction and GroupReduceFunction match, i.e.,
		//   GroupCombineFunction<IN, IN> and GroupReduceFunction<IN, OUT>.
		// This is a best effort check. If the check cannot be done, we might fail at runtime.
		Type[] reduceTypes = null;
		Type[] combineTypes = null;

		Type[] genInterfaces = function.getClass().getGenericInterfaces();
		for (Type genInterface : genInterfaces) {
			if (genInterface instanceof ParameterizedType) {
				// get parameters of GroupReduceFunction
				if (((ParameterizedType) genInterface).getRawType().equals(GroupReduceFunction.class)) {
					reduceTypes = ((ParameterizedType) genInterface).getActualTypeArguments();
				// get parameters of GroupCombineFunction
				} else if ((((ParameterizedType) genInterface).getRawType().equals(GroupCombineFunction.class)) ||
					(((ParameterizedType) genInterface).getRawType().equals(CombineFunction.class))) {

					combineTypes = ((ParameterizedType) genInterface).getActualTypeArguments();
				}
			}
		}

		if (reduceTypes != null && reduceTypes.length == 2 &&
			combineTypes != null && combineTypes.length == 2) {

			if (reduceTypes[0].equals(combineTypes[0]) && reduceTypes[0].equals(combineTypes[1])) {
				return true;
			} else {
				LOG.warn("GroupCombineFunction cannot be used as combiner for GroupReduceFunction. " +
					"Generic types are incompatible.");
				return false;
			}
		}
		else if (reduceTypes == null || reduceTypes.length != 2) {
			LOG.warn("Cannot check generic types of GroupReduceFunction. " +
				"Enabling combiner but combine function might fail at runtime.");
			return true;
		}
		else {
			LOG.warn("Cannot check generic types of GroupCombineFunction. " +
				"Enabling combiner but combine function might fail at runtime.");
			return true;
		}
	}
	return false;
}
 
Example #3
Source File: GroupReduceOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
private boolean checkCombinability() {
	if (function instanceof GroupCombineFunction || function instanceof CombineFunction) {

		// check if the generic types of GroupCombineFunction and GroupReduceFunction match, i.e.,
		//   GroupCombineFunction<IN, IN> and GroupReduceFunction<IN, OUT>.
		// This is a best effort check. If the check cannot be done, we might fail at runtime.
		Type[] reduceTypes = null;
		Type[] combineTypes = null;

		Type[] genInterfaces = function.getClass().getGenericInterfaces();
		for (Type genInterface : genInterfaces) {
			if (genInterface instanceof ParameterizedType) {
				// get parameters of GroupReduceFunction
				if (((ParameterizedType) genInterface).getRawType().equals(GroupReduceFunction.class)) {
					reduceTypes = ((ParameterizedType) genInterface).getActualTypeArguments();
				// get parameters of GroupCombineFunction
				} else if ((((ParameterizedType) genInterface).getRawType().equals(GroupCombineFunction.class)) ||
					(((ParameterizedType) genInterface).getRawType().equals(CombineFunction.class))) {

					combineTypes = ((ParameterizedType) genInterface).getActualTypeArguments();
				}
			}
		}

		if (reduceTypes != null && reduceTypes.length == 2 &&
			combineTypes != null && combineTypes.length == 2) {

			if (reduceTypes[0].equals(combineTypes[0]) && reduceTypes[0].equals(combineTypes[1])) {
				return true;
			} else {
				LOG.warn("GroupCombineFunction cannot be used as combiner for GroupReduceFunction. " +
					"Generic types are incompatible.");
				return false;
			}
		}
		else if (reduceTypes == null || reduceTypes.length != 2) {
			LOG.warn("Cannot check generic types of GroupReduceFunction. " +
				"Enabling combiner but combine function might fail at runtime.");
			return true;
		}
		else {
			LOG.warn("Cannot check generic types of GroupCombineFunction. " +
				"Enabling combiner but combine function might fail at runtime.");
			return true;
		}
	}
	return false;
}