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
}
相关推荐
haoyun6543213 分钟前
一文理清CRM:从基础概念到落地应用完整指南
大数据·人工智能·架构
办公室马主任20 分钟前
华南机械加工企业选MES服务商怎么选?
大数据·运维·人工智能·制造
IPHWT 零软网络2 小时前
政务热线:如何打造 7x24 小时不打烊的智能总机?
大数据·人工智能·政务·智能路由·ivr语音导航
陈天伟教授3 小时前
TraeWork初体验-生成研究报告
大数据·数据库·人工智能
ZDGJ60993 小时前
一文理清国际期货各大品类
大数据·区块链
保卫大狮兄3 小时前
设备利用率低,到底是设备问题还是排产问题?
大数据·运维·服务器
大大大大晴天️3 小时前
StarRocks 的查询性能为什么快?
大数据·starrocks
专注API从业者3 小时前
告别人工盯品!Open Claw 搭建京东商品全自动监控与数据分析系统(附完整可运行代码)
大数据·数据库·数据分析
千舟软件5 小时前
千舟软件介绍 | 顺便聊聊我们做了哪些产品
大数据·数据库·科技·小程序·业界资讯
阿童木写作6 小时前
跨境电商图片翻译工具推荐:批量AI翻译+视频字幕+智能抠图
大数据·人工智能·python·音视频