use of org.apache.flink.api.java.utils.MultipleParameterTool in project flink by apache.
the class WordCount method main.
// *************************************************************************
// PROGRAM
// *************************************************************************
public static void main(String[] args) throws Exception {
final MultipleParameterTool params = MultipleParameterTool.fromArgs(args);
// set up the execution environment
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
// make parameters available in the web interface
env.getConfig().setGlobalJobParameters(params);
// get input data
DataSet<String> text = null;
if (params.has("input")) {
// union all the inputs from text files
for (String input : params.getMultiParameterRequired("input")) {
if (text == null) {
text = env.readTextFile(input);
} else {
text = text.union(env.readTextFile(input));
}
}
Preconditions.checkNotNull(text, "Input DataSet should not be null.");
} else {
// get default test text data
System.out.println("Executing WordCount example with default input data set.");
System.out.println("Use --input to specify file input.");
text = WordCountData.getDefaultTextLineDataSet(env);
}
DataSet<Tuple2<String, Integer>> counts = // split up the lines in pairs (2-tuples) containing: (word,1)
text.flatMap(new Tokenizer()).groupBy(0).sum(1);
// emit result
if (params.has("output")) {
counts.writeAsCsv(params.get("output"), "\n", " ");
// execute program
env.execute("WordCount Example");
} else {
System.out.println("Printing result to stdout. Use --output to specify output path.");
counts.print();
}
}
use of org.apache.flink.api.java.utils.MultipleParameterTool in project flink by apache.
the class CLI method fromArgs.
public static CLI fromArgs(String[] args) throws Exception {
MultipleParameterTool params = MultipleParameterTool.fromArgs(args);
Path[] inputs = null;
if (params.has(INPUT_KEY)) {
inputs = params.getMultiParameterRequired(INPUT_KEY).stream().map(Path::new).toArray(Path[]::new);
} else {
System.out.println("Executing example with default input data.");
System.out.println("Use --input to specify file input.");
}
Path output = null;
if (params.has(OUTPUT_KEY)) {
output = new Path(params.get(OUTPUT_KEY));
} else {
System.out.println("Printing result to stdout. Use --output to specify output path.");
}
Duration watchInterval = null;
if (params.has(DISCOVERY_INTERVAL)) {
watchInterval = TimeUtils.parseDuration(params.get(DISCOVERY_INTERVAL));
}
RuntimeExecutionMode executionMode = ExecutionOptions.RUNTIME_MODE.defaultValue();
if (params.has(EXECUTION_MODE)) {
executionMode = RuntimeExecutionMode.valueOf(params.get(EXECUTION_MODE).toUpperCase());
}
return new CLI(inputs, output, watchInterval, executionMode, params);
}
Aggregations