Skip to content

Instantly share code, notes, and snippets.

@GEOFBOT
Created January 30, 2017 17:08
Show Gist options
  • Save GEOFBOT/084397bac7878b3547b7ffed662d930d to your computer and use it in GitHub Desktop.
Save GEOFBOT/084397bac7878b3547b7ffed662d930d to your computer and use it in GitHub Desktop.
Multiple Flink jobs in one file
package com.github.geofbot;
import org.apache.commons.cli.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.flink.api.common.functions.*;
import org.apache.flink.api.common.operators.Order;
import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.aggregation.Aggregations;
import org.apache.flink.api.java.operators.IterativeDataSet;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.api.java.tuple.Tuple3;
import org.apache.flink.api.java.tuple.Tuple4;
import org.apache.flink.api.java.utils.DataSetUtils;
import org.apache.flink.core.fs.FileSystem;
import org.apache.flink.util.Collector;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static java.lang.Math.round;
/**
* Experiment file
*/
public class Experiment {
//
// Program
//
public static void main(String[] args) throws Exception {
// Initialize the Flink environment.
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
// Read in the input data.
DataSet<Tuple2<Integer, Integer>> e = env.fromElements(
new Tuple2<>(0, 1),
new Tuple2<>(1, 2),
new Tuple2<>(2, 3),
new Tuple2<>(2, 10)
);
e = e.groupBy(0).aggregate(Aggregations.SUM, 1);
e.writeAsCsv("/tmp/e1", FileSystem.WriteMode.OVERWRITE);
env.execute();
final ExecutionEnvironment env2 = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple2<Integer, Integer>> f = env2.readCsvFile("/tmp/e1")
.types(Integer.class, Integer.class);
f = f.first(2);
f.writeAsCsv("/tmp/f1", FileSystem.WriteMode.OVERWRITE);
env2.execute();
}
}
@GEOFBOT
Copy link
Author

GEOFBOT commented Mar 2, 2023

@Johny-Ch Sorry, I'm not sure if this file ever worked. I made it a long time ago for my own testing

@Johny-Ch
Copy link

Johny-Ch commented Mar 2, 2023

No worries will update here If I'm able to figure it out. Thank you for the prompt response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment