从flink的官方文档,我们知道flink的编程模型分为四层,sql层是最高层的api,Table api是中间层,DataStream/DataSet Api 是核心,stateful Streaming process层是底层实现。

其中,
flink dataset api使用及原理介绍了DataSet Api
flink DataStream API使用及原理介绍了DataStream Api
flink中的时间戳如何使用?---Watermark使用及原理介绍了底层实现的基础Watermark
flink window实例分析介绍了window的概念及使用原理
Flink中的状态与容错介绍了State的概念及checkpoint,savepoint的容错机制
0. 基本概念:
0.1 TableEnvironment
TableEnvironment是Table API和SQL集成的核心概念,它主要负责:
1、在内部目录Catalog中注册一个Table
2、注册一个外部目录Catalog
3、执行SQL查询
4、注册一个用户自定义函数UDF
5、将DataStream或者DataSet转换成Table
6、持有BatchTableEnvironment或者StreamTableEnvironment的引用

/** * The base class for batch and stream TableEnvironments.
*
* <p>The TableEnvironment is a central concept of the Table API and SQL integration. It is
* responsible for:
*
* <ul>
* <li>Registering a Table in the internal catalog</li>
* <li>Registering an external catalog</li>
* <li>Executing SQL queries</li>
* <li>Registering a user-defined scalar function. For the user-defined table and aggregate
* function, use the StreamTableEnvironment or BatchTableEnvironment</li>
* </ul>
*/

0.2 Catalog
Catalog:所有对数据库和表的元数据信息都存放再Flink CataLog内部目录结构中,其存放了flink内部所有与Table相关的元数据信息,包括表结构信息/数据源信息等。
/** * This interface is responsible for reading and writing metadata such as database/table/views/UDFs
* from a registered catalog. It connects a registered catalog and Flink's Table API.
*/
其结构如下:

0.3 TableSource
在使用Table API时,可以将外部的数据源直接注册成Table数据结构。此结构称之为TableSource

/** * Defines an external table with the schema that is provided by {@link TableSource#getTableSchema}.
*
* <p>The data of a {@link TableSource} is produced as a {@code DataSet} in case of a {@code BatchTableSource}
* or as a {@code DataStream} in case of a {@code StreamTableSource}. The type of ths produced
* {@code DataSet} or {@code DataStream} is specified by the {@link TableSource#getProducedDataType()} method.
*
* <p>By default, the fields of the {@link TableSchema} are implicitly mapped by name to the fields of
* the produced {@link DataType}. An explicit mapping can be defined by implementing the
* {@link DefinedFieldMapping} interface.
*
* @param <T> The return type of the {@link TableSource}.
*/

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2730/viewspace-3153857/ ,如需转载,请注明出处,否则将追究法律责任。