Java Code Examples for org.apache.flink.api.java.functions.SemanticPropUtil#getSemanticPropsDualFromString()

The following examples show how to use org.apache.flink.api.java.functions.SemanticPropUtil#getSemanticPropsDualFromString() . 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: RequestedLocalPropertiesFilteringTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testDualGroupingPreserved() {

	DualInputSemanticProperties dprops = new DualInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsDualFromString(dprops, new String[]{"1->0;3;2->4"}, new String[]{"0->7;1"},
			null, null, null, null, tupleInfo, tupleInfo, tupleInfo);

	RequestedLocalProperties lprops1 = new RequestedLocalProperties();
	lprops1.setGroupedFields(new FieldSet(0,3,4));

	RequestedLocalProperties lprops2 = new RequestedLocalProperties();
	lprops2.setGroupedFields(new FieldSet(7, 1));

	RequestedLocalProperties filtered1 = lprops1.filterBySemanticProperties(dprops, 0);
	RequestedLocalProperties filtered2 = lprops2.filterBySemanticProperties(dprops, 1);

	assertNotNull(filtered1);
	assertNotNull(filtered1.getGroupedFields());
	assertEquals(3, filtered1.getGroupedFields().size());
	assertTrue(filtered1.getGroupedFields().contains(1));
	assertTrue(filtered1.getGroupedFields().contains(2));
	assertTrue(filtered1.getGroupedFields().contains(3));
	assertNull(filtered1.getOrdering());

	assertNotNull(filtered2);
	assertNotNull(filtered2.getGroupedFields());
	assertEquals(2, filtered2.getGroupedFields().size());
	assertTrue(filtered2.getGroupedFields().contains(0));
	assertTrue(filtered2.getGroupedFields().contains(1));
	assertNull(filtered2.getOrdering());
}
 
Example 2
Source File: RequestedGlobalPropertiesFilteringTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testDualHashPartitioningPreserved() {

	DualInputSemanticProperties dprops = new DualInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsDualFromString(dprops, new String[]{"0;2;4"}, new String[]{"1->3;4->6;3->7"},
			null, null, null, null, tupleInfo, tupleInfo, tupleInfo);

	RequestedGlobalProperties gprops1 = new RequestedGlobalProperties();
	RequestedGlobalProperties gprops2 = new RequestedGlobalProperties();
	gprops1.setHashPartitioned(new FieldSet(2, 0, 4));
	gprops2.setHashPartitioned(new FieldSet(3, 6, 7));
	RequestedGlobalProperties filtered1 = gprops1.filterBySemanticProperties(dprops, 0);
	RequestedGlobalProperties filtered2 = gprops2.filterBySemanticProperties(dprops, 1);

	assertNotNull(filtered1);
	assertEquals(PartitioningProperty.HASH_PARTITIONED, filtered1.getPartitioning());
	assertNotNull(filtered1.getPartitionedFields());
	assertEquals(3, filtered1.getPartitionedFields().size());
	assertTrue(filtered1.getPartitionedFields().contains(0));
	assertTrue(filtered1.getPartitionedFields().contains(2));
	assertTrue(filtered1.getPartitionedFields().contains(4));
	assertNull(filtered1.getOrdering());
	assertNull(filtered1.getCustomPartitioner());
	assertNull(filtered1.getDataDistribution());

	assertNotNull(filtered2);
	assertEquals(PartitioningProperty.HASH_PARTITIONED, filtered2.getPartitioning());
	assertNotNull(filtered2.getPartitionedFields());
	assertEquals(3, filtered2.getPartitionedFields().size());
	assertTrue(filtered2.getPartitionedFields().contains(1));
	assertTrue(filtered2.getPartitionedFields().contains(3));
	assertTrue(filtered2.getPartitionedFields().contains(4));
	assertNull(filtered2.getOrdering());
	assertNull(filtered2.getCustomPartitioner());
	assertNull(filtered2.getDataDistribution());
}
 
Example 3
Source File: RequestedLocalPropertiesFilteringTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDualGroupingPreserved() {

	DualInputSemanticProperties dprops = new DualInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsDualFromString(dprops, new String[]{"1->0;3;2->4"}, new String[]{"0->7;1"},
			null, null, null, null, tupleInfo, tupleInfo, tupleInfo);

	RequestedLocalProperties lprops1 = new RequestedLocalProperties();
	lprops1.setGroupedFields(new FieldSet(0,3,4));

	RequestedLocalProperties lprops2 = new RequestedLocalProperties();
	lprops2.setGroupedFields(new FieldSet(7, 1));

	RequestedLocalProperties filtered1 = lprops1.filterBySemanticProperties(dprops, 0);
	RequestedLocalProperties filtered2 = lprops2.filterBySemanticProperties(dprops, 1);

	assertNotNull(filtered1);
	assertNotNull(filtered1.getGroupedFields());
	assertEquals(3, filtered1.getGroupedFields().size());
	assertTrue(filtered1.getGroupedFields().contains(1));
	assertTrue(filtered1.getGroupedFields().contains(2));
	assertTrue(filtered1.getGroupedFields().contains(3));
	assertNull(filtered1.getOrdering());

	assertNotNull(filtered2);
	assertNotNull(filtered2.getGroupedFields());
	assertEquals(2, filtered2.getGroupedFields().size());
	assertTrue(filtered2.getGroupedFields().contains(0));
	assertTrue(filtered2.getGroupedFields().contains(1));
	assertNull(filtered2.getOrdering());
}
 
Example 4
Source File: RequestedGlobalPropertiesFilteringTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDualHashPartitioningPreserved() {

	DualInputSemanticProperties dprops = new DualInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsDualFromString(dprops, new String[]{"0;2;4"}, new String[]{"1->3;4->6;3->7"},
			null, null, null, null, tupleInfo, tupleInfo, tupleInfo);

	RequestedGlobalProperties gprops1 = new RequestedGlobalProperties();
	RequestedGlobalProperties gprops2 = new RequestedGlobalProperties();
	gprops1.setHashPartitioned(new FieldSet(2, 0, 4));
	gprops2.setHashPartitioned(new FieldSet(3, 6, 7));
	RequestedGlobalProperties filtered1 = gprops1.filterBySemanticProperties(dprops, 0);
	RequestedGlobalProperties filtered2 = gprops2.filterBySemanticProperties(dprops, 1);

	assertNotNull(filtered1);
	assertEquals(PartitioningProperty.HASH_PARTITIONED, filtered1.getPartitioning());
	assertNotNull(filtered1.getPartitionedFields());
	assertEquals(3, filtered1.getPartitionedFields().size());
	assertTrue(filtered1.getPartitionedFields().contains(0));
	assertTrue(filtered1.getPartitionedFields().contains(2));
	assertTrue(filtered1.getPartitionedFields().contains(4));
	assertNull(filtered1.getOrdering());
	assertNull(filtered1.getCustomPartitioner());
	assertNull(filtered1.getDataDistribution());

	assertNotNull(filtered2);
	assertEquals(PartitioningProperty.HASH_PARTITIONED, filtered2.getPartitioning());
	assertNotNull(filtered2.getPartitionedFields());
	assertEquals(3, filtered2.getPartitionedFields().size());
	assertTrue(filtered2.getPartitionedFields().contains(1));
	assertTrue(filtered2.getPartitionedFields().contains(3));
	assertTrue(filtered2.getPartitionedFields().contains(4));
	assertNull(filtered2.getOrdering());
	assertNull(filtered2.getCustomPartitioner());
	assertNull(filtered2.getDataDistribution());
}
 
Example 5
Source File: RequestedLocalPropertiesFilteringTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDualGroupingPreserved() {

	DualInputSemanticProperties dprops = new DualInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsDualFromString(dprops, new String[]{"1->0;3;2->4"}, new String[]{"0->7;1"},
			null, null, null, null, tupleInfo, tupleInfo, tupleInfo);

	RequestedLocalProperties lprops1 = new RequestedLocalProperties();
	lprops1.setGroupedFields(new FieldSet(0,3,4));

	RequestedLocalProperties lprops2 = new RequestedLocalProperties();
	lprops2.setGroupedFields(new FieldSet(7, 1));

	RequestedLocalProperties filtered1 = lprops1.filterBySemanticProperties(dprops, 0);
	RequestedLocalProperties filtered2 = lprops2.filterBySemanticProperties(dprops, 1);

	assertNotNull(filtered1);
	assertNotNull(filtered1.getGroupedFields());
	assertEquals(3, filtered1.getGroupedFields().size());
	assertTrue(filtered1.getGroupedFields().contains(1));
	assertTrue(filtered1.getGroupedFields().contains(2));
	assertTrue(filtered1.getGroupedFields().contains(3));
	assertNull(filtered1.getOrdering());

	assertNotNull(filtered2);
	assertNotNull(filtered2.getGroupedFields());
	assertEquals(2, filtered2.getGroupedFields().size());
	assertTrue(filtered2.getGroupedFields().contains(0));
	assertTrue(filtered2.getGroupedFields().contains(1));
	assertNull(filtered2.getOrdering());
}
 
Example 6
Source File: RequestedGlobalPropertiesFilteringTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDualHashPartitioningPreserved() {

	DualInputSemanticProperties dprops = new DualInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsDualFromString(dprops, new String[]{"0;2;4"}, new String[]{"1->3;4->6;3->7"},
			null, null, null, null, tupleInfo, tupleInfo, tupleInfo);

	RequestedGlobalProperties gprops1 = new RequestedGlobalProperties();
	RequestedGlobalProperties gprops2 = new RequestedGlobalProperties();
	gprops1.setHashPartitioned(new FieldSet(2, 0, 4));
	gprops2.setHashPartitioned(new FieldSet(3, 6, 7));
	RequestedGlobalProperties filtered1 = gprops1.filterBySemanticProperties(dprops, 0);
	RequestedGlobalProperties filtered2 = gprops2.filterBySemanticProperties(dprops, 1);

	assertNotNull(filtered1);
	assertEquals(PartitioningProperty.HASH_PARTITIONED, filtered1.getPartitioning());
	assertNotNull(filtered1.getPartitionedFields());
	assertEquals(3, filtered1.getPartitionedFields().size());
	assertTrue(filtered1.getPartitionedFields().contains(0));
	assertTrue(filtered1.getPartitionedFields().contains(2));
	assertTrue(filtered1.getPartitionedFields().contains(4));
	assertNull(filtered1.getOrdering());
	assertNull(filtered1.getCustomPartitioner());
	assertNull(filtered1.getDataDistribution());

	assertNotNull(filtered2);
	assertEquals(PartitioningProperty.HASH_PARTITIONED, filtered2.getPartitioning());
	assertNotNull(filtered2.getPartitionedFields());
	assertEquals(3, filtered2.getPartitionedFields().size());
	assertTrue(filtered2.getPartitionedFields().contains(1));
	assertTrue(filtered2.getPartitionedFields().contains(3));
	assertTrue(filtered2.getPartitionedFields().contains(4));
	assertNull(filtered2.getOrdering());
	assertNull(filtered2.getCustomPartitioner());
	assertNull(filtered2.getDataDistribution());
}
 
Example 7
Source File: TwoInputUdfOperator.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
/**
 * Adds semantic information about forwarded fields of the first input of the user-defined function.
 * The forwarded fields information declares fields which are never modified by the function and
 * which are forwarded at the same position to the output or unchanged copied to another position in the output.
 *
 * <p>Fields that are forwarded at the same position are specified by their position.
 * The specified position must be valid for the input and output data type and have the same type.
 * For example <code>withForwardedFieldsFirst("f2")</code> declares that the third field of a Java input tuple
 * from the first input is copied to the third field of an output tuple.
 *
 * <p>Fields which are unchanged copied from the first input to another position in the output are declared
 * by specifying the source field reference in the first input and the target field reference in the output.
 * {@code withForwardedFieldsFirst("f0->f2")} denotes that the first field of the first input Java tuple is
 * unchanged copied to the third field of the Java output tuple. When using a wildcard ("*") ensure that
 * the number of declared fields and their types in first input and output type match.
 *
 * <p>Multiple forwarded fields can be annotated in one ({@code withForwardedFieldsFirst("f2; f3->f0; f4")})
 * or separate Strings ({@code withForwardedFieldsFirst("f2", "f3->f0", "f4")}).
 * Please refer to the JavaDoc of {@link org.apache.flink.api.common.functions.Function} or Flink's documentation for
 * details on field references such as nested fields and wildcard.
 *
 * <p>It is not possible to override existing semantic information about forwarded fields of the first input which was
 * for example added by a {@link org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsFirst} class annotation.
 *
 * <p><b>NOTE: Adding semantic information for functions is optional!
 * If used correctly, semantic information can help the Flink optimizer to generate more efficient execution plans.
 * However, incorrect semantic information can cause the optimizer to generate incorrect execution plans which compute wrong results!
 * So be careful when adding semantic information.
 * </b>
 *
 * @param forwardedFieldsFirst A list of forwarded field expressions for the first input of the function.
 * @return This operator with annotated forwarded field information.
 *
 * @see org.apache.flink.api.java.functions.FunctionAnnotation
 * @see org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsFirst
 */
@SuppressWarnings("unchecked")
public O withForwardedFieldsFirst(String... forwardedFieldsFirst) {
	if (this.udfSemantics == null || this.analyzedUdfSemantics) {
		// extract semantic properties from function annotations
		setSemanticProperties(extractSemanticAnnotationsFromUdf(getFunction().getClass()));
	}

	if (this.udfSemantics == null || this.analyzedUdfSemantics) {
		setSemanticProperties(new DualInputSemanticProperties());
		SemanticPropUtil.getSemanticPropsDualFromString(this.udfSemantics, forwardedFieldsFirst, null,
				null, null, null, null, getInput1Type(), getInput2Type(), getResultType());
	} else {
		if (this.udfWithForwardedFieldsFirstAnnotation(getFunction().getClass())) {
			// refuse semantic information as it would override the function annotation
			throw new SemanticProperties.InvalidSemanticAnnotationException("Forwarded field information " +
					"has already been added by a function annotation for the first input of this operator. " +
					"Cannot overwrite function annotations.");
		} else {
			SemanticPropUtil.getSemanticPropsDualFromString(this.udfSemantics, forwardedFieldsFirst, null,
					null, null, null, null, getInput1Type(), getInput2Type(), getResultType());
		}
	}

	O returnType = (O) this;
	return returnType;
}
 
Example 8
Source File: TwoInputUdfOperator.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
/**
 * Adds semantic information about forwarded fields of the second input of the user-defined function.
 * The forwarded fields information declares fields which are never modified by the function and
 * which are forwarded at the same position to the output or unchanged copied to another position in the output.
 *
 * <p>Fields that are forwarded at the same position are specified by their position.
 * The specified position must be valid for the input and output data type and have the same type.
 * For example <code>withForwardedFieldsSecond("f2")</code> declares that the third field of a Java input tuple
 * from the second input is copied to the third field of an output tuple.
 *
 * <p>Fields which are unchanged copied from the second input to another position in the output are declared
 * by specifying the source field reference in the second input and the target field reference in the output.
 * {@code withForwardedFieldsSecond("f0->f2")} denotes that the first field of the second input Java tuple is
 * unchanged copied to the third field of the Java output tuple. When using a wildcard ("*") ensure that
 * the number of declared fields and their types in second input and output type match.
 *
 * <p>Multiple forwarded fields can be annotated in one ({@code withForwardedFieldsSecond("f2; f3->f0; f4")})
 * or separate Strings ({@code withForwardedFieldsSecond("f2", "f3->f0", "f4")}).
 * Please refer to the JavaDoc of {@link org.apache.flink.api.common.functions.Function} or Flink's documentation for
 * details on field references such as nested fields and wildcard.
 *
 * <p>It is not possible to override existing semantic information about forwarded fields of the second input which was
 * for example added by a {@link org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsSecond} class annotation.
 *
 * <p><b>NOTE: Adding semantic information for functions is optional!
 * If used correctly, semantic information can help the Flink optimizer to generate more efficient execution plans.
 * However, incorrect semantic information can cause the optimizer to generate incorrect execution plans which compute wrong results!
 * So be careful when adding semantic information.
 * </b>
 *
 * @param forwardedFieldsSecond A list of forwarded field expressions for the second input of the function.
 * @return This operator with annotated forwarded field information.
 *
 * @see org.apache.flink.api.java.functions.FunctionAnnotation
 * @see org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsSecond
 */
@SuppressWarnings("unchecked")
public O withForwardedFieldsSecond(String... forwardedFieldsSecond) {
	if (this.udfSemantics == null || this.analyzedUdfSemantics) {
		// extract semantic properties from function annotations
		setSemanticProperties(extractSemanticAnnotationsFromUdf(getFunction().getClass()));
	}

	if (this.udfSemantics == null || this.analyzedUdfSemantics) {
		setSemanticProperties(new DualInputSemanticProperties());
		SemanticPropUtil.getSemanticPropsDualFromString(this.udfSemantics, null, forwardedFieldsSecond,
				null, null, null, null, getInput1Type(), getInput2Type(), getResultType());
	} else {
		if (udfWithForwardedFieldsSecondAnnotation(getFunction().getClass())) {
			// refuse semantic information as it would override the function annotation
			throw new SemanticProperties.InvalidSemanticAnnotationException("Forwarded field information " +
					"has already been added by a function annotation for the second input of this operator. " +
					"Cannot overwrite function annotations.");
		} else {
			SemanticPropUtil.getSemanticPropsDualFromString(this.udfSemantics, null, forwardedFieldsSecond,
					null, null, null, null, getInput1Type(), getInput2Type(), getResultType());
		}
	}

	O returnType = (O) this;
	return returnType;
}
 
Example 9
Source File: TwoInputUdfOperator.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Adds semantic information about forwarded fields of the first input of the user-defined function.
 * The forwarded fields information declares fields which are never modified by the function and
 * which are forwarded at the same position to the output or unchanged copied to another position in the output.
 *
 * <p>Fields that are forwarded at the same position are specified by their position.
 * The specified position must be valid for the input and output data type and have the same type.
 * For example <code>withForwardedFieldsFirst("f2")</code> declares that the third field of a Java input tuple
 * from the first input is copied to the third field of an output tuple.
 *
 * <p>Fields which are unchanged copied from the first input to another position in the output are declared
 * by specifying the source field reference in the first input and the target field reference in the output.
 * {@code withForwardedFieldsFirst("f0->f2")} denotes that the first field of the first input Java tuple is
 * unchanged copied to the third field of the Java output tuple. When using a wildcard ("*") ensure that
 * the number of declared fields and their types in first input and output type match.
 *
 * <p>Multiple forwarded fields can be annotated in one ({@code withForwardedFieldsFirst("f2; f3->f0; f4")})
 * or separate Strings ({@code withForwardedFieldsFirst("f2", "f3->f0", "f4")}).
 * Please refer to the JavaDoc of {@link org.apache.flink.api.common.functions.Function} or Flink's documentation for
 * details on field references such as nested fields and wildcard.
 *
 * <p>It is not possible to override existing semantic information about forwarded fields of the first input which was
 * for example added by a {@link org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsFirst} class annotation.
 *
 * <p><b>NOTE: Adding semantic information for functions is optional!
 * If used correctly, semantic information can help the Flink optimizer to generate more efficient execution plans.
 * However, incorrect semantic information can cause the optimizer to generate incorrect execution plans which compute wrong results!
 * So be careful when adding semantic information.
 * </b>
 *
 * @param forwardedFieldsFirst A list of forwarded field expressions for the first input of the function.
 * @return This operator with annotated forwarded field information.
 *
 * @see org.apache.flink.api.java.functions.FunctionAnnotation
 * @see org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsFirst
 */
@SuppressWarnings("unchecked")
public O withForwardedFieldsFirst(String... forwardedFieldsFirst) {
	if (this.udfSemantics == null || this.analyzedUdfSemantics) {
		// extract semantic properties from function annotations
		setSemanticProperties(extractSemanticAnnotationsFromUdf(getFunction().getClass()));
	}

	if (this.udfSemantics == null || this.analyzedUdfSemantics) {
		setSemanticProperties(new DualInputSemanticProperties());
		SemanticPropUtil.getSemanticPropsDualFromString(this.udfSemantics, forwardedFieldsFirst, null,
				null, null, null, null, getInput1Type(), getInput2Type(), getResultType());
	} else {
		if (this.udfWithForwardedFieldsFirstAnnotation(getFunction().getClass())) {
			// refuse semantic information as it would override the function annotation
			throw new SemanticProperties.InvalidSemanticAnnotationException("Forwarded field information " +
					"has already been added by a function annotation for the first input of this operator. " +
					"Cannot overwrite function annotations.");
		} else {
			SemanticPropUtil.getSemanticPropsDualFromString(this.udfSemantics, forwardedFieldsFirst, null,
					null, null, null, null, getInput1Type(), getInput2Type(), getResultType());
		}
	}

	O returnType = (O) this;
	return returnType;
}
 
Example 10
Source File: TwoInputUdfOperator.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Adds semantic information about forwarded fields of the second input of the user-defined function.
 * The forwarded fields information declares fields which are never modified by the function and
 * which are forwarded at the same position to the output or unchanged copied to another position in the output.
 *
 * <p>Fields that are forwarded at the same position are specified by their position.
 * The specified position must be valid for the input and output data type and have the same type.
 * For example <code>withForwardedFieldsSecond("f2")</code> declares that the third field of a Java input tuple
 * from the second input is copied to the third field of an output tuple.
 *
 * <p>Fields which are unchanged copied from the second input to another position in the output are declared
 * by specifying the source field reference in the second input and the target field reference in the output.
 * {@code withForwardedFieldsSecond("f0->f2")} denotes that the first field of the second input Java tuple is
 * unchanged copied to the third field of the Java output tuple. When using a wildcard ("*") ensure that
 * the number of declared fields and their types in second input and output type match.
 *
 * <p>Multiple forwarded fields can be annotated in one ({@code withForwardedFieldsSecond("f2; f3->f0; f4")})
 * or separate Strings ({@code withForwardedFieldsSecond("f2", "f3->f0", "f4")}).
 * Please refer to the JavaDoc of {@link org.apache.flink.api.common.functions.Function} or Flink's documentation for
 * details on field references such as nested fields and wildcard.
 *
 * <p>It is not possible to override existing semantic information about forwarded fields of the second input which was
 * for example added by a {@link org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsSecond} class annotation.
 *
 * <p><b>NOTE: Adding semantic information for functions is optional!
 * If used correctly, semantic information can help the Flink optimizer to generate more efficient execution plans.
 * However, incorrect semantic information can cause the optimizer to generate incorrect execution plans which compute wrong results!
 * So be careful when adding semantic information.
 * </b>
 *
 * @param forwardedFieldsSecond A list of forwarded field expressions for the second input of the function.
 * @return This operator with annotated forwarded field information.
 *
 * @see org.apache.flink.api.java.functions.FunctionAnnotation
 * @see org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsSecond
 */
@SuppressWarnings("unchecked")
public O withForwardedFieldsSecond(String... forwardedFieldsSecond) {
	if (this.udfSemantics == null || this.analyzedUdfSemantics) {
		// extract semantic properties from function annotations
		setSemanticProperties(extractSemanticAnnotationsFromUdf(getFunction().getClass()));
	}

	if (this.udfSemantics == null || this.analyzedUdfSemantics) {
		setSemanticProperties(new DualInputSemanticProperties());
		SemanticPropUtil.getSemanticPropsDualFromString(this.udfSemantics, null, forwardedFieldsSecond,
				null, null, null, null, getInput1Type(), getInput2Type(), getResultType());
	} else {
		if (udfWithForwardedFieldsSecondAnnotation(getFunction().getClass())) {
			// refuse semantic information as it would override the function annotation
			throw new SemanticProperties.InvalidSemanticAnnotationException("Forwarded field information " +
					"has already been added by a function annotation for the second input of this operator. " +
					"Cannot overwrite function annotations.");
		} else {
			SemanticPropUtil.getSemanticPropsDualFromString(this.udfSemantics, null, forwardedFieldsSecond,
					null, null, null, null, getInput1Type(), getInput2Type(), getResultType());
		}
	}

	O returnType = (O) this;
	return returnType;
}
 
Example 11
Source File: TwoInputUdfOperator.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Adds semantic information about forwarded fields of the first input of the user-defined function.
 * The forwarded fields information declares fields which are never modified by the function and
 * which are forwarded at the same position to the output or unchanged copied to another position in the output.
 *
 * <p>Fields that are forwarded at the same position are specified by their position.
 * The specified position must be valid for the input and output data type and have the same type.
 * For example <code>withForwardedFieldsFirst("f2")</code> declares that the third field of a Java input tuple
 * from the first input is copied to the third field of an output tuple.
 *
 * <p>Fields which are unchanged copied from the first input to another position in the output are declared
 * by specifying the source field reference in the first input and the target field reference in the output.
 * {@code withForwardedFieldsFirst("f0->f2")} denotes that the first field of the first input Java tuple is
 * unchanged copied to the third field of the Java output tuple. When using a wildcard ("*") ensure that
 * the number of declared fields and their types in first input and output type match.
 *
 * <p>Multiple forwarded fields can be annotated in one ({@code withForwardedFieldsFirst("f2; f3->f0; f4")})
 * or separate Strings ({@code withForwardedFieldsFirst("f2", "f3->f0", "f4")}).
 * Please refer to the JavaDoc of {@link org.apache.flink.api.common.functions.Function} or Flink's documentation for
 * details on field references such as nested fields and wildcard.
 *
 * <p>It is not possible to override existing semantic information about forwarded fields of the first input which was
 * for example added by a {@link org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsFirst} class annotation.
 *
 * <p><b>NOTE: Adding semantic information for functions is optional!
 * If used correctly, semantic information can help the Flink optimizer to generate more efficient execution plans.
 * However, incorrect semantic information can cause the optimizer to generate incorrect execution plans which compute wrong results!
 * So be careful when adding semantic information.
 * </b>
 *
 * @param forwardedFieldsFirst A list of forwarded field expressions for the first input of the function.
 * @return This operator with annotated forwarded field information.
 *
 * @see org.apache.flink.api.java.functions.FunctionAnnotation
 * @see org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsFirst
 */
@SuppressWarnings("unchecked")
public O withForwardedFieldsFirst(String... forwardedFieldsFirst) {
	if (this.udfSemantics == null || this.analyzedUdfSemantics) {
		// extract semantic properties from function annotations
		setSemanticProperties(extractSemanticAnnotationsFromUdf(getFunction().getClass()));
	}

	if (this.udfSemantics == null || this.analyzedUdfSemantics) {
		setSemanticProperties(new DualInputSemanticProperties());
		SemanticPropUtil.getSemanticPropsDualFromString(this.udfSemantics, forwardedFieldsFirst, null,
				null, null, null, null, getInput1Type(), getInput2Type(), getResultType());
	} else {
		if (this.udfWithForwardedFieldsFirstAnnotation(getFunction().getClass())) {
			// refuse semantic information as it would override the function annotation
			throw new SemanticProperties.InvalidSemanticAnnotationException("Forwarded field information " +
					"has already been added by a function annotation for the first input of this operator. " +
					"Cannot overwrite function annotations.");
		} else {
			SemanticPropUtil.getSemanticPropsDualFromString(this.udfSemantics, forwardedFieldsFirst, null,
					null, null, null, null, getInput1Type(), getInput2Type(), getResultType());
		}
	}

	O returnType = (O) this;
	return returnType;
}
 
Example 12
Source File: TwoInputUdfOperator.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Adds semantic information about forwarded fields of the second input of the user-defined function.
 * The forwarded fields information declares fields which are never modified by the function and
 * which are forwarded at the same position to the output or unchanged copied to another position in the output.
 *
 * <p>Fields that are forwarded at the same position are specified by their position.
 * The specified position must be valid for the input and output data type and have the same type.
 * For example <code>withForwardedFieldsSecond("f2")</code> declares that the third field of a Java input tuple
 * from the second input is copied to the third field of an output tuple.
 *
 * <p>Fields which are unchanged copied from the second input to another position in the output are declared
 * by specifying the source field reference in the second input and the target field reference in the output.
 * {@code withForwardedFieldsSecond("f0->f2")} denotes that the first field of the second input Java tuple is
 * unchanged copied to the third field of the Java output tuple. When using a wildcard ("*") ensure that
 * the number of declared fields and their types in second input and output type match.
 *
 * <p>Multiple forwarded fields can be annotated in one ({@code withForwardedFieldsSecond("f2; f3->f0; f4")})
 * or separate Strings ({@code withForwardedFieldsSecond("f2", "f3->f0", "f4")}).
 * Please refer to the JavaDoc of {@link org.apache.flink.api.common.functions.Function} or Flink's documentation for
 * details on field references such as nested fields and wildcard.
 *
 * <p>It is not possible to override existing semantic information about forwarded fields of the second input which was
 * for example added by a {@link org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsSecond} class annotation.
 *
 * <p><b>NOTE: Adding semantic information for functions is optional!
 * If used correctly, semantic information can help the Flink optimizer to generate more efficient execution plans.
 * However, incorrect semantic information can cause the optimizer to generate incorrect execution plans which compute wrong results!
 * So be careful when adding semantic information.
 * </b>
 *
 * @param forwardedFieldsSecond A list of forwarded field expressions for the second input of the function.
 * @return This operator with annotated forwarded field information.
 *
 * @see org.apache.flink.api.java.functions.FunctionAnnotation
 * @see org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsSecond
 */
@SuppressWarnings("unchecked")
public O withForwardedFieldsSecond(String... forwardedFieldsSecond) {
	if (this.udfSemantics == null || this.analyzedUdfSemantics) {
		// extract semantic properties from function annotations
		setSemanticProperties(extractSemanticAnnotationsFromUdf(getFunction().getClass()));
	}

	if (this.udfSemantics == null || this.analyzedUdfSemantics) {
		setSemanticProperties(new DualInputSemanticProperties());
		SemanticPropUtil.getSemanticPropsDualFromString(this.udfSemantics, null, forwardedFieldsSecond,
				null, null, null, null, getInput1Type(), getInput2Type(), getResultType());
	} else {
		if (udfWithForwardedFieldsSecondAnnotation(getFunction().getClass())) {
			// refuse semantic information as it would override the function annotation
			throw new SemanticProperties.InvalidSemanticAnnotationException("Forwarded field information " +
					"has already been added by a function annotation for the second input of this operator. " +
					"Cannot overwrite function annotations.");
		} else {
			SemanticPropUtil.getSemanticPropsDualFromString(this.udfSemantics, null, forwardedFieldsSecond,
					null, null, null, null, getInput1Type(), getInput2Type(), getResultType());
		}
	}

	O returnType = (O) this;
	return returnType;
}