Search in sources :

Example 76 with ExecutionEnvironment

use of org.apache.flink.api.java.ExecutionEnvironment in project flink by apache.

the class FromElementsTest method fromElementsWithBaseTypeTest1.

@Test
public void fromElementsWithBaseTypeTest1() {
    ExecutionEnvironment executionEnvironment = ExecutionEnvironment.getExecutionEnvironment();
    executionEnvironment.fromElements(ParentType.class, new SubType(1, "Java"), new ParentType(1, "hello"));
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Test(org.junit.Test)

Example 77 with ExecutionEnvironment

use of org.apache.flink.api.java.ExecutionEnvironment in project flink by apache.

the class AggregateOperatorTest method testFieldsAggregate.

@Test
public void testFieldsAggregate() {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Tuple5<Integer, Long, String, Long, Integer>> tupleDs = env.fromCollection(emptyTupleData, tupleTypeInfo);
    // should work
    try {
        tupleDs.aggregate(Aggregations.SUM, 1);
    } catch (Exception e) {
        Assert.fail();
    }
    // should not work: index out of bounds
    try {
        tupleDs.aggregate(Aggregations.SUM, 10);
        Assert.fail();
    } catch (IllegalArgumentException iae) {
    // we're good here
    } catch (Exception e) {
        Assert.fail();
    }
    // should not work: not applied to tuple dataset
    DataSet<Long> longDs = env.fromCollection(emptyLongData, BasicTypeInfo.LONG_TYPE_INFO);
    try {
        longDs.aggregate(Aggregations.MIN, 1);
        Assert.fail();
    } catch (InvalidProgramException uoe) {
    // we're good here
    } catch (Exception e) {
        Assert.fail();
    }
}
Also used : Tuple5(org.apache.flink.api.java.tuple.Tuple5) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) UnsupportedAggregationTypeException(org.apache.flink.api.java.aggregation.UnsupportedAggregationTypeException) Test(org.junit.Test)

Example 78 with ExecutionEnvironment

use of org.apache.flink.api.java.ExecutionEnvironment 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)

Example 79 with ExecutionEnvironment

use of org.apache.flink.api.java.ExecutionEnvironment in project flink by apache.

the class CoGroupOperatorTest method testCoGroupKeyFields4.

@Test(expected = IndexOutOfBoundsException.class)
public void testCoGroupKeyFields4() {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds1 = env.fromCollection(emptyTupleData, tupleTypeInfo);
    DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds2 = env.fromCollection(emptyTupleData, tupleTypeInfo);
    // should not work, cogroup key out of range
    ds1.coGroup(ds2).where(5).equalTo(0);
}
Also used : Tuple5(org.apache.flink.api.java.tuple.Tuple5) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Test(org.junit.Test)

Example 80 with ExecutionEnvironment

use of org.apache.flink.api.java.ExecutionEnvironment in project flink by apache.

the class CoGroupOperatorTest method testCoGroupKeyExpressions4Nested.

@Test(expected = IllegalArgumentException.class)
public void testCoGroupKeyExpressions4Nested() {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<CustomType> ds1 = env.fromCollection(customTypeData);
    DataSet<CustomType> ds2 = env.fromCollection(customTypeData);
    // should not work, cogroup key non-existent
    ds1.coGroup(ds2).where("nested.myNonExistent").equalTo("nested.myInt");
}
Also used : CustomType(org.apache.flink.api.java.operator.JoinOperatorTest.CustomType) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Test(org.junit.Test)

Aggregations

ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)1247 Test (org.junit.Test)1090 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)374 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)264 Plan (org.apache.flink.api.common.Plan)238 Tuple5 (org.apache.flink.api.java.tuple.Tuple5)236 OptimizedPlan (org.apache.flink.optimizer.plan.OptimizedPlan)199 SinkPlanNode (org.apache.flink.optimizer.plan.SinkPlanNode)139 InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)138 Vertex (org.apache.flink.graph.Vertex)93 SingleInputPlanNode (org.apache.flink.optimizer.plan.SingleInputPlanNode)73 Edge (org.apache.flink.graph.Edge)70 DualInputPlanNode (org.apache.flink.optimizer.plan.DualInputPlanNode)66 ArrayList (java.util.ArrayList)57 Tuple1 (org.apache.flink.api.java.tuple.Tuple1)49 SourcePlanNode (org.apache.flink.optimizer.plan.SourcePlanNode)44 DiscardingOutputFormat (org.apache.flink.api.java.io.DiscardingOutputFormat)39 BatchTableEnvironment (org.apache.flink.table.api.java.BatchTableEnvironment)38 FieldSet (org.apache.flink.api.common.operators.util.FieldSet)37 JobGraphGenerator (org.apache.flink.optimizer.plantranslate.JobGraphGenerator)35