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
}
相关推荐
bubble小拾2 小时前
ElasticSearch高级功能详解与读写性能调优
大数据·elasticsearch·搜索引擎
ZOHO项目管理软件2 小时前
EDM平台大比拼 用户体验与营销效果双重测评
大数据
HyperAI超神经3 小时前
Meta 首个多模态大模型一键启动!首个多针刺绣数据集上线,含超 30k 张图片
大数据·人工智能·深度学习·机器学习·语言模型·大模型·数据集
Hello.Reader5 小时前
TopK算法在大数据重复数据分析中的应用与挑战
大数据·算法·数据分析
数据龙傲天5 小时前
1688商品API接口:电商数据自动化的新引擎
java·大数据·sql·mysql
Elastic 中国社区官方博客5 小时前
Elasticsearch:使用 LLM 实现传统搜索自动化
大数据·人工智能·elasticsearch·搜索引擎·ai·自动化·全文检索
Jason不在家7 小时前
Flink 本地 idea 调试开启 WebUI
大数据·flink·intellij-idea
Elastic 中国社区官方博客8 小时前
使用 Vertex AI Gemini 模型和 Elasticsearch Playground 快速创建 RAG 应用程序
大数据·人工智能·elasticsearch·搜索引擎·全文检索
CHICX12299 小时前
【Hadoop】改一下core-site.xml和hdfs-site.xml配置就可以访问Web UI
xml·大数据·hadoop
权^10 小时前
MySQL--聚合查询、联合查询、子查询、合并查询(上万字超详解!!!)
大数据·数据库·学习·mysql