FlinkSQL源码解析1--提交任务过程

提交入口

org.apache.flink.table.api.internal.TableEnvironmentImpl#executeSql
 @Override
    public TableResult executeSql(String statement) {
        List<Operation> operations = getParser().parse(statement);

        if (operations.size() != 1) {
            throw new TableException(UNSUPPORTED_QUERY_IN_EXECUTE_SQL_MSG);
        }

        Operation operation = operations.get(0);
        return executeInternal(operation);
    }

 提交过程概述


sql--》operation--》Transformation--》pipeline(StreamGraph)--》JobGraph--》deployJobCluster

具体过程

1、查询转成operation

sql-->SqlNodeList-->flinkPlanner.validate(sqlNode)-->Optional<Operation> operation = SqlNodeConverters.convertSqlNode(validated, context);


2、operation转成pipeline(StreamGraph)


org.apache.flink.table.api.internal.TableEnvironmentImpl#executeQueryOperation
executeQueryOperation--》

2.1、operation转成Transformation

List<Transformation<?>> transformations = translate(Collections.singletonList(sinkOperation));--》

org.apache.flink.table.planner.delegation.PlannerBase#translate

2.2、Transformation转成pipeline

Pipeline pipeline =
                execEnv.createPipeline(
                        transformations, tableConfig.getConfiguration(), defaultJobName);

2.3、pipeline转成streamGraph


final StreamGraph streamGraph = executionEnvironment.generateStreamGraph(transformations); // StreamGraph是Pipeline接口的实现类

3、将StreamGraph转成JobGraph


org.apache.flink.streaming.api.environment.StreamExecutionEnvironment#executeAsync(org.apache.flink.streaming.api.graph.StreamGraph)

 JobClient jobClient = execEnv.executeAsync(pipeline);
3.1、final PipelineExecutor executor = getPipelineExecutor();

        CompletableFuture<JobClient> jobClientFuture =
                executor.execute(streamGraph, configuration, userClassloader);
                
3.2、createJobGraph#new StreamingJobGraphGenerator(
                            userClassLoader, streamGraph, jobID, serializationExecutor)
                    .createJobGraph();


                    
4、将jobGraph提交到集群


org.apache.flink.client.deployment.executors.AbstractJobClusterExecutor#execute

4.1、获取集群信息


final ClusterClientProvider<ClusterID> clusterClientProvider =
                    clusterDescriptor.deployJobCluster(

                           clusterSpecification, jobGraph, configAccessor.getDetachedMode

4.2、提交任务到集群


return CompletableFuture.completedFuture(
                    new ClusterClientJobClientAdapter<>(
                            clusterClientProvider, jobGraph.getJobID(), userCodeClassloader));                            

要下载Flink SQL Connector for MySQL CDC,您可以按照以下步骤进行操作: 1. 首先,您需在您的项目中添加Flink SQL Connector for MySQL CDC的依赖项。可以使用Maven或Gradle构建工具来完成这一步骤。在您的项目配置文件中,将以下代码添加到依赖项部分: ``` <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-sql-connector-mysql-cdc_2.11</artifactId> <version>1.13.1</version> </dependency> ``` 2. 在使用Flink SQL Connector for MySQL CDC之前,您需要确保已经安装并启动了Flink集群。您可以从Flink官方网站下载并按照安装说明进行安装。 3. 下一步是配置MySQL的Change Data Capture (CDC)。您可以在MySQL的配置文件中启用CDC功能,并配置要监视的数据库表。具体配置项可能会因MySQL版本而有所不同,您可以参考MySQL的官方文档或相关教程进行操作。 4. 配置完CDC后,您可以使用Flink的Table API或SQL语句来读取CDC的数据。可以使用`TableEnvironment`对象来创建与MySQL CDC连接,并定义CDC表。以下是一个示例代码片段: ```java // 创建Flink Table环境 StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env); // 注册MySQL CDC Connector String ddl = "CREATE TABLE mysql_cdc_table (..., PRIMARY KEY (id)) " + "WITH (...properties...) "; tableEnv.executeSql(ddl); // 查询CDC数据 String query = "SELECT * FROM mysql_cdc_table"; Table result = tableEnv.sqlQuery(query); // 打印查询结果 tableEnv.toRetractStream(result, Row.class).print(); // 执行作业 env.execute(); ``` 这样,您就可以下载、配置和使用Flink SQL Connector for MySQL CDC来处理MySQL的Change Data Capture数据了。若需要进一步了解和使用该连接器的更多功能,建议参考官方文档或相关教程。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值