TableAPI和SQL介绍。
Flink针对标准的流处理和批处理提供了两种关系型API,Table API和SQL。Table API允许用户以一种很直观的方式进行select 、filter和join操作。Flink SQL基于 Apache Calcite实现标准SQL。针对批处理和流处理可以提供相同的处理语义和结果。 Flink Table API、SQL和Flink的DataStream API、DataSet API是紧密联系在一起的。
注意:Table API和SQL现在还处于活跃开发阶段,还没有完全实现Flink中所有的特性。不是所有的 [Table API,SQL] 和 [流,批] 的组合都是支持的。
Table API和SQL是一种关系型 API,用户可以像操作 Mysql 数据库表一样的操作数据,而不需要写代码,更不需要手工的对代码进行调优。另外,SQL 作为一个非程序员可操作的语言,学习成本很低,如果一个系统提供 SQL 支持,将很容易被用户接受。
如果你想要使用Table API 和SQL的话,需要添加下面的依赖。
pom.xml
<properties>
...
<flink-table-api.version>1.11.0</flink-table-api.version>
</properties>
<dependencies>
...
<!-- table API & SQL -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-api-java-bridge_2.12</artifactId>
<version>${flink-table-api.version}</version>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-api-scala-bridge_2.12</artifactId>
<version>${flink-table-api.version}</version>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-planner-blink_2.12</artifactId>
<version>${flink-table-api.version}</version>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-planner_2.12</artifactId>
<version>${flink-table-api.version}</version>
<!--<scope>provided</scope>-->
</dependency>
</dependencies>
Table API和SQL通过join API集成在一起,这个join API的核心概念是Table,Table可以作为查询的输入和输出。
针对Table API和SQL我们主要讲解以下内容: 1. Table API和SQL的使用。 2. DataStream、DataSet和Table之间的互相转换。