use of org.apache.flink.api.common.typeutils.CompositeType.FlatFieldDescriptor in project flink by apache.
the class SemanticPropUtil method parseNonForwardedFields.
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);
}
}
}
}
Aggregations