Search in sources :

Example 16 with InvalidProgramException

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

the class LocalEnvironment method validateAndGetConfiguration.

private static Configuration validateAndGetConfiguration(final Configuration configuration) {
    if (!ExecutionEnvironment.areExplicitEnvironmentsAllowed()) {
        throw new InvalidProgramException("The LocalEnvironment cannot be instantiated when running in a pre-defined context " + "(such as Command Line Client or TestEnvironment)");
    }
    final Configuration effectiveConfiguration = new Configuration(checkNotNull(configuration));
    effectiveConfiguration.set(DeploymentOptions.TARGET, "local");
    effectiveConfiguration.set(DeploymentOptions.ATTACHED, true);
    return effectiveConfiguration;
}
Also used : Configuration(org.apache.flink.configuration.Configuration) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException)

Example 17 with InvalidProgramException

use of org.apache.flink.api.common.InvalidProgramException 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 18 with InvalidProgramException

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

the class FirstNOperatorTest method testGroupedFirstN.

@Test
public void testGroupedFirstN() {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Tuple5<Integer, Long, String, Long, Integer>> tupleDs = env.fromCollection(emptyTupleData, tupleTypeInfo);
    // should work
    try {
        tupleDs.groupBy(2).first(1);
    } catch (Exception e) {
        Assert.fail();
    }
    // should work
    try {
        tupleDs.groupBy(1, 3).first(10);
    } catch (Exception e) {
        Assert.fail();
    }
    // should not work n == 0
    try {
        tupleDs.groupBy(0).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).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 19 with InvalidProgramException

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

the class GroupingKeySelectorTranslationTest method testCustomPartitioningTupleRejectCompositeKey.

@Test
public void testCustomPartitioningTupleRejectCompositeKey() {
    try {
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        DataSet<Tuple3<Integer, Integer, Integer>> data = env.fromElements(new Tuple3<Integer, Integer, Integer>(0, 0, 0)).rebalance().setParallelism(4);
        try {
            data.groupBy(new TestBinaryKeySelector<Tuple3<Integer, Integer, Integer>>()).withPartitioner(new TestPartitionerInt());
            fail("Should throw an exception");
        } catch (InvalidProgramException e) {
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) Tuple3(org.apache.flink.api.java.tuple.Tuple3) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) Test(org.junit.Test)

Example 20 with InvalidProgramException

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

the class GroupingKeySelectorTranslationTest method testCustomPartitioningKeySelectorInvalidTypeSorted.

@Test
public void testCustomPartitioningKeySelectorInvalidTypeSorted() {
    try {
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        DataSet<Tuple3<Integer, Integer, Integer>> data = env.fromElements(new Tuple3<Integer, Integer, Integer>(0, 0, 0)).rebalance().setParallelism(4);
        try {
            data.groupBy(new TestKeySelector<Tuple3<Integer, Integer, Integer>>()).sortGroup(1, Order.ASCENDING).withPartitioner(new TestPartitionerLong());
            fail("Should throw an exception");
        } catch (InvalidProgramException e) {
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) Tuple3(org.apache.flink.api.java.tuple.Tuple3) 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