Search in sources :

Example 41 with InvalidProgramException

use of org.apache.flink.api.common.InvalidProgramException in project flink by apache.

the class DeltaIterationTranslationTest method testRejectWhenSolutionSetKeysDontMatchJoin.

@Test
public void testRejectWhenSolutionSetKeysDontMatchJoin() {
    try {
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        @SuppressWarnings("unchecked") DataSet<Tuple3<Double, Long, String>> initialSolutionSet = env.fromElements(new Tuple3<Double, Long, String>(3.44, 5L, "abc"));
        @SuppressWarnings("unchecked") DataSet<Tuple2<Double, String>> initialWorkSet = env.fromElements(new Tuple2<Double, String>(1.23, "abc"));
        DeltaIteration<Tuple3<Double, Long, String>, Tuple2<Double, String>> iteration = initialSolutionSet.iterateDelta(initialWorkSet, 10, 1);
        try {
            iteration.getWorkset().join(iteration.getSolutionSet()).where(1).equalTo(2);
            fail("Accepted invalid program.");
        } catch (InvalidProgramException e) {
        // all good!
        }
        try {
            iteration.getSolutionSet().join(iteration.getWorkset()).where(2).equalTo(1);
            fail("Accepted invalid program.");
        } catch (InvalidProgramException e) {
        // all good!
        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Tuple3(org.apache.flink.api.java.tuple.Tuple3) Test(org.junit.Test)

Example 42 with InvalidProgramException

use of org.apache.flink.api.common.InvalidProgramException in project flink by apache.

the class OpenIterationTest method testOperationOnSolutionSet.

@Test
public void testOperationOnSolutionSet() {
    try {
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        @SuppressWarnings("unchecked") DataSet<Tuple2<Long, Long>> input = env.fromElements(new Tuple2<Long, Long>(0L, 0L));
        DeltaIteration<Tuple2<Long, Long>, Tuple2<Long, Long>> iteration = input.iterateDelta(input, 10, 0);
        DataSet<Tuple2<Long, Long>> mapped = iteration.getSolutionSet().map(new IdentityMapper<Tuple2<Long, Long>>());
        DataSet<Tuple2<Long, Long>> joined = iteration.getWorkset().join(mapped).where(0).equalTo(0).projectFirst(1).projectSecond(0);
        iteration.closeWith(joined, joined).output(new DiscardingOutputFormat<Tuple2<Long, Long>>());
        Plan p = env.createProgramPlan();
        try {
            compileNoStats(p);
            fail("should throw an exception");
        } catch (InvalidProgramException e) {
        // expected
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Plan(org.apache.flink.api.common.Plan) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) Test(org.junit.Test)

Example 43 with InvalidProgramException

use of org.apache.flink.api.common.InvalidProgramException in project flink by apache.

the class OpenIterationTest method testSinkOnSolutionSetDeltaIteration.

@Test
public void testSinkOnSolutionSetDeltaIteration() {
    try {
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        @SuppressWarnings("unchecked") DataSet<Tuple2<Long, Long>> input = env.fromElements(new Tuple2<Long, Long>(0L, 0L));
        DeltaIteration<Tuple2<Long, Long>, Tuple2<Long, Long>> iteration = input.iterateDelta(input, 10, 0);
        DataSet<Tuple2<Long, Long>> mapped = iteration.getSolutionSet().map(new IdentityMapper<Tuple2<Long, Long>>());
        mapped.output(new DiscardingOutputFormat<Tuple2<Long, Long>>());
        try {
            env.createProgramPlan();
            fail("should throw an exception");
        } catch (InvalidProgramException e) {
        // expected
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) Tuple2(org.apache.flink.api.java.tuple.Tuple2) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) Test(org.junit.Test)

Example 44 with InvalidProgramException

use of org.apache.flink.api.common.InvalidProgramException in project flink by apache.

the class FirstNOperatorTest method testGroupedSortedFirstN.

@Test
public void testGroupedSortedFirstN() {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Tuple5<Integer, Long, String, Long, Integer>> tupleDs = env.fromCollection(emptyTupleData, tupleTypeInfo);
    // should work
    try {
        tupleDs.groupBy(2).sortGroup(4, Order.ASCENDING).first(1);
    } catch (Exception e) {
        Assert.fail();
    }
    // should work
    try {
        tupleDs.groupBy(1, 3).sortGroup(4, Order.ASCENDING).first(10);
    } catch (Exception e) {
        Assert.fail();
    }
    // should not work n == 0
    try {
        tupleDs.groupBy(0).sortGroup(4, Order.ASCENDING).first(0);
        Assert.fail();
    } catch (InvalidProgramException ipe) {
    // we're good here
    } catch (Exception e) {
        Assert.fail();
    }
    // should not work n == -1
    try {
        tupleDs.groupBy(2).sortGroup(4, Order.ASCENDING).first(-1);
        Assert.fail();
    } catch (InvalidProgramException ipe) {
    // 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) Test(org.junit.Test)

Example 45 with InvalidProgramException

use of org.apache.flink.api.common.InvalidProgramException in project flink by apache.

the class FirstNOperatorTest method testUngroupedFirstN.

@Test
public void testUngroupedFirstN() {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Tuple5<Integer, Long, String, Long, Integer>> tupleDs = env.fromCollection(emptyTupleData, tupleTypeInfo);
    // should work
    try {
        tupleDs.first(1);
    } catch (Exception e) {
        Assert.fail();
    }
    // should work
    try {
        tupleDs.first(10);
    } catch (Exception e) {
        Assert.fail();
    }
    // should not work n == 0
    try {
        tupleDs.first(0);
        Assert.fail();
    } catch (InvalidProgramException ipe) {
    // we're good here
    } catch (Exception e) {
        Assert.fail();
    }
    // should not work n == -1
    try {
        tupleDs.first(-1);
        Assert.fail();
    } catch (InvalidProgramException ipe) {
    // 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) Test(org.junit.Test)

Aggregations

InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)65 Test (org.junit.Test)38 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)36 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)16 ArrayList (java.util.ArrayList)12 List (java.util.List)12 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)11 HashMap (java.util.HashMap)9 Map (java.util.Map)8 IOException (java.io.IOException)7 TaskInfo (org.apache.flink.api.common.TaskInfo)6 RuntimeUDFContext (org.apache.flink.api.common.functions.util.RuntimeUDFContext)6 Tuple5 (org.apache.flink.api.java.tuple.Tuple5)6 LinkedHashSet (java.util.LinkedHashSet)4 Aggregator (org.apache.flink.api.common.aggregators.Aggregator)4 ConvergenceCriterion (org.apache.flink.api.common.aggregators.ConvergenceCriterion)4 KeySelector (org.apache.flink.api.java.functions.KeySelector)4 InvalidTypesException (org.apache.flink.api.common.functions.InvalidTypesException)3 Configuration (org.apache.flink.configuration.Configuration)3 MetricGroup (org.apache.flink.metrics.MetricGroup)3