Search in sources :

Example 56 with SingleInputSemanticProperties

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

the class RequestedGlobalPropertiesFilteringTest method testAnyPartitioningPreserved1.

@Test
public void testAnyPartitioningPreserved1() {
    SingleInputSemanticProperties sProp = new SingleInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsSingleFromString(sProp, new String[] { "0;3;4" }, null, null, tupleInfo, tupleInfo);
    RequestedGlobalProperties rgProps = new RequestedGlobalProperties();
    rgProps.setAnyPartitioning(new FieldSet(0, 3, 4));
    RequestedGlobalProperties filtered = rgProps.filterBySemanticProperties(sProp, 0);
    assertNotNull(filtered);
    assertEquals(PartitioningProperty.ANY_PARTITIONING, filtered.getPartitioning());
    assertNotNull(filtered.getPartitionedFields());
    assertEquals(3, filtered.getPartitionedFields().size());
    assertTrue(filtered.getPartitionedFields().contains(0));
    assertTrue(filtered.getPartitionedFields().contains(3));
    assertTrue(filtered.getPartitionedFields().contains(4));
    assertNull(filtered.getDataDistribution());
    assertNull(filtered.getCustomPartitioner());
    assertNull(filtered.getOrdering());
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) SingleInputSemanticProperties(org.apache.flink.api.common.operators.SingleInputSemanticProperties) Test(org.junit.Test)

Example 57 with SingleInputSemanticProperties

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

the class RequestedLocalPropertiesFilteringTest method testGroupingPreserved2.

@Test
public void testGroupingPreserved2() {
    SingleInputSemanticProperties sProps = new SingleInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsSingleFromString(sProps, new String[] { "3->0;5->2;1->3" }, null, null, tupleInfo, tupleInfo);
    RequestedLocalProperties rlProp = new RequestedLocalProperties();
    rlProp.setGroupedFields(new FieldSet(0, 2, 3));
    RequestedLocalProperties filtered = rlProp.filterBySemanticProperties(sProps, 0);
    assertNotNull(filtered);
    assertNotNull(filtered.getGroupedFields());
    assertEquals(3, filtered.getGroupedFields().size());
    assertTrue(filtered.getGroupedFields().contains(3));
    assertTrue(filtered.getGroupedFields().contains(5));
    assertTrue(filtered.getGroupedFields().contains(1));
    assertNull(filtered.getOrdering());
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) SingleInputSemanticProperties(org.apache.flink.api.common.operators.SingleInputSemanticProperties) Test(org.junit.Test)

Example 58 with SingleInputSemanticProperties

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

the class RequestedLocalPropertiesFilteringTest method testGroupingErased.

@Test
public void testGroupingErased() {
    SingleInputSemanticProperties sProps = new SingleInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsSingleFromString(sProps, new String[] { "0;2" }, null, null, tupleInfo, tupleInfo);
    RequestedLocalProperties rlProp = new RequestedLocalProperties();
    rlProp.setGroupedFields(new FieldSet(0, 2, 3));
    RequestedLocalProperties filtered = rlProp.filterBySemanticProperties(sProps, 0);
    assertNull(filtered);
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) SingleInputSemanticProperties(org.apache.flink.api.common.operators.SingleInputSemanticProperties) Test(org.junit.Test)

Example 59 with SingleInputSemanticProperties

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

the class ScalaAggregateOperator method translateToDataFlow.

@SuppressWarnings("unchecked")
@Override
protected org.apache.flink.api.common.operators.base.GroupReduceOperatorBase<IN, IN, GroupReduceFunction<IN, IN>> translateToDataFlow(Operator<IN> input) {
    // sanity check
    if (this.aggregationFunctions.isEmpty() || this.aggregationFunctions.size() != this.fields.size()) {
        throw new IllegalStateException();
    }
    // construct the aggregation function
    AggregationFunction<Object>[] aggFunctions = new AggregationFunction[this.aggregationFunctions.size()];
    int[] fields = new int[this.fields.size()];
    StringBuilder genName = new StringBuilder();
    for (int i = 0; i < fields.length; i++) {
        aggFunctions[i] = (AggregationFunction<Object>) this.aggregationFunctions.get(i);
        fields[i] = this.fields.get(i);
        genName.append(aggFunctions[i].toString()).append('(').append(fields[i]).append(')').append(',');
    }
    genName.setLength(genName.length() - 1);
    @SuppressWarnings("rawtypes") RichGroupReduceFunction<IN, IN> function = new AggregatingUdf(getInputType(), aggFunctions, fields);
    String name = getName() != null ? getName() : genName.toString();
    // distinguish between grouped reduce and non-grouped reduce
    if (this.grouping == null) {
        // non grouped aggregation
        UnaryOperatorInformation<IN, IN> operatorInfo = new UnaryOperatorInformation<>(getInputType(), getResultType());
        GroupReduceOperatorBase<IN, IN, GroupReduceFunction<IN, IN>> po = new GroupReduceOperatorBase<IN, IN, GroupReduceFunction<IN, IN>>(function, operatorInfo, new int[0], name);
        po.setCombinable(true);
        // set input
        po.setInput(input);
        // set parallelism
        po.setParallelism(this.getParallelism());
        return po;
    }
    if (this.grouping.getKeys() instanceof Keys.ExpressionKeys) {
        // grouped aggregation
        int[] logicalKeyPositions = this.grouping.getKeys().computeLogicalKeyPositions();
        UnaryOperatorInformation<IN, IN> operatorInfo = new UnaryOperatorInformation<>(getInputType(), getResultType());
        GroupReduceOperatorBase<IN, IN, GroupReduceFunction<IN, IN>> po = new GroupReduceOperatorBase<IN, IN, GroupReduceFunction<IN, IN>>(function, operatorInfo, logicalKeyPositions, name);
        po.setCombinable(true);
        // set input
        po.setInput(input);
        // set parallelism
        po.setParallelism(this.getParallelism());
        SingleInputSemanticProperties props = new SingleInputSemanticProperties();
        for (int keyField : logicalKeyPositions) {
            boolean keyFieldUsedInAgg = false;
            for (int aggField : fields) {
                if (keyField == aggField) {
                    keyFieldUsedInAgg = true;
                    break;
                }
            }
            if (!keyFieldUsedInAgg) {
                props.addForwardedField(keyField, keyField);
            }
        }
        po.setSemanticProperties(props);
        po.setCustomPartitioner(grouping.getCustomPartitioner());
        return po;
    } else if (this.grouping.getKeys() instanceof Keys.SelectorFunctionKeys) {
        throw new UnsupportedOperationException("Aggregate does not support grouping with KeySelector functions, yet.");
    } else {
        throw new UnsupportedOperationException("Unrecognized key type.");
    }
}
Also used : RichGroupReduceFunction(org.apache.flink.api.common.functions.RichGroupReduceFunction) GroupReduceFunction(org.apache.flink.api.common.functions.GroupReduceFunction) AggregationFunction(org.apache.flink.api.java.aggregation.AggregationFunction) UnaryOperatorInformation(org.apache.flink.api.common.operators.UnaryOperatorInformation) Keys(org.apache.flink.api.common.operators.Keys) GroupReduceOperatorBase(org.apache.flink.api.common.operators.base.GroupReduceOperatorBase) SingleInputSemanticProperties(org.apache.flink.api.common.operators.SingleInputSemanticProperties)

Example 60 with SingleInputSemanticProperties

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

the class SemanticPropUtilTest method testNonForwardedInvalidTypes5.

@Test(expected = InvalidSemanticAnnotationException.class)
public void testNonForwardedInvalidTypes5() {
    String[] nonForwardedFields = { "int1" };
    SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsSingleFromString(sp, null, nonForwardedFields, null, pojoType, pojo2Type);
}
Also used : SingleInputSemanticProperties(org.apache.flink.api.common.operators.SingleInputSemanticProperties) Test(org.junit.Test)

Aggregations

SingleInputSemanticProperties (org.apache.flink.api.common.operators.SingleInputSemanticProperties)149 Test (org.junit.Test)131 FieldSet (org.apache.flink.api.common.operators.util.FieldSet)57 FieldList (org.apache.flink.api.common.operators.util.FieldList)26 Ordering (org.apache.flink.api.common.operators.Ordering)15 Plan (org.apache.flink.api.common.Plan)14 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)14 MapOperatorBase (org.apache.flink.api.common.operators.base.MapOperatorBase)12 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)12 DualInputSemanticProperties (org.apache.flink.api.common.operators.DualInputSemanticProperties)5 SemanticProperties (org.apache.flink.api.common.operators.SemanticProperties)5 Internal (org.apache.flink.annotation.Internal)4 SelectorFunctionKeys (org.apache.flink.api.common.operators.Keys.SelectorFunctionKeys)4 InvalidSemanticAnnotationException (org.apache.flink.api.common.operators.SemanticProperties.InvalidSemanticAnnotationException)4 Matcher (java.util.regex.Matcher)3 UnaryOperatorInformation (org.apache.flink.api.common.operators.UnaryOperatorInformation)3 FlatFieldDescriptor (org.apache.flink.api.common.typeutils.CompositeType.FlatFieldDescriptor)3 InvalidFieldReferenceException (org.apache.flink.api.common.typeutils.CompositeType.InvalidFieldReferenceException)3 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)3 Annotation (java.lang.annotation.Annotation)2