Search in sources :

Example 46 with DiscardingOutputFormat

use of org.apache.flink.api.java.io.DiscardingOutputFormat in project flink by apache.

the class InputOutputFormatContainerTest method testInputOutputFormat.

@Test
public void testInputOutputFormat() {
    InputOutputFormatContainer formatContainer = new InputOutputFormatContainer(Thread.currentThread().getContextClassLoader());
    OperatorID operatorID1 = new OperatorID();
    formatContainer.addInputFormat(operatorID1, new TestInputFormat("test input format"));
    formatContainer.addParameters(operatorID1, "parameter1", "abc123");
    OperatorID operatorID2 = new OperatorID();
    formatContainer.addOutputFormat(operatorID2, new DiscardingOutputFormat());
    formatContainer.addParameters(operatorID2, "parameter1", "bcd234");
    OperatorID operatorID3 = new OperatorID();
    formatContainer.addOutputFormat(operatorID3, new DiscardingOutputFormat());
    formatContainer.addParameters(operatorID3, "parameter1", "cde345");
    TaskConfig taskConfig = new TaskConfig(new Configuration());
    formatContainer.write(taskConfig);
    InputOutputFormatContainer loadedFormatContainer = new InputOutputFormatContainer(taskConfig, getClass().getClassLoader());
    Map<OperatorID, UserCodeWrapper<? extends InputFormat<?, ?>>> inputFormats = loadedFormatContainer.getInputFormats();
    Map<OperatorID, UserCodeWrapper<? extends OutputFormat<?>>> outputFormats = loadedFormatContainer.getOutputFormats();
    assertEquals(1, inputFormats.size());
    assertEquals(2, outputFormats.size());
    // verify the input format
    TestInputFormat inputFormat = (TestInputFormat) inputFormats.get(operatorID1).getUserCodeObject();
    assertEquals("test input format", inputFormat.getName());
    Configuration inputFormatParams = loadedFormatContainer.getParameters(operatorID1);
    assertEquals(1, inputFormatParams.keySet().size());
    assertEquals("abc123", inputFormatParams.getString("parameter1", null));
    // verify the output formats
    assertTrue(outputFormats.get(operatorID2).getUserCodeObject() instanceof DiscardingOutputFormat);
    Configuration outputFormatParams1 = loadedFormatContainer.getParameters(operatorID2);
    assertEquals(1, outputFormatParams1.keySet().size());
    assertEquals("bcd234", outputFormatParams1.getString("parameter1", null));
    assertTrue(outputFormats.get(operatorID3).getUserCodeObject() instanceof DiscardingOutputFormat);
    Configuration outputFormatParams2 = loadedFormatContainer.getParameters(operatorID3);
    assertEquals(1, outputFormatParams2.keySet().size());
    assertEquals("cde345", outputFormatParams2.getString("parameter1", null));
}
Also used : Configuration(org.apache.flink.configuration.Configuration) GenericInputFormat(org.apache.flink.api.common.io.GenericInputFormat) InputFormat(org.apache.flink.api.common.io.InputFormat) DiscardingOutputFormat(org.apache.flink.api.java.io.DiscardingOutputFormat) OutputFormat(org.apache.flink.api.common.io.OutputFormat) TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) UserCodeWrapper(org.apache.flink.api.common.operators.util.UserCodeWrapper) DiscardingOutputFormat(org.apache.flink.api.java.io.DiscardingOutputFormat) Test(org.junit.Test)

Example 47 with DiscardingOutputFormat

use of org.apache.flink.api.java.io.DiscardingOutputFormat in project flink by apache.

the class ErrorHandlingSubmissionJob method main.

public static void main(String[] args) throws Exception {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.fromCollection(Arrays.asList(1, 2, 3)).map(element -> element + 1).output(new DiscardingOutputFormat<>());
    try {
        env.execute();
    } catch (Exception e) {
        SUBMISSION_EXCEPTION.set(e);
        throw e;
    }
}
Also used : FlinkException(org.apache.flink.util.FlinkException) Arrays(java.util.Arrays) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) DiscardingOutputFormat(org.apache.flink.api.java.io.DiscardingOutputFormat) MalformedURLException(java.net.MalformedURLException) CliFrontendTestUtils(org.apache.flink.client.cli.CliFrontendTestUtils) PackagedProgram(org.apache.flink.client.program.PackagedProgram) Collections(java.util.Collections) AtomicReference(java.util.concurrent.atomic.AtomicReference) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) FlinkException(org.apache.flink.util.FlinkException) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) MalformedURLException(java.net.MalformedURLException) FileNotFoundException(java.io.FileNotFoundException)

Example 48 with DiscardingOutputFormat

use of org.apache.flink.api.java.io.DiscardingOutputFormat in project flink by apache.

the class LocalExecutorITCase method getRuntimeExceptionPlan.

private Plan getRuntimeExceptionPlan() {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.fromElements(1).map(element -> {
        if (element == 1) {
            throw new RuntimeException("oups");
        }
        return element;
    }).output(new DiscardingOutputFormat<>());
    return env.createProgramPlan();
}
Also used : DiscardingOutputFormat(org.apache.flink.api.java.io.DiscardingOutputFormat) Configuration(org.apache.flink.configuration.Configuration) FileWriter(java.io.FileWriter) Test(org.junit.Test) CommonTestUtils.assertThrows(org.apache.flink.core.testutils.CommonTestUtils.assertThrows) JobClient(org.apache.flink.core.execution.JobClient) File(java.io.File) WordCountData(org.apache.flink.test.testdata.WordCountData) Tokenizer(org.apache.flink.test.testfunctions.Tokenizer) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) CoreOptions(org.apache.flink.configuration.CoreOptions) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Plan(org.apache.flink.api.common.Plan) TestLogger(org.apache.flink.util.TestLogger) LocalExecutor(org.apache.flink.client.deployment.executors.LocalExecutor) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) DeploymentOptions(org.apache.flink.configuration.DeploymentOptions) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assert(org.junit.Assert) Before(org.junit.Before) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment)

Example 49 with DiscardingOutputFormat

use of org.apache.flink.api.java.io.DiscardingOutputFormat in project flink by apache.

the class WordCountCompilerTest method checkWordCount.

private void checkWordCount(boolean estimates) {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(DEFAULT_PARALLELISM);
    // get input data
    DataSet<String> lines = env.readTextFile(IN_FILE).name("Input Lines");
    lines.map(new MapFunction<String, Tuple2<String, Integer>>() {

        private static final long serialVersionUID = -3952739820618875030L;

        @Override
        public Tuple2<String, Integer> map(String v) throws Exception {
            return new Tuple2<>(v, 1);
        }
    }).name("Tokenize Lines").groupBy(0).sum(1).name("Count Words").output(new DiscardingOutputFormat<Tuple2<String, Integer>>()).name("Word Counts");
    // get the plan and compile it
    Plan p = env.createProgramPlan();
    p.setExecutionConfig(new ExecutionConfig());
    OptimizedPlan plan;
    if (estimates) {
        GenericDataSourceBase<?, ?> source = getContractResolver(p).getNode("Input Lines");
        setSourceStatistics(source, 1024 * 1024 * 1024 * 1024L, 24f);
        plan = compileWithStats(p);
    } else {
        plan = compileNoStats(p);
    }
    // get the optimizer plan nodes
    OptimizerPlanNodeResolver resolver = getOptimizerPlanNodeResolver(plan);
    SinkPlanNode sink = resolver.getNode("Word Counts");
    SingleInputPlanNode reducer = resolver.getNode("Count Words");
    SingleInputPlanNode mapper = resolver.getNode("Tokenize Lines");
    // verify the strategies
    Assert.assertEquals(ShipStrategyType.FORWARD, mapper.getInput().getShipStrategy());
    Assert.assertEquals(ShipStrategyType.PARTITION_HASH, reducer.getInput().getShipStrategy());
    Assert.assertEquals(ShipStrategyType.FORWARD, sink.getInput().getShipStrategy());
    Channel c = reducer.getInput();
    Assert.assertEquals(LocalStrategy.COMBININGSORT, c.getLocalStrategy());
    FieldList l = new FieldList(0);
    Assert.assertEquals(l, c.getShipStrategyKeys());
    Assert.assertEquals(l, c.getLocalStrategyKeys());
    Assert.assertTrue(Arrays.equals(c.getLocalStrategySortOrder(), reducer.getSortOrders(0)));
    // check the combiner
    SingleInputPlanNode combiner = (SingleInputPlanNode) reducer.getPredecessor();
    Assert.assertEquals(DriverStrategy.SORTED_GROUP_COMBINE, combiner.getDriverStrategy());
    Assert.assertEquals(l, combiner.getKeys(0));
    Assert.assertEquals(ShipStrategyType.FORWARD, combiner.getInput().getShipStrategy());
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Channel(org.apache.flink.optimizer.plan.Channel) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Plan(org.apache.flink.api.common.Plan) OptimizedPlan(org.apache.flink.optimizer.plan.OptimizedPlan) DiscardingOutputFormat(org.apache.flink.api.java.io.DiscardingOutputFormat) OptimizedPlan(org.apache.flink.optimizer.plan.OptimizedPlan) FieldList(org.apache.flink.api.common.operators.util.FieldList) SingleInputPlanNode(org.apache.flink.optimizer.plan.SingleInputPlanNode) Tuple2(org.apache.flink.api.java.tuple.Tuple2) SinkPlanNode(org.apache.flink.optimizer.plan.SinkPlanNode)

Aggregations

DiscardingOutputFormat (org.apache.flink.api.java.io.DiscardingOutputFormat)49 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)44 Test (org.junit.Test)39 OptimizedPlan (org.apache.flink.optimizer.plan.OptimizedPlan)34 Plan (org.apache.flink.api.common.Plan)33 SingleInputPlanNode (org.apache.flink.optimizer.plan.SingleInputPlanNode)28 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)26 SinkPlanNode (org.apache.flink.optimizer.plan.SinkPlanNode)25 FieldList (org.apache.flink.api.common.operators.util.FieldList)20 SourcePlanNode (org.apache.flink.optimizer.plan.SourcePlanNode)19 DataSet (org.apache.flink.api.java.DataSet)11 Channel (org.apache.flink.optimizer.plan.Channel)10 DualInputPlanNode (org.apache.flink.optimizer.plan.DualInputPlanNode)9 MapFunction (org.apache.flink.api.common.functions.MapFunction)6 Configuration (org.apache.flink.configuration.Configuration)6 PlanNode (org.apache.flink.optimizer.plan.PlanNode)5 File (java.io.File)4 RichReduceFunction (org.apache.flink.api.common.functions.RichReduceFunction)4 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)4 NAryUnionPlanNode (org.apache.flink.optimizer.plan.NAryUnionPlanNode)4