郭卫东 发表于 2023-9-16 18:48:18

【共建开源】手把手教你贡献一个 SeaTunnel PR,超级详细教程!

https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112405776-1500602035.jpg
Apache SeaTunnel是一个非常易于使用的、超高性能的分布式数据集成平台,支持海量数据的实时同步。每天可稳定高效同步数百亿数据,已被近百家企业投入生产使用。
现在的版本不支持通过jtds的方式链接sqlserver,我们来自己写代码来实现它,并把代码提交给apache seatunnel。
1. 下载源代码

1.首先从远端仓库 https://github.com/apache/seatunnel fork一份代码到自己的仓库中
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112406296-36613422.png
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112406933-854466533.png
2.远端仓库中目前有超过30个分支:

[*]dev :日常开发分支
[*]其他分支 :发布版本分支
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112407626-781511944.png
3.把自己仓库clone到本地
git clone git@github.com:yougithubID/seatunnel.git
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112408063-1540269072.png

[*]添加远端仓库地址,命名为upstream
这一步是为了让本地代码知道他的上游是apache/seatunnel
git remote add upstream git@github.com:apache/seatunnel.git
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112408279-390880106.png
5.查看仓库:
git remote -v
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112408475-725850402.png
此时会有两个仓库:origin(自己的仓库)和upstream(远端仓库)
6.获取/更新远端仓库代码(已经是最新代码,就跳过)
git fetch upstream
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112408670-183900117.png
2. 编写代码

1.加载拉取到本地的代码到IDEA中
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112409050-216236028.png
这里我们需要注意两个module:seatunnel-connectors-v2和seatunnel-examples,其中seatunnel-connectors-v2是我们来写代码的module,seatunnel-examples是我们用来测试代码的module。
2.编写代码
目前代码中已经实现了基于JDBC的方式取链接SqlServer。我们只需要在它的基础之上去做一定的修改即可,经过debug来阅读源码,并了解了需要改的地方如下图:
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112409521-1395400388.png
代码实现如下:
SqlServerDialectFactory.java
return (url.startsWith("jdbc:jtds:sqlserver:") || url.startsWith("jdbc:sqlserver:"));SqlserverTypeMapper.java
private static final String SQLSERVER_SYSNAME = "SYSNAME";
case SQLSERVER_SYSNAME:
                return BasicType.STRING_TYPE;SimpleJdbcConnectionProvider.java
public boolean isConnectionValid() throws SQLException {
      if (connection != null && connection.toString().startsWith("net.sourceforge.jtds")){
            return connection != null
                  && !connection.isClosed();
      }else {
            return connection != null
                  && connection.isValid(jdbcConfig.getConnectionCheckTimeoutSeconds());
      }
    }pom.xml
<jtds.version>1.3.1</jtds.version>
<dependency>
                <groupId>net.sourceforge.jtds</groupId>
                <artifactId>jtds</artifactId>
                <version>${jtds.version}</version>
                <scope>provided</scope>
            </dependency>
<dependency>
            <groupId>net.sourceforge.jtds</groupId>
            <artifactId>jtds</artifactId>
            <version>${jtds.version}</version>
      </dependency>3. 测试代码

1.编写config文件,我们测试通过net.sourceforge.jtds.jdbc.Driver 从sqlserver中读出数据再写入sqlserver中
env {
# You can set flink configuration here
execution.parallelism = 1
job.mode = "BATCH"
#execution.checkpoint.interval = 10000
#execution.checkpoint.data-uri = "hdfs://localhost:9000/checkpoint"
}

source {
# This is a example source plugin **only for test and demonstrate the feature source plugin**
Jdbc {
    driver = net.sourceforge.jtds.jdbc.Driver
    url = "jdbc:jtds:sqlserver://localhost:1433/dbname"
    user = SA
    password = "A_Str0ng_Required_Password"
    query = "select age, name from source"
}

# If you would like to get more information about how to configure seatunnel and see full list of source plugins,
# please go to https://seatunnel.apache.org/docs/connector-v2/source/Jdbc
}

transform {

# If you would like to get more information about how to configure seatunnel and see full list of transform plugins,
# please go to https://seatunnel.apache.org/docs/transform-v2/sql
}

sink {
Jdbc {
    driver = net.sourceforge.jtds.jdbc.Driver
    url = "jdbc:jtds:sqlserver://localhost:1433/dbname"
    user = SA
    password = "A_Str0ng_Required_Password"
    query = "insert into sink(age, name) values(?,?)"
}

# If you would like to get more information about how to configure seatunnel and see full list of sink plugins,
# please go to https://seatunnel.apache.org/docs/connector-v2/sink/Jdbc
}https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112410133-939122522.png
2.修改seatunnel-flink-connector-v2-example中的SeaTunnelApiExample,写入我们写好的config文件
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112410768-2127022871.png
添加seatunnel-flink-connector-v2-example pom文件中添加jdbc依赖
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112411527-1111391437.png
3.运行代码
运行SeaTunnelApiExample,右键->run
4. 提交issue

issue的作用就是告诉社区我们打算做什么事情,后续的PR就是来提交代码解决这个issue。除此以外issue也是我们来提出bug或者其他想法的地方。不一定自己来实现它。你提出来,别人能解决,他们就会提交PR来解决这个问题。
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112412194-1522066495.png
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112412561-1055233212.png
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112412911-1397685608.png
我这里提交了一个叫 Support driver jtds for SqlServer #5307 的issue,其中Feature可以按具体的内容换成BUG/DOCS等等 Connector-V2可以换成其他的具体模块,这里大家可以参照别人已经提的issue来命名。
注:带"*"的都是必填项
5. 提交代码

git commit -m 'commit content'
git push提交后在github上查看提交代码详情
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112413513-2140070038.png
6. 提交PR(Pull Request)

提交完成后,因为我们的仓库的代码的上游是apache/seatunnel,在conribute中我们就可以去提交一个PR。
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112414197-67238425.png
点击Open pull request,就会跳转到上游apache/seatunnel下面的Pull Request列表,并自动开发创建PR页面。填写相关内容,PR的名称就跟需要解决的这个issue一样就可以了,需要注意的时候,最后要带上issue的ID ,我这里是#5307 ,之后点击提交就可以了。
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112414776-432459808.png
https://img2023.cnblogs.com/other/3195851/202309/3195851-20230913112415287-1448381778.png
之后就等社区的管理员审核就可以了,这个过程中可能会在PR中进行留言交流,必要的话,再修改代码,重新提交代码,openPR...
本文由 白鲸开源 提供发布支持!

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: 【共建开源】手把手教你贡献一个 SeaTunnel PR,超级详细教程!