Table In Flink
Some notes on the Table APIs, which I had not used before.
Translated from Chinese with AI · Read the original
I had not used the Table APIs before, so these are a few notes.
Structure of Program
A program using the Table API is structured roughly as follows:
// create a TableEnvironment for specific planner batch or streamingTableEnvironment tableEnv = ...; // see "Create a TableEnvironment" section
// register a TabletableEnv.registerTable("table1", ...) // ortableEnv.registerTableSource("table2", ...); // or// register an output TabletableEnv.registerTableSink("outputTable", ...);
// create a Table from a Table API queryTable tapiResult = tableEnv.scan("table1").select(...);// create a Table from a SQL queryTable sqlResult = tableEnv.sqlQuery("SELECT ... FROM table2 ... ");
// emit a Table API result Table to a TableSink, same for SQL resulttapiResult.insertInto("outputTable");
// executetableEnv.execute("java_job");TableEnvironment has Batch and Stream variants. Their bridge modules provide conversions to and from DataSet and DataStream, respectively.
There are three ways to register a Table:
- registerTable // register with Table
- registerTableSource // register with TableSource
- registerTableSink // register with TableSink
Registration adds the corresponding table to the Catalog. Hive and InMemory modes are currently supported.