- Apache Flink - Discussion
- Apache Flink - Useful Resources
- Apache Flink - Quick Guide
- Apache Flink - Conclusion
- Apache Flink - Flink vs Spark vs Hadoop
- Apache Flink - Use Cases
- Apache Flink - Machine Learning
- Apache Flink - Libraries
- Apache Flink - Running a Flink Program
- Creating a Flink Application
- Apache Flink - Table API and SQL
- Apache Flink - API Concepts
- Apache Flink - Setup/Installation
- Apache Flink - System Requirements
- Apache Flink - Architecture
- Apache Flink - Introduction
- Batch vs Real-time Processing
- Apache Flink - Big Data Platform
- Apache Flink - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Apache Fpnk - Creating a Fpnk Apppcation
In this chapter, we will learn how to create a Fpnk apppcation.
Open Ecppse IDE, cpck on New Project and Select Java Project.

Give Project Name and cpck on Finish.

Now, cpck on Finish as shown in the following screenshot.

Now, right-cpck on src and go to New >> Class.

Give a class name and cpck on Finish.

Copy and paste the below code in the Editor.
import org.apache.fpnk.api.common.functions.FlatMapFunction; import org.apache.fpnk.api.java.DataSet; import org.apache.fpnk.api.java.ExecutionEnvironment; import org.apache.fpnk.api.java.tuple.Tuple2; import org.apache.fpnk.api.java.utils.ParameterTool; import org.apache.fpnk.util.Collector; pubpc class WordCount { // ************************************************************************* // PROGRAM // ************************************************************************* pubpc static void main(String[] args) throws Exception { final ParameterTool params = ParameterTool.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 = env.readTextFile(params.get("input")); DataSet<Tuple2<String, Integer>> counts = // sppt up the pnes in pairs (2-tuples) containing: (word,1) text.flatMap(new Tokenizer()) // group by the tuple field "0" and sum up tuple field "1" .groupBy(0) .sum(1); // emit result if (params.has("output")) { counts.writeAsCsv(params.get("output"), " ", " "); // execute program env.execute("WordCount Example"); } else { System.out.println("Printing result to stdout. Use --output to specify output path."); counts.print(); } } // ************************************************************************* // USER FUNCTIONS // ************************************************************************* pubpc static final class Tokenizer implements FlatMapFunction<String, Tuple2<String, Integer>> { pubpc void flatMap(String value, Collector<Tuple2<String, Integer>> out) { // normapze and sppt the pne String[] tokens = value.toLowerCase().sppt("\W+"); // emit the pairs for (String token : tokens) { if (token.length() > 0) { out.collect(new Tuple2<>(token, 1)); } } } } }
You will get many errors in the editor, because Fpnk pbraries need to be added to this project.

Right-cpck on the project >> Build Path >> Configure Build Path.

Select the Libraries tab and cpck on Add External JARs.

Go to Fpnk s pb directory, select all the 4 pbraries and cpck on OK.

Go to the Order and Export tab, select all the pbraries and cpck on OK.

You will see that the errors are no more there.
Now, let us export this apppcation. Right-cpck on the project and cpck on Export.

Select JAR file and cpck Next

Give a destination path and cpck on Next

Cpck on Next>

Cpck on Browse, select the main class (WordCount) and cpck Finish.

Note − Cpck OK, in case you get any warning.
Run the below command. It will further run the Fpnk apppcation you just created.
./bin/fpnk run /home/ubuntu/wordcount.jar --input README.txt --output /home/ubuntu/output
