Flink创建TableEnvironment

在官网上,Flink创建TableEnvironment有两种方式:1.通过静态方法 TableEnvironment.create() 创建;2.从现有的 StreamExecutionEnvironment 创建一个 StreamTableEnvironment 与 DataStream API 互操作

java 复制代码
import org.apache.flink.table.api.EnvironmentSettings;
import org.apache.flink.table.api.TableEnvironment;


//1.通过静态方法 TableEnvironment.create() 创建
EnvironmentSettings settings = EnvironmentSettings
    .newInstance()
    .inStreamingMode()//默认为StreamingMode。可以不写
    //.inBatchMode()
    //.useOldPlanner()//1.14.4已过时
    //.useBlinkPlanner()//1.14.4已过时。默认BLINK
    .build();

TableEnvironment tEnv = TableEnvironment.create(settings);

//2.从现有的 StreamExecutionEnvironment 创建一个 StreamTableEnvironment 与 DataStream API 互操作
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.EnvironmentSettings;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);

而在写代码时会发现,通过静态方法 TableEnvironment.create() 创建时,create()方法有两种参数,一种就是官网上的EnvironmentSettings,另一种是Configuration。

查看源码会发现EnvironmentSettings最终还是会将EnvironmentSettings转为Configuration。且可以看到默认的RUNTIME_MODE是StreamingMode。

复制代码
TableEnvironment.create(settings)-->TableEnvironmentImpl.create(settings)-->create(settings, settings.toConfiguration())
java 复制代码
    /** Convert the environment setting to the {@link Configuration}. */
    public Configuration toConfiguration() {
        Configuration configuration = new Configuration();
        configuration.set(RUNTIME_MODE, isStreamingMode() ? STREAMING : BATCH);
        configuration.set(TABLE_PLANNER, PlannerType.BLINK);
        return configuration;
    }

同样,看EnvironmentSettings的构造方法也可以发现默认的RUNTIME_MODE是StreamingMode。

java 复制代码
    private EnvironmentSettings(
            String planner,
            @Nullable String executor,
            String builtInCatalogName,
            String builtInDatabaseName,
            boolean isStreamingMode) {
        this.planner = planner;
        this.executor = executor;
        this.builtInCatalogName = builtInCatalogName;
        this.builtInDatabaseName = builtInDatabaseName;
        this.isStreamingMode = isStreamingMode;
    }

此外,我看的是1.14.4的源码,发现默认的planner已经是BLINK,而OLD未来将不会保留。

java 复制代码
/**
 * Determine the type of the {@link Planner}. Except for the optimization, the different planner
 * also differs in the time semantic and so on.
 *
 * @deprecated The old planner has been removed in Flink 1.14. Since there is only one planner left
 *     (previously called the 'blink' planner), this class is obsolete and will be removed in future
 *     versions.
 */
@PublicEvolving
@Deprecated
public enum PlannerType {
    /** Blink planner is the up-to-date planner in Flink. */
    BLINK,

    /** Old planner is used before. It will not be maintained in the future. */
    OLD
}
相关推荐
AI优秘企业大脑20 小时前
需求洞察助力战略规划实现潜在市场机会
大数据·人工智能
罗不俷20 小时前
【Hadoop】Hadoop核心基础——YARN 框架架构与运行机制(Hadoop 集群的 “资源管家”)
大数据
小小王app小程序开发1 天前
上门家政小程序用户激励机制分析:用 “利益 + 情感” 双驱动,解锁高复购增长密码
大数据·小程序
武汉唯众智创1 天前
高职院校大数据软件教学实训室建设方案
大数据·大数据实训室·大数据实验室·大数据软件教学实训室·大数据教学实训室
Elastic 中国社区官方博客1 天前
Elasticsearch:如何为 Elastic Stack 部署 E5 模型 - 下载及隔离环境
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
qqxhb1 天前
系统架构设计师备考第68天——大数据处理架构
大数据·hadoop·flink·spark·系统架构·lambda·kappa
思通数科多模态大模型1 天前
扑灭斗殴的火苗:AI智能守护如何为校园安全保驾护航
大数据·人工智能·深度学习·安全·目标检测·计算机视觉·数据挖掘
high20111 天前
【Git】-- Rebase 减少 Commit 次数指南
大数据·git·elasticsearch
Ace_31750887761 天前
淘宝店铺全量商品接口实战:分类穿透采集与增量同步的技术方案
大数据·数据库·python
盈飞无限1 天前
质量智能革命:SPC软件助力中国制造驶入高质量发展快车道
大数据·人工智能·制造