Search in sources :

Example 6 with DualInputSemanticProperties

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

the class SemanticPropUtilTest method testNonForwardedDualInvalidTypes2.

@Test(expected = InvalidSemanticAnnotationException.class)
public void testNonForwardedDualInvalidTypes2() {
    String[] nonNorwardedFieldsSecond = { "f1" };
    DualInputSemanticProperties dsp = new DualInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsDualFromString(dsp, null, null, null, nonNorwardedFieldsSecond, null, null, threeIntTupleType, pojoInTupleType, threeIntTupleType);
}
Also used : DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties) Test(org.junit.Test)

Example 7 with DualInputSemanticProperties

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

the class SemanticPropUtilTest method testForwardedNonForwardedSecondCheck.

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

Example 8 with DualInputSemanticProperties

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

the class CoGroupNode method getSemanticPropertiesForLocalPropertyFiltering.

@Override
protected SemanticProperties getSemanticPropertiesForLocalPropertyFiltering() {
    // Local properties for CoGroup may only be preserved on key fields.
    DualInputSemanticProperties origProps = ((DualInputOperator<?, ?, ?, ?>) getOperator()).getSemanticProperties();
    DualInputSemanticProperties filteredProps = new DualInputSemanticProperties();
    FieldSet readSet1 = origProps.getReadFields(0);
    FieldSet readSet2 = origProps.getReadFields(1);
    if (readSet1 != null) {
        filteredProps.addReadFields(0, readSet1);
    }
    if (readSet2 != null) {
        filteredProps.addReadFields(1, readSet2);
    }
    // preserve only key fields (first input)
    for (int f : this.keys1) {
        FieldSet targets = origProps.getForwardingTargetFields(0, f);
        for (int t : targets) {
            filteredProps.addForwardedField(0, f, t);
        }
    }
    // preserve only key fields (second input)
    for (int f : this.keys2) {
        FieldSet targets = origProps.getForwardingTargetFields(1, f);
        for (int t : targets) {
            filteredProps.addForwardedField(1, f, t);
        }
    }
    return filteredProps;
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) DualInputOperator(org.apache.flink.api.common.operators.DualInputOperator) DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties)

Example 9 with DualInputSemanticProperties

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

the class UdfAnalyzerTest method compareAnalyzerResultWithAnnotationsDualInputWithKeys.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void compareAnalyzerResultWithAnnotationsDualInputWithKeys(Class<?> baseClass, Class<?> clazz, String in1, String in2, String out, String[] keys1, String[] keys2) {
    final TypeInformation<?> in1Type = TypeInfoParser.parse(in1);
    final TypeInformation<?> in2Type = TypeInfoParser.parse(in2);
    final TypeInformation<?> outType = TypeInfoParser.parse(out);
    // expected
    final Set<Annotation> annotations = FunctionAnnotation.readDualForwardAnnotations(clazz);
    final DualInputSemanticProperties expected = SemanticPropUtil.getSemanticPropsDual(annotations, in1Type, in2Type, outType);
    // actual
    final UdfAnalyzer ua = new UdfAnalyzer(baseClass, clazz, "operator", in1Type, in2Type, outType, (keys1 == null) ? null : new Keys.ExpressionKeys(keys1, in1Type), (keys2 == null) ? null : new Keys.ExpressionKeys(keys2, in2Type), true);
    ua.analyze();
    final DualInputSemanticProperties actual = (DualInputSemanticProperties) ua.getSemanticProperties();
    assertEquals(expected.toString(), actual.toString());
}
Also used : DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties) FunctionAnnotation(org.apache.flink.api.java.functions.FunctionAnnotation) Annotation(java.lang.annotation.Annotation)

Example 10 with DualInputSemanticProperties

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

the class SemanticPropertiesTranslationTest method testBinaryForwardedInLine2.

@Test
public void testBinaryForwardedInLine2() {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    @SuppressWarnings("unchecked") DataSet<Tuple2<Long, Long>> input1 = env.fromElements(new Tuple2<Long, Long>(3l, 4l));
    @SuppressWarnings("unchecked") DataSet<Tuple2<Long, Long>> input2 = env.fromElements(new Tuple2<Long, Long>(3l, 2l));
    input1.join(input2).where(0).equalTo(0).with(new ReadSetJoin<Long>()).withForwardedFieldsFirst("0->1; 1->2").withForwardedFieldsSecond("1->0").output(new DiscardingOutputFormat<Tuple3<Long, Long, Long>>());
    Plan plan = env.createProgramPlan();
    GenericDataSinkBase<?> sink = plan.getDataSinks().iterator().next();
    InnerJoinOperatorBase<?, ?, ?, ?> join = (InnerJoinOperatorBase<?, ?, ?, ?>) sink.getInput();
    DualInputSemanticProperties semantics = join.getSemanticProperties();
    assertNotNull(semantics.getForwardingTargetFields(1, 0));
    assertEquals(1, semantics.getForwardingTargetFields(0, 0).size());
    assertEquals(1, semantics.getForwardingTargetFields(0, 1).size());
    assertEquals(1, semantics.getForwardingTargetFields(1, 1).size());
    assertTrue(semantics.getForwardingTargetFields(0, 0).contains(1));
    assertTrue(semantics.getForwardingTargetFields(0, 1).contains(2));
    assertTrue(semantics.getForwardingTargetFields(1, 1).contains(0));
    assertNotNull(semantics.getReadFields(0));
    assertNotNull(semantics.getReadFields(1));
    assertEquals(1, semantics.getReadFields(0).size());
    assertEquals(1, semantics.getReadFields(1).size());
    assertTrue(semantics.getReadFields(0).contains(1));
    assertTrue(semantics.getReadFields(1).contains(0));
    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) Tuple3(org.apache.flink.api.java.tuple.Tuple3) 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