org.apache.flink.api.common.typeutils.CompositeType.InvalidFieldReferenceException Java Examples

The following examples show how to use org.apache.flink.api.common.typeutils.CompositeType.InvalidFieldReferenceException. 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: SemanticPropUtil.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private static boolean areFieldsCompatible(String sourceField, TypeInformation<?> inType, String targetField,
		TypeInformation<?> outType, boolean throwException) {

	try {
		// get source type information
		TypeInformation<?> sourceType = getExpressionTypeInformation(sourceField, inType);
		// get target type information
		TypeInformation<?> targetType = getExpressionTypeInformation(targetField, outType);
		return sourceType.equals(targetType);
	} catch (InvalidFieldReferenceException e) {
		if (throwException) {
			throw e;
		} else {
			return false;
		}
	}
}
 
Example #2
Source File: SemanticPropUtil.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private static TypeInformation<?> getExpressionTypeInformation(String fieldStr, TypeInformation<?> typeInfo) {
	Matcher wildcardMatcher = PATTERN_WILDCARD.matcher(fieldStr);
	if (wildcardMatcher.matches()) {
		return typeInfo;
	} else {
		Matcher expMatcher = PATTERN_FIELD.matcher(fieldStr);
		if (!expMatcher.matches()) {
			throw new InvalidFieldReferenceException("Invalid field expression \"" + fieldStr + "\".");
		}
		if (typeInfo instanceof CompositeType<?>) {
			return ((CompositeType<?>) typeInfo).getTypeAt(expMatcher.group(1));
		} else {
			throw new InvalidFieldReferenceException("Nested field expression \"" + fieldStr + "\" not possible on atomic type (" + typeInfo + ").");
		}
	}
}
 
Example #3
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
private static boolean areFieldsCompatible(String sourceField, TypeInformation<?> inType, String targetField,
		TypeInformation<?> outType, boolean throwException) {

	try {
		// get source type information
		TypeInformation<?> sourceType = getExpressionTypeInformation(sourceField, inType);
		// get target type information
		TypeInformation<?> targetType = getExpressionTypeInformation(targetField, outType);
		return sourceType.equals(targetType);
	} catch (InvalidFieldReferenceException e) {
		if (throwException) {
			throw e;
		} else {
			return false;
		}
	}
}
 
Example #4
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
private static TypeInformation<?> getExpressionTypeInformation(String fieldStr, TypeInformation<?> typeInfo) {
	Matcher wildcardMatcher = PATTERN_WILDCARD.matcher(fieldStr);
	if (wildcardMatcher.matches()) {
		return typeInfo;
	} else {
		Matcher expMatcher = PATTERN_FIELD.matcher(fieldStr);
		if (!expMatcher.matches()) {
			throw new InvalidFieldReferenceException("Invalid field expression \"" + fieldStr + "\".");
		}
		if (typeInfo instanceof CompositeType<?>) {
			return ((CompositeType<?>) typeInfo).getTypeAt(expMatcher.group(1));
		} else {
			throw new InvalidFieldReferenceException("Nested field expression \"" + fieldStr + "\" not possible on atomic type (" + typeInfo + ").");
		}
	}
}
 
Example #5
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
private static boolean areFieldsCompatible(String sourceField, TypeInformation<?> inType, String targetField,
		TypeInformation<?> outType, boolean throwException) {

	try {
		// get source type information
		TypeInformation<?> sourceType = getExpressionTypeInformation(sourceField, inType);
		// get target type information
		TypeInformation<?> targetType = getExpressionTypeInformation(targetField, outType);
		return sourceType.equals(targetType);
	} catch (InvalidFieldReferenceException e) {
		if (throwException) {
			throw e;
		} else {
			return false;
		}
	}
}
 
Example #6
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
private static TypeInformation<?> getExpressionTypeInformation(String fieldStr, TypeInformation<?> typeInfo) {
	Matcher wildcardMatcher = PATTERN_WILDCARD.matcher(fieldStr);
	if (wildcardMatcher.matches()) {
		return typeInfo;
	} else {
		Matcher expMatcher = PATTERN_FIELD.matcher(fieldStr);
		if (!expMatcher.matches()) {
			throw new InvalidFieldReferenceException("Invalid field expression \"" + fieldStr + "\".");
		}
		if (typeInfo instanceof CompositeType<?>) {
			return ((CompositeType<?>) typeInfo).getTypeAt(expMatcher.group(1));
		} else {
			throw new InvalidFieldReferenceException("Nested field expression \"" + fieldStr + "\" not possible on atomic type (" + typeInfo + ").");
		}
	}
}
 
Example #7
Source File: SemanticPropUtil.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static List<FlatFieldDescriptor> getFlatFields(String fieldStr, TypeInformation<?> typeInfo) {
	if (typeInfo instanceof CompositeType<?>) {
		return ((CompositeType<?>) typeInfo).getFlatFields(fieldStr);
	} else {
		Matcher wildcardMatcher = PATTERN_WILDCARD.matcher(fieldStr);
		if (wildcardMatcher.matches()) {
			return Collections.singletonList(new FlatFieldDescriptor(0, typeInfo));
		} else {
			throw new InvalidFieldReferenceException("Nested field expression \"" + fieldStr + "\" not possible on atomic type (" + typeInfo + ").");
		}
	}
}
 
Example #8
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 5 votes vote down vote up
private static List<FlatFieldDescriptor> getFlatFields(String fieldStr, TypeInformation<?> typeInfo) {
	if (typeInfo instanceof CompositeType<?>) {
		return ((CompositeType<?>) typeInfo).getFlatFields(fieldStr);
	} else {
		Matcher wildcardMatcher = PATTERN_WILDCARD.matcher(fieldStr);
		if (wildcardMatcher.matches()) {
			return Collections.singletonList(new FlatFieldDescriptor(0, typeInfo));
		} else {
			throw new InvalidFieldReferenceException("Nested field expression \"" + fieldStr + "\" not possible on atomic type (" + typeInfo + ").");
		}
	}
}
 
Example #9
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 5 votes vote down vote up
private static List<FlatFieldDescriptor> getFlatFields(String fieldStr, TypeInformation<?> typeInfo) {
	if (typeInfo instanceof CompositeType<?>) {
		return ((CompositeType<?>) typeInfo).getFlatFields(fieldStr);
	} else {
		Matcher wildcardMatcher = PATTERN_WILDCARD.matcher(fieldStr);
		if (wildcardMatcher.matches()) {
			return Collections.singletonList(new FlatFieldDescriptor(0, typeInfo));
		} else {
			throw new InvalidFieldReferenceException("Nested field expression \"" + fieldStr + "\" not possible on atomic type (" + typeInfo + ").");
		}
	}
}
 
Example #10
Source File: SemanticPropUtil.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private static void parseNonForwardedFields(SemanticProperties sp, String[] nonForwardedStr,
		TypeInformation<?> inType, TypeInformation<?> outType, int input, boolean skipIncompatibleTypes) {

	if (nonForwardedStr == null) {
		return;
	}

	FieldSet excludedFields = new FieldSet();
	for (String s : nonForwardedStr) {

		// remove white characters
		s = s.replaceAll("\\s", "");

		if (s.equals("")) {
			continue;
		}

		if (!inType.equals(outType)) {
			if (skipIncompatibleTypes) {
				continue;
			} else {
				throw new InvalidSemanticAnnotationException("Non-forwarded fields annotation only allowed for identical input and output types.");
			}
		}

		Matcher matcher = PATTERN_LIST.matcher(s);
		if (!matcher.matches()) {
			throw new InvalidSemanticAnnotationException("Invalid format of non-forwarded fields annotation \"" + s + "\".");
		}

		// process individual fields
		matcher = PATTERN_FIELD.matcher(s);
		while (matcher.find()) {
			String fieldStr = matcher.group();

			try {
				// get and add all flat field positions
				List<FlatFieldDescriptor> inFFDs = getFlatFields(fieldStr, inType);
				for (FlatFieldDescriptor ffd : inFFDs) {
					excludedFields = excludedFields.addField(ffd.getPosition());
				}
			} catch (InvalidFieldReferenceException ifre) {
				throw new InvalidSemanticAnnotationException("Invalid field reference in non-forwarded fields annotation \"" + fieldStr + "\".", ifre);
			}
		}
	}

	for (int i = 0; i < inType.getTotalFields(); i++) {
		if (!excludedFields.contains(i)) {
			if (sp instanceof SingleInputSemanticProperties) {
				((SingleInputSemanticProperties) sp).addForwardedField(i, i);
			} else if (sp instanceof DualInputSemanticProperties) {
				((DualInputSemanticProperties) sp).addForwardedField(input, i, i);
			}
		}
	}

}
 
Example #11
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
private static void parseNonForwardedFields(SemanticProperties sp, String[] nonForwardedStr,
		TypeInformation<?> inType, TypeInformation<?> outType, int input, boolean skipIncompatibleTypes) {

	if (nonForwardedStr == null) {
		return;
	}

	FieldSet excludedFields = new FieldSet();
	for (String s : nonForwardedStr) {

		// remove white characters
		s = s.replaceAll("\\s", "");

		if (s.equals("")) {
			continue;
		}

		if (!inType.equals(outType)) {
			if (skipIncompatibleTypes) {
				continue;
			} else {
				throw new InvalidSemanticAnnotationException("Non-forwarded fields annotation only allowed for identical input and output types.");
			}
		}

		Matcher matcher = PATTERN_LIST.matcher(s);
		if (!matcher.matches()) {
			throw new InvalidSemanticAnnotationException("Invalid format of non-forwarded fields annotation \"" + s + "\".");
		}

		// process individual fields
		matcher = PATTERN_FIELD.matcher(s);
		while (matcher.find()) {
			String fieldStr = matcher.group();

			try {
				// get and add all flat field positions
				List<FlatFieldDescriptor> inFFDs = getFlatFields(fieldStr, inType);
				for (FlatFieldDescriptor ffd : inFFDs) {
					excludedFields = excludedFields.addField(ffd.getPosition());
				}
			} catch (InvalidFieldReferenceException ifre) {
				throw new InvalidSemanticAnnotationException("Invalid field reference in non-forwarded fields annotation \"" + fieldStr + "\".", ifre);
			}
		}
	}

	for (int i = 0; i < inType.getTotalFields(); i++) {
		if (!excludedFields.contains(i)) {
			if (sp instanceof SingleInputSemanticProperties) {
				((SingleInputSemanticProperties) sp).addForwardedField(i, i);
			} else if (sp instanceof DualInputSemanticProperties) {
				((DualInputSemanticProperties) sp).addForwardedField(input, i, i);
			}
		}
	}

}
 
Example #12
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
private static void parseNonForwardedFields(SemanticProperties sp, String[] nonForwardedStr,
		TypeInformation<?> inType, TypeInformation<?> outType, int input, boolean skipIncompatibleTypes) {

	if (nonForwardedStr == null) {
		return;
	}

	FieldSet excludedFields = new FieldSet();
	for (String s : nonForwardedStr) {

		// remove white characters
		s = s.replaceAll("\\s", "");

		if (s.equals("")) {
			continue;
		}

		if (!inType.equals(outType)) {
			if (skipIncompatibleTypes) {
				continue;
			} else {
				throw new InvalidSemanticAnnotationException("Non-forwarded fields annotation only allowed for identical input and output types.");
			}
		}

		Matcher matcher = PATTERN_LIST.matcher(s);
		if (!matcher.matches()) {
			throw new InvalidSemanticAnnotationException("Invalid format of non-forwarded fields annotation \"" + s + "\".");
		}

		// process individual fields
		matcher = PATTERN_FIELD.matcher(s);
		while (matcher.find()) {
			String fieldStr = matcher.group();

			try {
				// get and add all flat field positions
				List<FlatFieldDescriptor> inFFDs = getFlatFields(fieldStr, inType);
				for (FlatFieldDescriptor ffd : inFFDs) {
					excludedFields = excludedFields.addField(ffd.getPosition());
				}
			} catch (InvalidFieldReferenceException ifre) {
				throw new InvalidSemanticAnnotationException("Invalid field reference in non-forwarded fields annotation \"" + fieldStr + "\".", ifre);
			}
		}
	}

	for (int i = 0; i < inType.getTotalFields(); i++) {
		if (!excludedFields.contains(i)) {
			if (sp instanceof SingleInputSemanticProperties) {
				((SingleInputSemanticProperties) sp).addForwardedField(i, i);
			} else if (sp instanceof DualInputSemanticProperties) {
				((DualInputSemanticProperties) sp).addForwardedField(input, i, i);
			}
		}
	}

}