Search in sources :

Example 6 with FlatFieldDescriptor

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);
            }
        }
    }
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) Matcher(java.util.regex.Matcher) InvalidSemanticAnnotationException(org.apache.flink.api.common.operators.SemanticProperties.InvalidSemanticAnnotationException) SingleInputSemanticProperties(org.apache.flink.api.common.operators.SingleInputSemanticProperties) DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties) FlatFieldDescriptor(org.apache.flink.api.common.typeutils.CompositeType.FlatFieldDescriptor) InvalidFieldReferenceException(org.apache.flink.api.common.typeutils.CompositeType.InvalidFieldReferenceException)

Aggregations

FlatFieldDescriptor (org.apache.flink.api.common.typeutils.CompositeType.FlatFieldDescriptor)6 ArrayList (java.util.ArrayList)3 Matcher (java.util.regex.Matcher)3 DualInputSemanticProperties (org.apache.flink.api.common.operators.DualInputSemanticProperties)3 InvalidSemanticAnnotationException (org.apache.flink.api.common.operators.SemanticProperties.InvalidSemanticAnnotationException)3 SingleInputSemanticProperties (org.apache.flink.api.common.operators.SingleInputSemanticProperties)3 InvalidFieldReferenceException (org.apache.flink.api.common.typeutils.CompositeType.InvalidFieldReferenceException)3 FieldSet (org.apache.flink.api.common.operators.util.FieldSet)2 BasicTypeInfo (org.apache.flink.api.common.typeinfo.BasicTypeInfo)2 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)2 Test (org.junit.Test)2 BigInteger (java.math.BigInteger)1 Date (java.util.Date)1 List (java.util.List)1 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 InvalidTypesException (org.apache.flink.api.common.functions.InvalidTypesException)1 RichMapFunction (org.apache.flink.api.common.functions.RichMapFunction)1 ExpressionKeys (org.apache.flink.api.common.operators.Keys.ExpressionKeys)1 IncompatibleKeysException (org.apache.flink.api.common.operators.Keys.IncompatibleKeysException)1 TypeHint (org.apache.flink.api.common.typeinfo.TypeHint)1