Search in sources :

Example 6 with InvalidProgramException

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

the class OpenIterationTest method testSinkInOpenBulkIteration.

@Test
public void testSinkInOpenBulkIteration() {
    try {
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        DataSet<Long> input = env.generateSequence(1, 10);
        IterativeDataSet<Long> iteration = input.iterate(10);
        DataSet<Long> mapped = iteration.map(new IdentityMapper<Long>());
        mapped.output(new DiscardingOutputFormat<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) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) Test(org.junit.Test)

Example 7 with InvalidProgramException

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

the class OpenIterationTest method testSinkOnWorksetDeltaIteration.

@Test
public void testSinkOnWorksetDeltaIteration() {
    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.getWorkset().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 8 with InvalidProgramException

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

the class OpenIterationTest method testSinkInClosedBulkIteration.

@Test
public void testSinkInClosedBulkIteration() {
    try {
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        DataSet<Long> input = env.generateSequence(1, 10);
        IterativeDataSet<Long> iteration = input.iterate(10);
        DataSet<Long> mapped = iteration.map(new IdentityMapper<Long>());
        iteration.closeWith(mapped).output(new DiscardingOutputFormat<Long>());
        mapped.output(new DiscardingOutputFormat<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) Plan(org.apache.flink.api.common.Plan) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) Test(org.junit.Test)

Example 9 with InvalidProgramException

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

the class ExistingSavepoint method readKeyedState.

/**
 * Read keyed state from an operator in a {@code Savepoint}.
 *
 * @param uid The uid of the operator.
 * @param function The {@link KeyedStateReaderFunction} that is called for each key in state.
 * @param <K> The type of the key in state.
 * @param <OUT> The output type of the transform function.
 * @return A {@code DataSet} of objects read from keyed state.
 * @throws IOException If the savepoint does not contain operator state with the given uid.
 */
public <K, OUT> DataSource<OUT> readKeyedState(String uid, KeyedStateReaderFunction<K, OUT> function) throws IOException {
    TypeInformation<K> keyTypeInfo;
    TypeInformation<OUT> outType;
    try {
        keyTypeInfo = TypeExtractor.createTypeInfo(KeyedStateReaderFunction.class, function.getClass(), 0, null, null);
    } catch (InvalidTypesException e) {
        throw new InvalidProgramException("The key type of the KeyedStateReaderFunction could not be automatically determined. Please use " + "Savepoint#readKeyedState(String, KeyedStateReaderFunction, TypeInformation, TypeInformation) instead.", e);
    }
    try {
        outType = TypeExtractor.getUnaryOperatorReturnType(function, KeyedStateReaderFunction.class, 0, 1, TypeExtractor.NO_INDEX, keyTypeInfo, Utils.getCallLocationName(), false);
    } catch (InvalidTypesException e) {
        throw new InvalidProgramException("The output type of the KeyedStateReaderFunction could not be automatically determined. Please use " + "Savepoint#readKeyedState(String, KeyedStateReaderFunction, TypeInformation, TypeInformation) instead.", e);
    }
    return readKeyedState(uid, function, keyTypeInfo, outType);
}
Also used : InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) KeyedStateReaderFunction(org.apache.flink.state.api.functions.KeyedStateReaderFunction) InvalidTypesException(org.apache.flink.api.common.functions.InvalidTypesException)

Example 10 with InvalidProgramException

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

the class SavepointReader method readKeyedState.

/**
 * Read keyed state from an operator in a {@code Savepoint}.
 *
 * @param uid The uid of the operator.
 * @param function The {@link KeyedStateReaderFunction} that is called for each key in state.
 * @param <K> The type of the key in state.
 * @param <OUT> The output type of the transform function.
 * @return A {@code DataStream} of objects read from keyed state.
 * @throws IOException If the savepoint does not contain operator state with the given uid.
 */
public <K, OUT> DataStream<OUT> readKeyedState(String uid, KeyedStateReaderFunction<K, OUT> function) throws IOException {
    TypeInformation<K> keyTypeInfo;
    TypeInformation<OUT> outType;
    try {
        keyTypeInfo = TypeExtractor.createTypeInfo(KeyedStateReaderFunction.class, function.getClass(), 0, null, null);
    } catch (InvalidTypesException e) {
        throw new InvalidProgramException("The key type of the KeyedStateReaderFunction could not be automatically determined. Please use " + "Savepoint#readKeyedState(String, KeyedStateReaderFunction, TypeInformation, TypeInformation) instead.", e);
    }
    try {
        outType = TypeExtractor.getUnaryOperatorReturnType(function, KeyedStateReaderFunction.class, 0, 1, TypeExtractor.NO_INDEX, keyTypeInfo, Utils.getCallLocationName(), false);
    } catch (InvalidTypesException e) {
        throw new InvalidProgramException("The output type of the KeyedStateReaderFunction could not be automatically determined. Please use " + "Savepoint#readKeyedState(String, KeyedStateReaderFunction, TypeInformation, TypeInformation) instead.", e);
    }
    return readKeyedState(uid, function, keyTypeInfo, outType);
}
Also used : InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) KeyedStateReaderFunction(org.apache.flink.state.api.functions.KeyedStateReaderFunction) InvalidTypesException(org.apache.flink.api.common.functions.InvalidTypesException)

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