Java Code Examples for org.apache.flink.api.common.operators.SingleInputSemanticProperties#getReadFields()

The following examples show how to use org.apache.flink.api.common.operators.SingleInputSemanticProperties#getReadFields() . 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: SemanticPropertiesTranslationTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnaryFunctionReadFieldsAnnotation() {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	@SuppressWarnings("unchecked")
	DataSet<Tuple3<Long, Long, Long>> input = env.fromElements(new Tuple3<Long, Long, Long>(3L, 2L, 1L));
	input.map(new ReadSetMapper<Tuple3<Long, Long, Long>>()).output(new DiscardingOutputFormat<Tuple3<Long, Long, Long>>());
	Plan plan = env.createProgramPlan();

	GenericDataSinkBase<?> sink = plan.getDataSinks().iterator().next();
	MapOperatorBase<?, ?, ?> mapper = (MapOperatorBase<?, ?, ?>) sink.getInput();

	SingleInputSemanticProperties semantics = mapper.getSemanticProperties();

	FieldSet read = semantics.getReadFields(0);
	assertNotNull(read);
	assertEquals(2, read.size());
	assertTrue(read.contains(0));
	assertTrue(read.contains(2));
}
 
Example 2
Source File: GroupCombineNode.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected SemanticProperties getSemanticPropertiesForLocalPropertyFiltering() {

	// Local properties for GroupCombine may only be preserved on key fields.
	SingleInputSemanticProperties origProps =
			((SingleInputOperator<?,?,?>) getOperator()).getSemanticProperties();
	SingleInputSemanticProperties filteredProps = new SingleInputSemanticProperties();
	FieldSet readSet = origProps.getReadFields(0);
	if(readSet != null) {
		filteredProps.addReadFields(readSet);
	}

	// only add forward field information for key fields
	if(this.keys != null) {
		for (int f : this.keys) {
			FieldSet targets = origProps.getForwardingTargetFields(0, f);
			for (int t : targets) {
				filteredProps.addForwardedField(f, t);
			}
		}
	}
	return filteredProps;
}
 
Example 3
Source File: SemanticPropertiesTranslationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnaryFunctionReadFieldsAnnotation() {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	@SuppressWarnings("unchecked")
	DataSet<Tuple3<Long, Long, Long>> input = env.fromElements(new Tuple3<Long, Long, Long>(3L, 2L, 1L));
	input.map(new ReadSetMapper<Tuple3<Long, Long, Long>>()).output(new DiscardingOutputFormat<Tuple3<Long, Long, Long>>());
	Plan plan = env.createProgramPlan();

	GenericDataSinkBase<?> sink = plan.getDataSinks().iterator().next();
	MapOperatorBase<?, ?, ?> mapper = (MapOperatorBase<?, ?, ?>) sink.getInput();

	SingleInputSemanticProperties semantics = mapper.getSemanticProperties();

	FieldSet read = semantics.getReadFields(0);
	assertNotNull(read);
	assertEquals(2, read.size());
	assertTrue(read.contains(0));
	assertTrue(read.contains(2));
}
 
Example 4
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 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: GroupCombineNode.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected SemanticProperties getSemanticPropertiesForLocalPropertyFiltering() {

	// Local properties for GroupCombine may only be preserved on key fields.
	SingleInputSemanticProperties origProps =
			((SingleInputOperator<?,?,?>) getOperator()).getSemanticProperties();
	SingleInputSemanticProperties filteredProps = new SingleInputSemanticProperties();
	FieldSet readSet = origProps.getReadFields(0);
	if(readSet != null) {
		filteredProps.addReadFields(readSet);
	}

	// only add forward field information for key fields
	if(this.keys != null) {
		for (int f : this.keys) {
			FieldSet targets = origProps.getForwardingTargetFields(0, f);
			for (int t : targets) {
				filteredProps.addForwardedField(f, t);
			}
		}
	}
	return filteredProps;
}
 
Example 7
Source File: GroupReduceNode.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected SemanticProperties getSemanticPropertiesForLocalPropertyFiltering() {
	// Local properties for GroupReduce may only be preserved on key fields.
	SingleInputSemanticProperties origProps = getOperator().getSemanticProperties();
	SingleInputSemanticProperties filteredProps = new SingleInputSemanticProperties();
	FieldSet readSet = origProps.getReadFields(0);
	if(readSet != null) {
		filteredProps.addReadFields(readSet);
	}

	// only add forward field information for key fields
	if(this.keys != null) {
		for (int f : this.keys) {
			FieldSet targets = origProps.getForwardingTargetFields(0, f);
			for (int t : targets) {
				filteredProps.addForwardedField(f, t);
			}
		}
	}
	return filteredProps;
}
 
Example 8
Source File: GroupReduceNode.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected SemanticProperties getSemanticPropertiesForLocalPropertyFiltering() {
	// Local properties for GroupReduce may only be preserved on key fields.
	SingleInputSemanticProperties origProps = getOperator().getSemanticProperties();
	SingleInputSemanticProperties filteredProps = new SingleInputSemanticProperties();
	FieldSet readSet = origProps.getReadFields(0);
	if(readSet != null) {
		filteredProps.addReadFields(readSet);
	}

	// only add forward field information for key fields
	if(this.keys != null) {
		for (int f : this.keys) {
			FieldSet targets = origProps.getForwardingTargetFields(0, f);
			for (int t : targets) {
				filteredProps.addForwardedField(f, t);
			}
		}
	}
	return filteredProps;
}
 
Example 9
Source File: GroupCombineNode.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected SemanticProperties getSemanticPropertiesForLocalPropertyFiltering() {

	// Local properties for GroupCombine may only be preserved on key fields.
	SingleInputSemanticProperties origProps =
			((SingleInputOperator<?,?,?>) getOperator()).getSemanticProperties();
	SingleInputSemanticProperties filteredProps = new SingleInputSemanticProperties();
	FieldSet readSet = origProps.getReadFields(0);
	if(readSet != null) {
		filteredProps.addReadFields(readSet);
	}

	// only add forward field information for key fields
	if(this.keys != null) {
		for (int f : this.keys) {
			FieldSet targets = origProps.getForwardingTargetFields(0, f);
			for (int t : targets) {
				filteredProps.addForwardedField(f, t);
			}
		}
	}
	return filteredProps;
}
 
Example 10
Source File: SemanticPropUtilTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadFieldsSpaces() {
	String[] readFields = { "  f1  ; f2   " };
	SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sp, null, null, readFields, threeIntTupleType, threeIntTupleType);

	FieldSet fs = sp.getReadFields(0);
	assertTrue(fs.size() == 2);
	assertTrue(fs.contains(2));
	assertTrue(fs.contains(1));
}
 
Example 11
Source File: SemanticPropUtilTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadFieldsPojoInTuple() {
	String[] readFields = { "f0; f2.int1; f2.string1" };
	SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sp, null, null, readFields, pojoInTupleType, pojo2Type);

	FieldSet fs = sp.getReadFields(0);
	assertTrue(fs.size() == 3);
	assertTrue(fs.contains(0));
	assertTrue(fs.contains(2));
	assertTrue(fs.contains(5));
}
 
Example 12
Source File: SemanticPropUtilTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadFieldsSpaces() {
	String[] readFields = { "  f1  ; f2   " };
	SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sp, null, null, readFields, threeIntTupleType, threeIntTupleType);

	FieldSet fs = sp.getReadFields(0);
	assertTrue(fs.size() == 2);
	assertTrue(fs.contains(2));
	assertTrue(fs.contains(1));
}
 
Example 13
Source File: SemanticPropUtilTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadFieldsIndividualStrings() {
	String[] readFields = { "f1", "f2" };
	SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sp, null, null, readFields, threeIntTupleType, threeIntTupleType);

	FieldSet fs = sp.getReadFields(0);
	assertTrue(fs.size() == 2);
	assertTrue(fs.contains(2));
	assertTrue(fs.contains(1));
}
 
Example 14
Source File: MapPartitionNode.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected SemanticProperties getSemanticPropertiesForLocalPropertyFiltering() {

	// Local properties for MapPartition may not be preserved.
	SingleInputSemanticProperties origProps =
			((SingleInputOperator<?,?,?>) getOperator()).getSemanticProperties();
	SingleInputSemanticProperties filteredProps = new SingleInputSemanticProperties();
	FieldSet readSet = origProps.getReadFields(0);
	if(readSet != null) {
		filteredProps.addReadFields(readSet);
	}

	return filteredProps;
}
 
Example 15
Source File: SemanticPropUtilTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadFieldsPojoInTuple() {
	String[] readFields = { "f0; f2.int1; f2.string1" };
	SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sp, null, null, readFields, pojoInTupleType, pojo2Type);

	FieldSet fs = sp.getReadFields(0);
	assertTrue(fs.size() == 3);
	assertTrue(fs.contains(0));
	assertTrue(fs.contains(2));
	assertTrue(fs.contains(5));
}
 
Example 16
Source File: SemanticPropUtilTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadFieldsIndividualStrings() {
	String[] readFields = { "f1", "f2" };
	SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sp, null, null, readFields, threeIntTupleType, threeIntTupleType);

	FieldSet fs = sp.getReadFields(0);
	assertTrue(fs.size() == 2);
	assertTrue(fs.contains(2));
	assertTrue(fs.contains(1));
}
 
Example 17
Source File: MapPartitionNode.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected SemanticProperties getSemanticPropertiesForLocalPropertyFiltering() {

	// Local properties for MapPartition may not be preserved.
	SingleInputSemanticProperties origProps =
			((SingleInputOperator<?,?,?>) getOperator()).getSemanticProperties();
	SingleInputSemanticProperties filteredProps = new SingleInputSemanticProperties();
	FieldSet readSet = origProps.getReadFields(0);
	if(readSet != null) {
		filteredProps.addReadFields(readSet);
	}

	return filteredProps;
}
 
Example 18
Source File: SemanticPropUtilTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadFieldsPojoInTuple() {
	String[] readFields = { "f0; f2.int1; f2.string1" };
	SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sp, null, null, readFields, pojoInTupleType, pojo2Type);

	FieldSet fs = sp.getReadFields(0);
	assertTrue(fs.size() == 3);
	assertTrue(fs.contains(0));
	assertTrue(fs.contains(2));
	assertTrue(fs.contains(5));
}
 
Example 19
Source File: SemanticPropUtilTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadFieldsSpaces() {
	String[] readFields = { "  f1  ; f2   " };
	SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sp, null, null, readFields, threeIntTupleType, threeIntTupleType);

	FieldSet fs = sp.getReadFields(0);
	assertTrue(fs.size() == 2);
	assertTrue(fs.contains(2));
	assertTrue(fs.contains(1));
}
 
Example 20
Source File: MapPartitionNode.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected SemanticProperties getSemanticPropertiesForLocalPropertyFiltering() {

	// Local properties for MapPartition may not be preserved.
	SingleInputSemanticProperties origProps =
			((SingleInputOperator<?,?,?>) getOperator()).getSemanticProperties();
	SingleInputSemanticProperties filteredProps = new SingleInputSemanticProperties();
	FieldSet readSet = origProps.getReadFields(0);
	if(readSet != null) {
		filteredProps.addReadFields(readSet);
	}

	return filteredProps;
}