Table API

API’s built on top of DataStream and DataSet API’s enabling SQL like queries on the data is termed as Table API. They are available in the Java and Scala languages. Using these API’s you can use SQL-like expressions for specifying the required operations.

The Table API creates this abstraction above DataStream and DataSet, making it easy for coding. Using this, its easy to deal with structured data using the popular SQL expression. Basic data structures that the API deals with is Table.

SQL (Structured Query Language) is a domain-specific language used in programming and designed for managing data held in a Relational Database Management System (RDBMS), or for stream processing in a RDBMS.
- Wikipedia

Similar to the DataStream and DataSet APIs, using the Table API can done by doing the following steps:

  1. Get the ExecutionEnvironment as this is the starting point for any API execution in Flink:
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
  1. After that, you need to get TableExecutionEnvironment using ExecutionEnvironment as shown next in the code snippet. According to the data type (batch or stream data) to be handled, you need to get either BatchTableEnvironment (batch data) and StreamTableEnvironment (stream data), as shown in this code snippet:
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);
OR
StreamTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);
  1. Now, register the table. This can be from DataStream, DataSet, and so on, shown in this code snippet as an example:
tableEnv.registerDataSet("table_name", mytable);
OR
tableEnv.registerDataStream("table_name", mytable);
  1. Now, using the TableAPI, perform various operations.

The Flink documentation has all the details with regards to this API at https://goo.gl/B6F8Ey.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.79.176