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
}
相关推荐
zhixingheyi_tian19 分钟前
Mapreduce 之 nativetask
大数据·mapreduce
远航计算机2 小时前
职业技能培训机构如何利用QClaw+Skills做豆包GEO:知识库搭建×内容创作×效果监测的完整实操手册
大数据·人工智能·自动化·aigc·火山引擎
IanSkunk2 小时前
视光中心承接近视防控需求,核心是先把服务流程做成标准化工程
大数据
SEO_juper2 小时前
用Google Search Console数据做内容审计:找出网站上哪些页面在“吃白饭“
大数据·人工智能·外贸独立站
独行侠影a4 小时前
Mojo:专为AI而生的“Python++”,能否真正挑战CUDA与C++的统治地位?
大数据·人工智能·深度学习
greenbbLV4 小时前
中小公司积分商城选型:SaaS与私有化方案对比解析
大数据·前端·小程序
半兽先生5 小时前
大模型技术开发与应用——5.大模型Agent开发(CrewAI)
大数据·人工智能·python·机器学习·ai
空杆推不起5 小时前
穿透 Flink CDC 表层用法:数据库日志捕获机制、Flink Source 运行时、端到端一致性底层原理详解
大数据·数据库·flink
跨境生态圈6 小时前
2026跨境出海服务商深度测评:凌赟科技如何用“SEO+GEO双引擎”重构AI时代获客逻辑?
大数据·运维·人工智能·科技·chatgpt
小邓的技术笔记6 小时前
DeepSeek 大模型落地应用与场景实战指南
大数据·人工智能