Search in sources :

Example 26 with DualInputSemanticProperties

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;
}
Also used : DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties) SemanticProperties(org.apache.flink.api.common.operators.SemanticProperties) SingleInputSemanticProperties(org.apache.flink.api.common.operators.SingleInputSemanticProperties) SingleInputSemanticProperties(org.apache.flink.api.common.operators.SingleInputSemanticProperties) DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties)

Example 27 with DualInputSemanticProperties

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));
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Plan(org.apache.flink.api.common.Plan) DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties) Test(org.junit.Test)

Example 28 with DualInputSemanticProperties

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));
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Plan(org.apache.flink.api.common.Plan) DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties) Test(org.junit.Test)

Example 29 with DualInputSemanticProperties

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));
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Plan(org.apache.flink.api.common.Plan) DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties) Test(org.junit.Test)

Example 30 with DualInputSemanticProperties

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));
}
Also used : DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties) Test(org.junit.Test)

Aggregations

DualInputSemanticProperties (org.apache.flink.api.common.operators.DualInputSemanticProperties)36 Test (org.junit.Test)24 Plan (org.apache.flink.api.common.Plan)11 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)11 FieldSet (org.apache.flink.api.common.operators.util.FieldSet)8 InnerJoinOperatorBase (org.apache.flink.api.common.operators.base.InnerJoinOperatorBase)7 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)6 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)6 InvalidSemanticAnnotationException (org.apache.flink.api.common.operators.SemanticProperties.InvalidSemanticAnnotationException)4 SingleInputSemanticProperties (org.apache.flink.api.common.operators.SingleInputSemanticProperties)4 Matcher (java.util.regex.Matcher)3 FlatFieldDescriptor (org.apache.flink.api.common.typeutils.CompositeType.FlatFieldDescriptor)3 InvalidFieldReferenceException (org.apache.flink.api.common.typeutils.CompositeType.InvalidFieldReferenceException)3 Annotation (java.lang.annotation.Annotation)2 SemanticProperties (org.apache.flink.api.common.operators.SemanticProperties)2 DualInputOperator (org.apache.flink.api.common.operators.DualInputOperator)1 SelectorFunctionKeys (org.apache.flink.api.common.operators.Keys.SelectorFunctionKeys)1 FunctionAnnotation (org.apache.flink.api.java.functions.FunctionAnnotation)1 ForwardedFields (org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFields)1 ForwardedFieldsFirst (org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsFirst)1