This walkthrough will quickly get you started building a pure Python Flink project.
Please refer to the Python Table API installation guide on how to set up the Python execution environments.
You can begin by creating a Python project and installing the PyFlink package following the installation guide.
Table API applications begin by declaring a table environment; either a
BatchTableEvironment for batch applications or
StreamTableEnvironment for streaming applications.
This serves as the main entry point for interacting with the Flink runtime.
It can be used for setting execution parameters such as restart strategy, default parallelism, etc.
The table config allows setting Table API specific configurations.
The the table environment created, you can declare source and sink tables.
This registers a table named
mySource and a table named
mySink in the execution environment.
mySource has only one column, word, and it consumes strings read from file
mySink has two columns, word and count, and writes data to the file
\t as the field delimiter.
You can now create a job which reads input from table
mySource, preforms some transformations, and writes the results to table
Finally you must execute the actual Flink Python Table API job.
All operations, such as creating sources, transformations and sinks are lazy.
t_env.execute(job_name) is called will the job be run.
The complete code so far:
Firstly, you need to prepare input data in the “/tmp/input” file. You can choose the following command line to prepare the input data:
Next, you can run this example on the command line (Note: if the result file “/tmp/output” has already existed, you need to remove the file before running the example):
The command builds and runs the Python Table API program in a local mini cluster. You can also submit the Python Table API program to a remote cluster, you can refer Job Submission Examples for more details.
Finally, you can see the execution result on the command line:
This should get you started with writing your own Flink Python Table API programs. To learn more about the Python Table API, you can refer Flink Python Table API Docs for more details.