use of org.apache.flink.api.common.operators.DualInputSemanticProperties in project flink by apache.
the class UdfAnalyzer method getSemanticProperties.
public SemanticProperties getSemanticProperties() {
final SemanticProperties sp;
if (isBinary) {
sp = new DualInputSemanticProperties();
if (returnValue != null) {
String[] ff1Array = null;
final String ff1 = returnValue.toForwardedFieldsExpression(Input.INPUT_1);
if (ff1 != null && ff1.length() > 0) {
ff1Array = new String[] { ff1 };
}
String[] ff2Array = null;
final String ff2 = returnValue.toForwardedFieldsExpression(Input.INPUT_2);
if (ff2 != null && ff2.length() > 0) {
ff2Array = new String[] { ff2 };
}
SemanticPropUtil.getSemanticPropsDualFromString((DualInputSemanticProperties) sp, ff1Array, ff2Array, null, null, null, null, in1Type, in2Type, outType, true);
}
} else {
sp = new SingleInputSemanticProperties();
if (returnValue != null) {
String[] ffArray = null;
final String ff = returnValue.toForwardedFieldsExpression(Input.INPUT_1);
if (ff != null && ff.length() > 0) {
ffArray = new String[] { ff };
}
SemanticPropUtil.getSemanticPropsSingleFromString((SingleInputSemanticProperties) sp, ffArray, null, null, in1Type, outType, true);
}
}
return sp;
}
use of org.apache.flink.api.common.operators.DualInputSemanticProperties in project flink by apache.
the class SemanticPropertiesProjectionTest method testCrossProjectionSemProps2.
@Test
public void testCrossProjectionSemProps2() {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple4<Integer, Tuple3<String, Integer, Long>, Tuple2<Long, Long>, String>> tupleDs = env.fromCollection(emptyNestedTupleData, nestedTupleTypeInfo);
tupleDs.cross(tupleDs).projectFirst(2, 0).projectSecond(1, 3).output(new DiscardingOutputFormat<Tuple>());
Plan plan = env.createProgramPlan();
GenericDataSinkBase<?> sink = plan.getDataSinks().iterator().next();
CrossOperatorBase<?, ?, ?, ?> projectCrossOperator = ((CrossOperatorBase<?, ?, ?, ?>) sink.getInput());
DualInputSemanticProperties props = projectCrossOperator.getSemanticProperties();
assertEquals(1, props.getForwardingTargetFields(0, 0).size());
assertNotNull(props.getForwardingTargetFields(0, 1));
assertNotNull(props.getForwardingTargetFields(0, 2));
assertNotNull(props.getForwardingTargetFields(0, 3));
assertEquals(1, props.getForwardingTargetFields(0, 4).size());
assertEquals(1, props.getForwardingTargetFields(0, 5).size());
assertNotNull(props.getForwardingTargetFields(0, 6));
assertEquals(0, props.getForwardingTargetFields(0, 1).size());
assertEquals(0, props.getForwardingTargetFields(0, 2).size());
assertEquals(0, props.getForwardingTargetFields(0, 3).size());
assertEquals(0, props.getForwardingTargetFields(0, 6).size());
assertNotNull(props.getForwardingTargetFields(1, 0));
assertEquals(1, props.getForwardingTargetFields(1, 1).size());
assertEquals(1, props.getForwardingTargetFields(1, 2).size());
assertEquals(1, props.getForwardingTargetFields(1, 3).size());
assertNotNull(props.getForwardingTargetFields(1, 4));
assertNotNull(props.getForwardingTargetFields(1, 5));
assertEquals(1, props.getForwardingTargetFields(1, 6).size());
assertEquals(0, props.getForwardingTargetFields(1, 0).size());
assertEquals(0, props.getForwardingTargetFields(1, 4).size());
assertEquals(0, props.getForwardingTargetFields(1, 5).size());
assertTrue(props.getForwardingTargetFields(0, 4).contains(0));
assertTrue(props.getForwardingTargetFields(0, 5).contains(1));
assertTrue(props.getForwardingTargetFields(0, 0).contains(2));
assertTrue(props.getForwardingTargetFields(1, 1).contains(3));
assertTrue(props.getForwardingTargetFields(1, 2).contains(4));
assertTrue(props.getForwardingTargetFields(1, 3).contains(5));
assertTrue(props.getForwardingTargetFields(1, 6).contains(6));
}
use of org.apache.flink.api.common.operators.DualInputSemanticProperties in project flink by apache.
the class SemanticPropertiesProjectionTest method testCrossProjectionSemProps1.
@Test
public void testCrossProjectionSemProps1() {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple5<Integer, Long, String, Long, Integer>> tupleDs = env.fromCollection(emptyTupleData, tupleTypeInfo);
tupleDs.cross(tupleDs).projectFirst(2, 3).projectSecond(1, 4).output(new DiscardingOutputFormat<Tuple>());
Plan plan = env.createProgramPlan();
GenericDataSinkBase<?> sink = plan.getDataSinks().iterator().next();
CrossOperatorBase<?, ?, ?, ?> projectCrossOperator = ((CrossOperatorBase<?, ?, ?, ?>) sink.getInput());
DualInputSemanticProperties props = projectCrossOperator.getSemanticProperties();
assertEquals(1, props.getForwardingTargetFields(0, 2).size());
assertEquals(1, props.getForwardingTargetFields(0, 3).size());
assertEquals(1, props.getForwardingTargetFields(1, 1).size());
assertEquals(1, props.getForwardingTargetFields(1, 4).size());
assertTrue(props.getForwardingTargetFields(0, 2).contains(0));
assertTrue(props.getForwardingTargetFields(0, 3).contains(1));
assertTrue(props.getForwardingTargetFields(1, 1).contains(2));
assertTrue(props.getForwardingTargetFields(1, 4).contains(3));
}
use of org.apache.flink.api.common.operators.DualInputSemanticProperties in project flink by apache.
the class SemanticPropertiesProjectionTest method testJoinProjectionSemProps2.
@Test
public void testJoinProjectionSemProps2() {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple4<Integer, Tuple3<String, Integer, Long>, Tuple2<Long, Long>, String>> tupleDs = env.fromCollection(emptyNestedTupleData, nestedTupleTypeInfo);
tupleDs.join(tupleDs).where(0).equalTo(0).projectFirst(2, 0).projectSecond(1, 3).output(new DiscardingOutputFormat<Tuple>());
Plan plan = env.createProgramPlan();
GenericDataSinkBase<?> sink = plan.getDataSinks().iterator().next();
InnerJoinOperatorBase<?, ?, ?, ?> projectJoinOperator = ((InnerJoinOperatorBase<?, ?, ?, ?>) sink.getInput());
DualInputSemanticProperties props = projectJoinOperator.getSemanticProperties();
assertEquals(1, props.getForwardingTargetFields(0, 0).size());
assertNotNull(props.getForwardingTargetFields(0, 1));
assertNotNull(props.getForwardingTargetFields(0, 2));
assertNotNull(props.getForwardingTargetFields(0, 3));
assertEquals(1, props.getForwardingTargetFields(0, 4).size());
assertEquals(1, props.getForwardingTargetFields(0, 5).size());
assertNotNull(props.getForwardingTargetFields(0, 6));
assertEquals(0, props.getForwardingTargetFields(0, 1).size());
assertEquals(0, props.getForwardingTargetFields(0, 2).size());
assertEquals(0, props.getForwardingTargetFields(0, 3).size());
assertEquals(0, props.getForwardingTargetFields(0, 6).size());
assertNotNull(props.getForwardingTargetFields(1, 0));
assertEquals(1, props.getForwardingTargetFields(1, 1).size());
assertEquals(1, props.getForwardingTargetFields(1, 2).size());
assertEquals(1, props.getForwardingTargetFields(1, 3).size());
assertNotNull(props.getForwardingTargetFields(1, 4));
assertNotNull(props.getForwardingTargetFields(1, 5));
assertEquals(1, props.getForwardingTargetFields(1, 6).size());
assertEquals(0, props.getForwardingTargetFields(1, 0).size());
assertEquals(0, props.getForwardingTargetFields(1, 4).size());
assertEquals(0, props.getForwardingTargetFields(1, 5).size());
assertTrue(props.getForwardingTargetFields(0, 4).contains(0));
assertTrue(props.getForwardingTargetFields(0, 5).contains(1));
assertTrue(props.getForwardingTargetFields(0, 0).contains(2));
assertTrue(props.getForwardingTargetFields(1, 1).contains(3));
assertTrue(props.getForwardingTargetFields(1, 2).contains(4));
assertTrue(props.getForwardingTargetFields(1, 3).contains(5));
assertTrue(props.getForwardingTargetFields(1, 6).contains(6));
}
use of org.apache.flink.api.common.operators.DualInputSemanticProperties in project flink by apache.
the class SemanticPropUtilTest method testReadFieldsDual.
@Test
public void testReadFieldsDual() {
String[] readFieldsFirst = { "f1;f2" };
String[] readFieldsSecond = { "f0" };
DualInputSemanticProperties dsp = new DualInputSemanticProperties();
SemanticPropUtil.getSemanticPropsDualFromString(dsp, null, null, null, null, readFieldsFirst, readFieldsSecond, threeIntTupleType, threeIntTupleType, threeIntTupleType);
assertTrue(dsp.getReadFields(0).size() == 2);
assertTrue(dsp.getReadFields(0).contains(1));
assertTrue(dsp.getReadFields(0).contains(2));
assertTrue(dsp.getReadFields(1).size() == 1);
assertTrue(dsp.getReadFields(1).contains(0));
readFieldsFirst[0] = "f0.*; f2";
readFieldsSecond[0] = "int1; string1";
dsp = new DualInputSemanticProperties();
SemanticPropUtil.getSemanticPropsDualFromString(dsp, null, null, null, null, readFieldsFirst, readFieldsSecond, nestedTupleType, pojoType, threeIntTupleType);
assertTrue(dsp.getReadFields(0).size() == 4);
assertTrue(dsp.getReadFields(0).contains(0));
assertTrue(dsp.getReadFields(0).contains(1));
assertTrue(dsp.getReadFields(0).contains(2));
assertTrue(dsp.getReadFields(0).contains(4));
assertTrue(dsp.getReadFields(1).size() == 2);
assertTrue(dsp.getReadFields(1).contains(0));
assertTrue(dsp.getReadFields(1).contains(3));
readFieldsFirst[0] = "pojo1.int2; string1";
readFieldsSecond[0] = "f2.int2";
dsp = new DualInputSemanticProperties();
SemanticPropUtil.getSemanticPropsDualFromString(dsp, null, null, null, null, readFieldsFirst, readFieldsSecond, nestedPojoType, pojoInTupleType, threeIntTupleType);
assertTrue(dsp.getReadFields(0).size() == 2);
assertTrue(dsp.getReadFields(0).contains(2));
assertTrue(dsp.getReadFields(0).contains(5));
assertTrue(dsp.getReadFields(1).size() == 1);
assertTrue(dsp.getReadFields(1).contains(3));
String[] readFields = { "f0", "f2", "f4" };
dsp = new DualInputSemanticProperties();
SemanticPropUtil.getSemanticPropsDualFromString(dsp, null, null, null, null, readFields, readFields, fiveIntTupleType, fiveIntTupleType, threeIntTupleType);
assertTrue(dsp.getReadFields(0).size() == 3);
assertTrue(dsp.getReadFields(0).contains(0));
assertTrue(dsp.getReadFields(0).contains(2));
assertTrue(dsp.getReadFields(0).contains(4));
assertTrue(dsp.getReadFields(1).size() == 3);
assertTrue(dsp.getReadFields(1).contains(0));
assertTrue(dsp.getReadFields(1).contains(2));
assertTrue(dsp.getReadFields(1).contains(4));
}
Aggregations