Java Code Examples for org.apache.flink.api.common.operators.util.FieldSet#addField()

The following examples show how to use org.apache.flink.api.common.operators.util.FieldSet#addField() . 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
/**
 * Creates SemanticProperties by adding an offset to each input field index of the given SemanticProperties.
 *
 * @param props The SemanticProperties to which the offset is added.
 * @param numInputFields The original number of fields of the input.
 * @param offset The offset that is added to each input field index.
 * @return New SemanticProperties with added offset.
 */
public static SingleInputSemanticProperties addSourceFieldOffset(SingleInputSemanticProperties props,
																	int numInputFields, int offset) {

	SingleInputSemanticProperties offsetProps = new SingleInputSemanticProperties();
	if (props.getReadFields(0) != null) {
		FieldSet offsetReadFields = new FieldSet();
		for (int r : props.getReadFields(0)) {
			offsetReadFields = offsetReadFields.addField(r + offset);
		}
		offsetProps.addReadFields(offsetReadFields);
	}
	for (int s = 0; s < numInputFields; s++) {
		FieldSet targetFields = props.getForwardingTargetFields(0, s);
		for (int t : targetFields) {
			offsetProps.addForwardedField(s + offset, t);
		}
	}
	return offsetProps;
}
 
Example 2
Source File: FieldSetTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testImmutability() {
	FieldSet s1 = new FieldSet();
	FieldSet s2 = new FieldSet(5);
	FieldSet s3 = new FieldSet(Integer.valueOf(7));
	FieldSet s4 = new FieldSet(5, 4, 7, 6);
	
	s1.addFields(s2).addFields(s3);
	s2.addFields(s4);
	s4.addFields(s1);
	
	s1.addField(Integer.valueOf(14));
	s2.addFields(78, 13, 66, 3);
	
	assertEquals(0, s1.size());
	assertEquals(1, s2.size());
	assertEquals(1, s3.size());
	assertEquals(4, s4.size());
}
 
Example 3
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates SemanticProperties by adding an offset to each input field index of the given SemanticProperties.
 *
 * @param props The SemanticProperties to which the offset is added.
 * @param numInputFields The original number of fields of the input.
 * @param offset The offset that is added to each input field index.
 * @return New SemanticProperties with added offset.
 */
public static SingleInputSemanticProperties addSourceFieldOffset(SingleInputSemanticProperties props,
																	int numInputFields, int offset) {

	SingleInputSemanticProperties offsetProps = new SingleInputSemanticProperties();
	if (props.getReadFields(0) != null) {
		FieldSet offsetReadFields = new FieldSet();
		for (int r : props.getReadFields(0)) {
			offsetReadFields = offsetReadFields.addField(r + offset);
		}
		offsetProps.addReadFields(offsetReadFields);
	}
	for (int s = 0; s < numInputFields; s++) {
		FieldSet targetFields = props.getForwardingTargetFields(0, s);
		for (int t : targetFields) {
			offsetProps.addForwardedField(s + offset, t);
		}
	}
	return offsetProps;
}
 
Example 4
Source File: FieldSetTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testImmutability() {
	FieldSet s1 = new FieldSet();
	FieldSet s2 = new FieldSet(5);
	FieldSet s3 = new FieldSet(Integer.valueOf(7));
	FieldSet s4 = new FieldSet(5, 4, 7, 6);
	
	s1.addFields(s2).addFields(s3);
	s2.addFields(s4);
	s4.addFields(s1);
	
	s1.addField(Integer.valueOf(14));
	s2.addFields(78, 13, 66, 3);
	
	assertEquals(0, s1.size());
	assertEquals(1, s2.size());
	assertEquals(1, s3.size());
	assertEquals(4, s4.size());
}
 
Example 5
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates SemanticProperties by adding an offset to each input field index of the given SemanticProperties.
 *
 * @param props The SemanticProperties to which the offset is added.
 * @param numInputFields The original number of fields of the input.
 * @param offset The offset that is added to each input field index.
 * @return New SemanticProperties with added offset.
 */
public static SingleInputSemanticProperties addSourceFieldOffset(SingleInputSemanticProperties props,
																	int numInputFields, int offset) {

	SingleInputSemanticProperties offsetProps = new SingleInputSemanticProperties();
	if (props.getReadFields(0) != null) {
		FieldSet offsetReadFields = new FieldSet();
		for (int r : props.getReadFields(0)) {
			offsetReadFields = offsetReadFields.addField(r + offset);
		}
		offsetProps.addReadFields(offsetReadFields);
	}
	for (int s = 0; s < numInputFields; s++) {
		FieldSet targetFields = props.getForwardingTargetFields(0, s);
		for (int t : targetFields) {
			offsetProps.addForwardedField(s + offset, t);
		}
	}
	return offsetProps;
}
 
Example 6
Source File: FieldSetTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testImmutability() {
	FieldSet s1 = new FieldSet();
	FieldSet s2 = new FieldSet(5);
	FieldSet s3 = new FieldSet(Integer.valueOf(7));
	FieldSet s4 = new FieldSet(5, 4, 7, 6);
	
	s1.addFields(s2).addFields(s3);
	s2.addFields(s4);
	s4.addFields(s1);
	
	s1.addField(Integer.valueOf(14));
	s2.addFields(78, 13, 66, 3);
	
	assertEquals(0, s1.size());
	assertEquals(1, s2.size());
	assertEquals(1, s3.size());
	assertEquals(4, s4.size());
}
 
Example 7
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 8
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 9
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);
			}
		}
	}

}