Java Code Examples for org.apache.flink.api.common.operators.DualInputSemanticProperties#addForwardedField()

The following examples show how to use org.apache.flink.api.common.operators.DualInputSemanticProperties#addForwardedField() . 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 4 votes vote down vote up
public static DualInputSemanticProperties createProjectionPropertiesDual(
	int[] fields, boolean[] isFromFirst, TypeInformation<?> inType1, TypeInformation<?> inType2) {
	DualInputSemanticProperties dsp = new DualInputSemanticProperties();

	int[] sourceOffsets1;
	if (inType1 instanceof TupleTypeInfo<?>) {
		sourceOffsets1 = new int[inType1.getArity()];
		sourceOffsets1[0] = 0;
		for (int i = 1; i < inType1.getArity(); i++) {
			sourceOffsets1[i] = ((TupleTypeInfo<?>) inType1).getTypeAt(i - 1).getTotalFields() + sourceOffsets1[i - 1];
		}
	} else {
		sourceOffsets1 = new int[]{0};
	}

	int[] sourceOffsets2;
	if (inType2 instanceof TupleTypeInfo<?>) {
		sourceOffsets2 = new int[inType2.getArity()];
		sourceOffsets2[0] = 0;
		for (int i = 1; i < inType2.getArity(); i++) {
			sourceOffsets2[i] = ((TupleTypeInfo<?>) inType2).getTypeAt(i - 1).getTotalFields() + sourceOffsets2[i - 1];
		}
	} else {
		sourceOffsets2 = new int[]{0};
	}

	int targetOffset = 0;
	for (int i = 0; i < fields.length; i++) {
		int sourceOffset;
		int numFieldsToCopy;
		int input;
		if (isFromFirst[i]) {
			input = 0;
			if (fields[i] == -1) {
				sourceOffset = 0;
				numFieldsToCopy = inType1.getTotalFields();
			} else {
				sourceOffset = sourceOffsets1[fields[i]];
				numFieldsToCopy = ((TupleTypeInfo<?>) inType1).getTypeAt(fields[i]).getTotalFields();
			}
		} else {
			input = 1;
			if (fields[i] == -1) {
				sourceOffset = 0;
				numFieldsToCopy = inType2.getTotalFields();
			} else {
				sourceOffset = sourceOffsets2[fields[i]];
				numFieldsToCopy = ((TupleTypeInfo<?>) inType2).getTypeAt(fields[i]).getTotalFields();
			}
		}

		for (int j = 0; j < numFieldsToCopy; j++) {
			dsp.addForwardedField(input, sourceOffset + j, targetOffset + j);
		}
		targetOffset += numFieldsToCopy;
	}

	return dsp;
}
 
Example 2
Source File: CoGroupNodeTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetSemanticProperties() {

	DualInputSemanticProperties origProps = new DualInputSemanticProperties();
	// props for first input
	origProps.addForwardedField(0, 0, 1);
	origProps.addForwardedField(0, 2, 2);
	origProps.addForwardedField(0, 3, 4);
	origProps.addForwardedField(0, 6, 0);
	origProps.addReadFields(0, new FieldSet(0, 2, 4, 7));
	// props for second input
	origProps.addForwardedField(1, 1, 2);
	origProps.addForwardedField(1, 2, 8);
	origProps.addForwardedField(1, 3, 7);
	origProps.addForwardedField(1, 6, 6);
	origProps.addReadFields(1, new FieldSet(1, 3, 4));

	CoGroupOperatorBase<?,?,?,?> op = mock(CoGroupOperatorBase.class);
	when(op.getSemanticProperties()).thenReturn(origProps);
	when(op.getKeyColumns(0)).thenReturn(new int[]{3,2});
	when(op.getKeyColumns(1)).thenReturn(new int[]{6,3});
	when(op.getParameters()).thenReturn(new Configuration());

	CoGroupNode node = new CoGroupNode(op);

	SemanticProperties filteredProps = node.getSemanticPropertiesForLocalPropertyFiltering();

	// check first input props
	assertTrue(filteredProps.getForwardingTargetFields(0, 0).size() == 0);
	assertTrue(filteredProps.getForwardingTargetFields(0, 2).size() == 1);
	assertTrue(filteredProps.getForwardingTargetFields(0, 2).contains(2));
	assertTrue(filteredProps.getForwardingTargetFields(0, 3).size() == 1);
	assertTrue(filteredProps.getForwardingTargetFields(0, 3).contains(4));
	assertTrue(filteredProps.getForwardingTargetFields(0, 6).size() == 0);
	assertTrue(filteredProps.getForwardingSourceField(0, 1) < 0);
	assertTrue(filteredProps.getForwardingSourceField(0, 2) == 2);
	assertTrue(filteredProps.getForwardingSourceField(0, 4) == 3);
	assertTrue(filteredProps.getForwardingSourceField(0, 0) < 0);
	// check second input props
	assertTrue(filteredProps.getReadFields(0).size() == 4);
	assertTrue(filteredProps.getReadFields(0).contains(0));
	assertTrue(filteredProps.getReadFields(0).contains(2));
	assertTrue(filteredProps.getReadFields(0).contains(4));
	assertTrue(filteredProps.getReadFields(0).contains(7));

	assertTrue(filteredProps.getForwardingTargetFields(1, 1).size() == 0);
	assertTrue(filteredProps.getForwardingTargetFields(1, 2).size() == 0);
	assertTrue(filteredProps.getForwardingTargetFields(1, 3).size() == 1);
	assertTrue(filteredProps.getForwardingTargetFields(1, 3).contains(7));
	assertTrue(filteredProps.getForwardingTargetFields(1, 6).size() == 1);
	assertTrue(filteredProps.getForwardingTargetFields(1, 6).contains(6));
	assertTrue(filteredProps.getForwardingSourceField(1, 2) < 0);
	assertTrue(filteredProps.getForwardingSourceField(1, 8) < 0);
	assertTrue(filteredProps.getForwardingSourceField(1, 7) == 3);
	assertTrue(filteredProps.getForwardingSourceField(1, 6) == 6);

	assertTrue(filteredProps.getReadFields(1).size() == 3);
	assertTrue(filteredProps.getReadFields(1).contains(1));
	assertTrue(filteredProps.getReadFields(1).contains(3));
	assertTrue(filteredProps.getReadFields(1).contains(4));

}
 
Example 3
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
public static DualInputSemanticProperties createProjectionPropertiesDual(
	int[] fields, boolean[] isFromFirst, TypeInformation<?> inType1, TypeInformation<?> inType2) {
	DualInputSemanticProperties dsp = new DualInputSemanticProperties();

	int[] sourceOffsets1;
	if (inType1 instanceof TupleTypeInfo<?>) {
		sourceOffsets1 = new int[inType1.getArity()];
		sourceOffsets1[0] = 0;
		for (int i = 1; i < inType1.getArity(); i++) {
			sourceOffsets1[i] = ((TupleTypeInfo<?>) inType1).getTypeAt(i - 1).getTotalFields() + sourceOffsets1[i - 1];
		}
	} else {
		sourceOffsets1 = new int[]{0};
	}

	int[] sourceOffsets2;
	if (inType2 instanceof TupleTypeInfo<?>) {
		sourceOffsets2 = new int[inType2.getArity()];
		sourceOffsets2[0] = 0;
		for (int i = 1; i < inType2.getArity(); i++) {
			sourceOffsets2[i] = ((TupleTypeInfo<?>) inType2).getTypeAt(i - 1).getTotalFields() + sourceOffsets2[i - 1];
		}
	} else {
		sourceOffsets2 = new int[]{0};
	}

	int targetOffset = 0;
	for (int i = 0; i < fields.length; i++) {
		int sourceOffset;
		int numFieldsToCopy;
		int input;
		if (isFromFirst[i]) {
			input = 0;
			if (fields[i] == -1) {
				sourceOffset = 0;
				numFieldsToCopy = inType1.getTotalFields();
			} else {
				sourceOffset = sourceOffsets1[fields[i]];
				numFieldsToCopy = ((TupleTypeInfo<?>) inType1).getTypeAt(fields[i]).getTotalFields();
			}
		} else {
			input = 1;
			if (fields[i] == -1) {
				sourceOffset = 0;
				numFieldsToCopy = inType2.getTotalFields();
			} else {
				sourceOffset = sourceOffsets2[fields[i]];
				numFieldsToCopy = ((TupleTypeInfo<?>) inType2).getTypeAt(fields[i]).getTotalFields();
			}
		}

		for (int j = 0; j < numFieldsToCopy; j++) {
			dsp.addForwardedField(input, sourceOffset + j, targetOffset + j);
		}
		targetOffset += numFieldsToCopy;
	}

	return dsp;
}
 
Example 4
Source File: CoGroupNodeTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetSemanticProperties() {

	DualInputSemanticProperties origProps = new DualInputSemanticProperties();
	// props for first input
	origProps.addForwardedField(0, 0, 1);
	origProps.addForwardedField(0, 2, 2);
	origProps.addForwardedField(0, 3, 4);
	origProps.addForwardedField(0, 6, 0);
	origProps.addReadFields(0, new FieldSet(0, 2, 4, 7));
	// props for second input
	origProps.addForwardedField(1, 1, 2);
	origProps.addForwardedField(1, 2, 8);
	origProps.addForwardedField(1, 3, 7);
	origProps.addForwardedField(1, 6, 6);
	origProps.addReadFields(1, new FieldSet(1, 3, 4));

	CoGroupOperatorBase<?,?,?,?> op = mock(CoGroupOperatorBase.class);
	when(op.getSemanticProperties()).thenReturn(origProps);
	when(op.getKeyColumns(0)).thenReturn(new int[]{3,2});
	when(op.getKeyColumns(1)).thenReturn(new int[]{6,3});
	when(op.getParameters()).thenReturn(new Configuration());

	CoGroupNode node = new CoGroupNode(op);

	SemanticProperties filteredProps = node.getSemanticPropertiesForLocalPropertyFiltering();

	// check first input props
	assertTrue(filteredProps.getForwardingTargetFields(0, 0).size() == 0);
	assertTrue(filteredProps.getForwardingTargetFields(0, 2).size() == 1);
	assertTrue(filteredProps.getForwardingTargetFields(0, 2).contains(2));
	assertTrue(filteredProps.getForwardingTargetFields(0, 3).size() == 1);
	assertTrue(filteredProps.getForwardingTargetFields(0, 3).contains(4));
	assertTrue(filteredProps.getForwardingTargetFields(0, 6).size() == 0);
	assertTrue(filteredProps.getForwardingSourceField(0, 1) < 0);
	assertTrue(filteredProps.getForwardingSourceField(0, 2) == 2);
	assertTrue(filteredProps.getForwardingSourceField(0, 4) == 3);
	assertTrue(filteredProps.getForwardingSourceField(0, 0) < 0);
	// check second input props
	assertTrue(filteredProps.getReadFields(0).size() == 4);
	assertTrue(filteredProps.getReadFields(0).contains(0));
	assertTrue(filteredProps.getReadFields(0).contains(2));
	assertTrue(filteredProps.getReadFields(0).contains(4));
	assertTrue(filteredProps.getReadFields(0).contains(7));

	assertTrue(filteredProps.getForwardingTargetFields(1, 1).size() == 0);
	assertTrue(filteredProps.getForwardingTargetFields(1, 2).size() == 0);
	assertTrue(filteredProps.getForwardingTargetFields(1, 3).size() == 1);
	assertTrue(filteredProps.getForwardingTargetFields(1, 3).contains(7));
	assertTrue(filteredProps.getForwardingTargetFields(1, 6).size() == 1);
	assertTrue(filteredProps.getForwardingTargetFields(1, 6).contains(6));
	assertTrue(filteredProps.getForwardingSourceField(1, 2) < 0);
	assertTrue(filteredProps.getForwardingSourceField(1, 8) < 0);
	assertTrue(filteredProps.getForwardingSourceField(1, 7) == 3);
	assertTrue(filteredProps.getForwardingSourceField(1, 6) == 6);

	assertTrue(filteredProps.getReadFields(1).size() == 3);
	assertTrue(filteredProps.getReadFields(1).contains(1));
	assertTrue(filteredProps.getReadFields(1).contains(3));
	assertTrue(filteredProps.getReadFields(1).contains(4));

}
 
Example 5
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
public static DualInputSemanticProperties createProjectionPropertiesDual(
	int[] fields, boolean[] isFromFirst, TypeInformation<?> inType1, TypeInformation<?> inType2) {
	DualInputSemanticProperties dsp = new DualInputSemanticProperties();

	int[] sourceOffsets1;
	if (inType1 instanceof TupleTypeInfo<?>) {
		sourceOffsets1 = new int[inType1.getArity()];
		sourceOffsets1[0] = 0;
		for (int i = 1; i < inType1.getArity(); i++) {
			sourceOffsets1[i] = ((TupleTypeInfo<?>) inType1).getTypeAt(i - 1).getTotalFields() + sourceOffsets1[i - 1];
		}
	} else {
		sourceOffsets1 = new int[]{0};
	}

	int[] sourceOffsets2;
	if (inType2 instanceof TupleTypeInfo<?>) {
		sourceOffsets2 = new int[inType2.getArity()];
		sourceOffsets2[0] = 0;
		for (int i = 1; i < inType2.getArity(); i++) {
			sourceOffsets2[i] = ((TupleTypeInfo<?>) inType2).getTypeAt(i - 1).getTotalFields() + sourceOffsets2[i - 1];
		}
	} else {
		sourceOffsets2 = new int[]{0};
	}

	int targetOffset = 0;
	for (int i = 0; i < fields.length; i++) {
		int sourceOffset;
		int numFieldsToCopy;
		int input;
		if (isFromFirst[i]) {
			input = 0;
			if (fields[i] == -1) {
				sourceOffset = 0;
				numFieldsToCopy = inType1.getTotalFields();
			} else {
				sourceOffset = sourceOffsets1[fields[i]];
				numFieldsToCopy = ((TupleTypeInfo<?>) inType1).getTypeAt(fields[i]).getTotalFields();
			}
		} else {
			input = 1;
			if (fields[i] == -1) {
				sourceOffset = 0;
				numFieldsToCopy = inType2.getTotalFields();
			} else {
				sourceOffset = sourceOffsets2[fields[i]];
				numFieldsToCopy = ((TupleTypeInfo<?>) inType2).getTypeAt(fields[i]).getTotalFields();
			}
		}

		for (int j = 0; j < numFieldsToCopy; j++) {
			dsp.addForwardedField(input, sourceOffset + j, targetOffset + j);
		}
		targetOffset += numFieldsToCopy;
	}

	return dsp;
}
 
Example 6
Source File: CoGroupNodeTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetSemanticProperties() {

	DualInputSemanticProperties origProps = new DualInputSemanticProperties();
	// props for first input
	origProps.addForwardedField(0, 0, 1);
	origProps.addForwardedField(0, 2, 2);
	origProps.addForwardedField(0, 3, 4);
	origProps.addForwardedField(0, 6, 0);
	origProps.addReadFields(0, new FieldSet(0, 2, 4, 7));
	// props for second input
	origProps.addForwardedField(1, 1, 2);
	origProps.addForwardedField(1, 2, 8);
	origProps.addForwardedField(1, 3, 7);
	origProps.addForwardedField(1, 6, 6);
	origProps.addReadFields(1, new FieldSet(1, 3, 4));

	CoGroupOperatorBase<?,?,?,?> op = mock(CoGroupOperatorBase.class);
	when(op.getSemanticProperties()).thenReturn(origProps);
	when(op.getKeyColumns(0)).thenReturn(new int[]{3,2});
	when(op.getKeyColumns(1)).thenReturn(new int[]{6,3});
	when(op.getParameters()).thenReturn(new Configuration());

	CoGroupNode node = new CoGroupNode(op);

	SemanticProperties filteredProps = node.getSemanticPropertiesForLocalPropertyFiltering();

	// check first input props
	assertTrue(filteredProps.getForwardingTargetFields(0, 0).size() == 0);
	assertTrue(filteredProps.getForwardingTargetFields(0, 2).size() == 1);
	assertTrue(filteredProps.getForwardingTargetFields(0, 2).contains(2));
	assertTrue(filteredProps.getForwardingTargetFields(0, 3).size() == 1);
	assertTrue(filteredProps.getForwardingTargetFields(0, 3).contains(4));
	assertTrue(filteredProps.getForwardingTargetFields(0, 6).size() == 0);
	assertTrue(filteredProps.getForwardingSourceField(0, 1) < 0);
	assertTrue(filteredProps.getForwardingSourceField(0, 2) == 2);
	assertTrue(filteredProps.getForwardingSourceField(0, 4) == 3);
	assertTrue(filteredProps.getForwardingSourceField(0, 0) < 0);
	// check second input props
	assertTrue(filteredProps.getReadFields(0).size() == 4);
	assertTrue(filteredProps.getReadFields(0).contains(0));
	assertTrue(filteredProps.getReadFields(0).contains(2));
	assertTrue(filteredProps.getReadFields(0).contains(4));
	assertTrue(filteredProps.getReadFields(0).contains(7));

	assertTrue(filteredProps.getForwardingTargetFields(1, 1).size() == 0);
	assertTrue(filteredProps.getForwardingTargetFields(1, 2).size() == 0);
	assertTrue(filteredProps.getForwardingTargetFields(1, 3).size() == 1);
	assertTrue(filteredProps.getForwardingTargetFields(1, 3).contains(7));
	assertTrue(filteredProps.getForwardingTargetFields(1, 6).size() == 1);
	assertTrue(filteredProps.getForwardingTargetFields(1, 6).contains(6));
	assertTrue(filteredProps.getForwardingSourceField(1, 2) < 0);
	assertTrue(filteredProps.getForwardingSourceField(1, 8) < 0);
	assertTrue(filteredProps.getForwardingSourceField(1, 7) == 3);
	assertTrue(filteredProps.getForwardingSourceField(1, 6) == 6);

	assertTrue(filteredProps.getReadFields(1).size() == 3);
	assertTrue(filteredProps.getReadFields(1).contains(1));
	assertTrue(filteredProps.getReadFields(1).contains(3));
	assertTrue(filteredProps.getReadFields(1).contains(4));

}