Search in sources :

Example 1 with UnsupportedAggregationTypeException

use of org.apache.flink.api.java.aggregation.UnsupportedAggregationTypeException in project flink by apache.

the class AggregateOperatorTest method testAggregationTypes.

@Test
public void testAggregationTypes() {
    try {
        final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        DataSet<Tuple5<Integer, Long, String, Long, Integer>> tupleDs = env.fromCollection(emptyTupleData, tupleTypeInfo);
        // should work: multiple aggregates
        tupleDs.aggregate(Aggregations.SUM, 0).and(Aggregations.MIN, 4);
        // should work: nested aggregates
        tupleDs.aggregate(Aggregations.MIN, 2).aggregate(Aggregations.SUM, 1);
        // should not work: average on string
        try {
            tupleDs.aggregate(Aggregations.SUM, 2);
            Assert.fail();
        } catch (UnsupportedAggregationTypeException iae) {
        // we're good here
        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : Tuple5(org.apache.flink.api.java.tuple.Tuple5) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) UnsupportedAggregationTypeException(org.apache.flink.api.java.aggregation.UnsupportedAggregationTypeException) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) UnsupportedAggregationTypeException(org.apache.flink.api.java.aggregation.UnsupportedAggregationTypeException) Test(org.junit.Test)

Aggregations

InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)1 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)1 UnsupportedAggregationTypeException (org.apache.flink.api.java.aggregation.UnsupportedAggregationTypeException)1 Tuple5 (org.apache.flink.api.java.tuple.Tuple5)1 Test (org.junit.Test)1