Search in sources :

Example 1 with LocalEnvironment

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

the class ExecutionPlanAfterExecutionTest method testGetExecutionPlanOfRangePartition.

@Test
public void testGetExecutionPlanOfRangePartition() {
    ExecutionEnvironment env = new LocalEnvironment();
    env.getConfig().disableSysoutLogging();
    DataSet<Integer> baseSet = env.fromElements(1, 2);
    DataSet<Tuple2<Integer, Integer>> result = baseSet.map(new MapFunction<Integer, Tuple2<Integer, Integer>>() {

        @Override
        public Tuple2<Integer, Integer> map(Integer value) throws Exception {
            return new Tuple2(value, value * 2);
        }
    }).partitionByRange(0).aggregate(Aggregations.MAX, 1);
    result.output(new DiscardingOutputFormat<Tuple2<Integer, Integer>>());
    try {
        env.getExecutionPlan();
        env.execute();
    } catch (Exception e) {
        e.printStackTrace();
        fail("Cannot run both #getExecutionPlan and #execute.");
    }
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple2(org.apache.flink.api.java.tuple.Tuple2) LocalEnvironment(org.apache.flink.api.java.LocalEnvironment) Test(org.junit.Test)

Example 2 with LocalEnvironment

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

the class ExecutionPlanAfterExecutionTest method testExecuteAfterGetExecutionPlan.

@Test
public void testExecuteAfterGetExecutionPlan() {
    ExecutionEnvironment env = new LocalEnvironment();
    env.getConfig().disableSysoutLogging();
    DataSet<Integer> baseSet = env.fromElements(1, 2);
    DataSet<Integer> result = baseSet.map(new MapFunction<Integer, Integer>() {

        @Override
        public Integer map(Integer value) throws Exception {
            return value * 2;
        }
    });
    result.output(new DiscardingOutputFormat<Integer>());
    try {
        env.getExecutionPlan();
        env.execute();
    } catch (Exception e) {
        e.printStackTrace();
        fail("Cannot run both #getExecutionPlan and #execute.");
    }
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) LocalEnvironment(org.apache.flink.api.java.LocalEnvironment) Test(org.junit.Test)

Example 3 with LocalEnvironment

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

the class ExecutionPlanAfterExecutionTest method testCreatePlanAfterGetExecutionPlan.

@Test
public void testCreatePlanAfterGetExecutionPlan() {
    ExecutionEnvironment env = new LocalEnvironment();
    DataSet<Integer> baseSet = env.fromElements(1, 2);
    DataSet<Integer> result = baseSet.map(new MapFunction<Integer, Integer>() {

        @Override
        public Integer map(Integer value) throws Exception {
            return value * 2;
        }
    });
    result.output(new DiscardingOutputFormat<Integer>());
    try {
        env.getExecutionPlan();
        env.createProgramPlan();
    } catch (Exception e) {
        e.printStackTrace();
        fail("Cannot run both #getExecutionPlan and #execute. Message: " + e.getMessage());
    }
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) LocalEnvironment(org.apache.flink.api.java.LocalEnvironment) Test(org.junit.Test)

Example 4 with LocalEnvironment

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

the class PythonPlanBinder method runPlan.

private void runPlan(String[] args) throws Exception {
    env = ExecutionEnvironment.getExecutionEnvironment();
    int split = 0;
    for (int x = 0; x < args.length; x++) {
        if (args[x].compareTo("-") == 0) {
            split = x;
        }
    }
    try {
        String tmpPath = FLINK_PYTHON_FILE_PATH + r.nextInt();
        prepareFiles(tmpPath, Arrays.copyOfRange(args, 0, split == 0 ? args.length : split));
        startPython(tmpPath, Arrays.copyOfRange(args, split == 0 ? args.length : split + 1, args.length));
        receivePlan();
        if (env instanceof LocalEnvironment) {
            FLINK_HDFS_PATH = "file:" + System.getProperty("java.io.tmpdir") + File.separator + "flink";
        }
        distributeFiles(tmpPath, env);
        JobExecutionResult jer = env.execute();
        sendResult(jer);
        close();
    } catch (Exception e) {
        close();
        throw e;
    }
}
Also used : JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) DatasizeHint(org.apache.flink.python.api.PythonOperationInfo.DatasizeHint) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) LocalEnvironment(org.apache.flink.api.java.LocalEnvironment)

Aggregations

LocalEnvironment (org.apache.flink.api.java.LocalEnvironment)4 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)3 Test (org.junit.Test)3 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 DatasizeHint (org.apache.flink.python.api.PythonOperationInfo.DatasizeHint)1