Search in sources :

Example 31 with DualInputSemanticProperties

use of org.apache.flink.api.common.operators.DualInputSemanticProperties in project flink by apache.

the class SemanticPropUtilTest method testNonForwardedDual.

@Test
public void testNonForwardedDual() {
    String[] nonNorwardedFieldsFirst = { "f1;f2" };
    String[] nonNorwardedFieldsSecond = { "f0" };
    DualInputSemanticProperties dsp = new DualInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsDualFromString(dsp, null, null, nonNorwardedFieldsFirst, nonNorwardedFieldsSecond, null, null, threeIntTupleType, threeIntTupleType, threeIntTupleType);
    assertTrue(dsp.getForwardingTargetFields(0, 0).contains(0));
    assertTrue(dsp.getForwardingTargetFields(0, 1).size() == 0);
    assertTrue(dsp.getForwardingTargetFields(0, 2).size() == 0);
    assertTrue(dsp.getForwardingTargetFields(1, 0).size() == 0);
    assertTrue(dsp.getForwardingTargetFields(1, 1).contains(1));
    assertTrue(dsp.getForwardingTargetFields(1, 2).contains(2));
    nonNorwardedFieldsFirst[0] = "f1";
    nonNorwardedFieldsSecond[0] = "";
    dsp = new DualInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsDualFromString(dsp, null, null, nonNorwardedFieldsFirst, null, null, null, threeIntTupleType, fiveIntTupleType, threeIntTupleType);
    assertTrue(dsp.getForwardingTargetFields(0, 0).contains(0));
    assertTrue(dsp.getForwardingTargetFields(0, 1).size() == 0);
    assertTrue(dsp.getForwardingTargetFields(0, 2).contains(2));
    assertTrue(dsp.getForwardingTargetFields(1, 0).size() == 0);
    assertTrue(dsp.getForwardingTargetFields(1, 1).size() == 0);
    assertTrue(dsp.getForwardingTargetFields(1, 2).size() == 0);
    nonNorwardedFieldsFirst[0] = "";
    nonNorwardedFieldsSecond[0] = "f2;f0";
    dsp = new DualInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsDualFromString(dsp, null, null, null, nonNorwardedFieldsSecond, null, null, fiveIntTupleType, threeIntTupleType, threeIntTupleType);
    assertTrue(dsp.getForwardingTargetFields(0, 0).size() == 0);
    assertTrue(dsp.getForwardingTargetFields(0, 1).size() == 0);
    assertTrue(dsp.getForwardingTargetFields(0, 2).size() == 0);
    assertTrue(dsp.getForwardingTargetFields(1, 0).size() == 0);
    assertTrue(dsp.getForwardingTargetFields(1, 1).contains(1));
    assertTrue(dsp.getForwardingTargetFields(1, 2).size() == 0);
    String[] nonForwardedFields = { "f1", "f3" };
    dsp = new DualInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsDualFromString(dsp, null, null, nonForwardedFields, null, null, null, fiveIntTupleType, threeIntTupleType, fiveIntTupleType);
    assertTrue(dsp.getForwardingTargetFields(0, 0).contains(0));
    assertTrue(dsp.getForwardingTargetFields(0, 1).size() == 0);
    assertTrue(dsp.getForwardingTargetFields(0, 2).contains(2));
    assertTrue(dsp.getForwardingTargetFields(0, 3).size() == 0);
    assertTrue(dsp.getForwardingTargetFields(0, 4).contains(4));
    dsp = new DualInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsDualFromString(dsp, null, null, null, nonForwardedFields, null, null, threeIntTupleType, fiveIntTupleType, fiveIntTupleType);
    assertTrue(dsp.getForwardingTargetFields(1, 0).contains(0));
    assertTrue(dsp.getForwardingTargetFields(1, 1).size() == 0);
    assertTrue(dsp.getForwardingTargetFields(1, 2).contains(2));
    assertTrue(dsp.getForwardingTargetFields(1, 3).size() == 0);
    assertTrue(dsp.getForwardingTargetFields(1, 4).contains(4));
}
Also used : DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties) Test(org.junit.Test)

Example 32 with DualInputSemanticProperties

use of org.apache.flink.api.common.operators.DualInputSemanticProperties in project flink by apache.

the class SemanticPropUtilTest method testForwardedReadDual.

@Test
public void testForwardedReadDual() {
    String[] forwardedFieldsFirst = { "f1->f2; f2->f3" };
    String[] forwardedFieldsSecond = { "f1->f1; f2->f0" };
    String[] readFieldsFirst = { "0;2" };
    String[] readFieldsSecond = { "1" };
    DualInputSemanticProperties dsp = new DualInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsDualFromString(dsp, forwardedFieldsFirst, forwardedFieldsSecond, null, null, readFieldsFirst, readFieldsSecond, fourIntTupleType, fourIntTupleType, fourIntTupleType);
    assertTrue(dsp.getForwardingTargetFields(0, 1).contains(2));
    assertTrue(dsp.getForwardingTargetFields(0, 2).contains(3));
    assertTrue(dsp.getForwardingTargetFields(1, 1).contains(1));
    assertTrue(dsp.getForwardingTargetFields(1, 2).contains(0));
    assertTrue(dsp.getForwardingTargetFields(0, 0).size() == 0);
    assertTrue(dsp.getForwardingTargetFields(1, 3).size() == 0);
    assertTrue(dsp.getReadFields(0).size() == 2);
    assertTrue(dsp.getReadFields(0).contains(0));
    assertTrue(dsp.getReadFields(0).contains(2));
    assertTrue(dsp.getReadFields(1).size() == 1);
    assertTrue(dsp.getReadFields(1).contains(1));
}
Also used : DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties) Test(org.junit.Test)

Example 33 with DualInputSemanticProperties

use of org.apache.flink.api.common.operators.DualInputSemanticProperties in project flink by apache.

the class SemanticPropUtilTest method testAddSourceFieldOffsets.

@Test
public void testAddSourceFieldOffsets() {
    DualInputSemanticProperties semProps = new DualInputSemanticProperties();
    semProps.addForwardedField(0, 0, 1);
    semProps.addForwardedField(0, 3, 3);
    semProps.addForwardedField(1, 1, 2);
    semProps.addForwardedField(1, 1, 4);
    semProps.addReadFields(0, new FieldSet(1, 2));
    semProps.addReadFields(1, new FieldSet(0, 3, 4));
    DualInputSemanticProperties offsetProps = SemanticPropUtil.addSourceFieldOffsets(semProps, 4, 3, 1, 2);
    assertTrue(offsetProps.getForwardingTargetFields(0, 0).size() == 0);
    assertTrue(offsetProps.getForwardingTargetFields(0, 1).size() == 1);
    assertTrue(offsetProps.getForwardingTargetFields(0, 1).contains(1));
    assertTrue(offsetProps.getForwardingTargetFields(0, 2).size() == 0);
    assertTrue(offsetProps.getForwardingTargetFields(0, 3).size() == 0);
    assertTrue(offsetProps.getForwardingTargetFields(0, 4).size() == 1);
    assertTrue(offsetProps.getForwardingTargetFields(0, 4).contains(3));
    assertTrue(offsetProps.getForwardingTargetFields(1, 0).size() == 0);
    assertTrue(offsetProps.getForwardingTargetFields(1, 1).size() == 0);
    assertTrue(offsetProps.getForwardingTargetFields(1, 2).size() == 0);
    assertTrue(offsetProps.getForwardingTargetFields(1, 3).size() == 2);
    assertTrue(offsetProps.getForwardingTargetFields(1, 3).contains(2));
    assertTrue(offsetProps.getForwardingTargetFields(1, 3).contains(4));
    assertTrue(offsetProps.getReadFields(0).size() == 2);
    assertTrue(offsetProps.getReadFields(0).contains(2));
    assertTrue(offsetProps.getReadFields(0).contains(3));
    assertTrue(offsetProps.getReadFields(1).size() == 3);
    assertTrue(offsetProps.getReadFields(1).contains(2));
    assertTrue(offsetProps.getReadFields(1).contains(5));
    assertTrue(offsetProps.getReadFields(1).contains(6));
    semProps = new DualInputSemanticProperties();
    SemanticPropUtil.addSourceFieldOffsets(semProps, 4, 3, 2, 2);
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties) Test(org.junit.Test)

Example 34 with DualInputSemanticProperties

use of org.apache.flink.api.common.operators.DualInputSemanticProperties in project flink by apache.

the class SemanticPropUtilTest method testForwardedNonForwardedFirstCheck.

@Test(expected = InvalidSemanticAnnotationException.class)
public void testForwardedNonForwardedFirstCheck() {
    String[] forwarded = { "1" };
    String[] nonForwarded = { "1" };
    SemanticPropUtil.getSemanticPropsDualFromString(new DualInputSemanticProperties(), forwarded, null, nonForwarded, null, null, null, threeIntTupleType, threeIntTupleType, threeIntTupleType);
}
Also used : DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties) Test(org.junit.Test)

Example 35 with DualInputSemanticProperties

use of org.apache.flink.api.common.operators.DualInputSemanticProperties in project flink by apache.

the class SemanticPropertiesTranslationTest method testBinaryForwardedAnnotation.

@Test
public void testBinaryForwardedAnnotation() {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    @SuppressWarnings("unchecked") DataSet<Tuple2<Long, String>> input1 = env.fromElements(new Tuple2<Long, String>(3l, "test"));
    @SuppressWarnings("unchecked") DataSet<Tuple2<Long, Double>> input2 = env.fromElements(new Tuple2<Long, Double>(3l, 3.1415));
    input1.join(input2).where(0).equalTo(0).with(new ForwardedBothAnnotationJoin<Long, String, Long, Double>()).output(new DiscardingOutputFormat<Tuple2<String, Double>>());
    Plan plan = env.createProgramPlan();
    GenericDataSinkBase<?> sink = plan.getDataSinks().iterator().next();
    InnerJoinOperatorBase<?, ?, ?, ?> join = (InnerJoinOperatorBase<?, ?, ?, ?>) sink.getInput();
    DualInputSemanticProperties semantics = join.getSemanticProperties();
    assertNotNull(semantics.getForwardingTargetFields(0, 0));
    assertNotNull(semantics.getForwardingTargetFields(1, 0));
    assertEquals(1, semantics.getForwardingTargetFields(0, 1).size());
    assertEquals(1, semantics.getForwardingTargetFields(1, 1).size());
    assertTrue(semantics.getForwardingTargetFields(0, 1).contains(0));
    assertTrue(semantics.getForwardingTargetFields(1, 1).contains(1));
    assertEquals(0, semantics.getForwardingTargetFields(0, 0).size());
    assertEquals(0, semantics.getForwardingTargetFields(1, 0).size());
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Plan(org.apache.flink.api.common.Plan) DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties) Tuple2(org.apache.flink.api.java.tuple.Tuple2) InnerJoinOperatorBase(org.apache.flink.api.common.operators.base.InnerJoinOperatorBase) 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