• idea启动dataX,开发金仓和达梦插件


    一、idea跑datax

    1、首先去官网拉取datax项目代码,地址 https://gitee.com/mirrors/DataX.git 选择克隆/下载的地址。

     2、进入准备好的下载目录,右键选择git base here进行下载(自己下载好就行)。

     3、打开idea,导入下载好的datax项目

    4、会加载一段时间,等待就行了,前提条件是maven配置好,联网哦 

    5、在maven中,项目根目录下先clean,勾选跳过test,再package。clean速度快,package要等一会的,完成后可以看到target目录,将core中的datax复制出来,要进行配置,clean就清除了。

    6、进行项目启动配置,我这里已经配置好了,根据图上的标识,把对应的参数配置上去。

    VM options: -Ddatax.home=D:\Project\etl\setting\datax

    Program arguments:  -mode standalone -jobid -1 -job D:\Project\etl\setting\datax\job\job.json

     7、在datax下面新建plugin插件目录,在下面新增reader目录,存放读取插件。writer目录存放写入插件。

     8、datax下面的job目录存放job任务配置,包含使用的插件,数据库链接,用户名密码,要操作的表等,这一块可以问度娘,我这里是一个最简单的

     9、上面配置好就可以启动了。这里跑一下

    二、达梦插件开发

    1、在datax项目右键new -》Module,选择Maven,其他什么不用勾选,next

     2、在窗口中填写模块名称,这里用dmreader,然后next

    3、创建完成后,是下面的一个空的模块(因为我有dmreader了,这里用dmreader1),删除test,仿照mysqlreader新增对应文件。

    4、pom.xml

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    5. <parent>
    6. <artifactId>datax-all</artifactId>
    7. <groupId>com.alibaba.datax</groupId>
    8. <version>0.0.1-SNAPSHOT</version>
    9. </parent>
    10. <modelVersion>4.0.0</modelVersion>
    11. <artifactId>dmreader</artifactId>
    12. <name>dmreader</name>
    13. <packaging>jar</packaging>
    14. <dependencies>
    15. <dependency>
    16. <groupId>com.alibaba.datax</groupId>
    17. <artifactId>datax-common</artifactId>
    18. <version>${datax-project-version}</version>
    19. <exclusions>
    20. <exclusion>
    21. <artifactId>slf4j-log4j12</artifactId>
    22. <groupId>org.slf4j</groupId>
    23. </exclusion>
    24. </exclusions>
    25. </dependency>
    26. <dependency>
    27. <groupId>org.slf4j</groupId>
    28. <artifactId>slf4j-api</artifactId>
    29. </dependency>
    30. <dependency>
    31. <groupId>ch.qos.logback</groupId>
    32. <artifactId>logback-classic</artifactId>
    33. </dependency>
    34. <dependency>
    35. <groupId>com.alibaba.datax</groupId>
    36. <artifactId>plugin-rdbms-util</artifactId>
    37. <version>${datax-project-version}</version>
    38. </dependency>
    39. <!-- 达梦模块 siqm -->
    40. <dependency>
    41. <groupId>com.dameng</groupId>
    42. <artifactId>DmJdbcDriver18</artifactId>
    43. <version>8.1.2.141</version>
    44. <scope>system</scope>
    45. <systemPath>${basedir}/src/main/libs/DmJdbcDriver18-8.1.2.141.jar</systemPath>
    46. </dependency>
    47. </dependencies>
    48. <build>
    49. <plugins>
    50. <!-- compiler plugin -->
    51. <plugin>
    52. <artifactId>maven-compiler-plugin</artifactId>
    53. <configuration>
    54. <source>${jdk-version}</source>
    55. <target>${jdk-version}</target>
    56. <encoding>${project-sourceEncoding}</encoding>
    57. </configuration>
    58. </plugin>
    59. <!-- assembly plugin -->
    60. <plugin>
    61. <artifactId>maven-assembly-plugin</artifactId>
    62. <configuration>
    63. <descriptors>
    64. <descriptor>src/main/assembly/package.xml</descriptor>
    65. </descriptors>
    66. <finalName>datax</finalName>
    67. </configuration>
    68. <executions>
    69. <execution>
    70. <id>dwzip</id>
    71. <phase>package</phase>
    72. <goals>
    73. <goal>single</goal>
    74. </goals>
    75. </execution>
    76. </executions>
    77. </plugin>
    78. </plugins>
    79. </build>
    80. </project>

     5、Constant这常量类其实和其他的一样。

    1. package com.alibaba.datax.plugin.reader.dmreader;
    2. /**
    3. * Des: 常量
    4. * Author: SiQiangMing 2022/9/8 18:09
    5. */
    6. public class Constant {
    7. public static final int DEFAULT_FETCH_SIZE = 1000;
    8. }

    6、新增达梦的配置,可以参考MySql进行配置,这里有9个地方,注意别忘改了dm.jdbc.driver.DmDriver

    7、DmReader主要是继承Reader,还有Job和Task两个内部类,还有DATABASE_TYPE这个常量别忘修改为DM对应。

    1. package com.alibaba.datax.plugin.reader.dmreader;
    2. import com.alibaba.datax.common.exception.DataXException;
    3. import com.alibaba.datax.common.plugin.RecordSender;
    4. import com.alibaba.datax.common.spi.Reader;
    5. import com.alibaba.datax.common.util.Configuration;
    6. import com.alibaba.datax.plugin.rdbms.reader.CommonRdbmsReader;
    7. import com.alibaba.datax.plugin.rdbms.util.DBUtilErrorCode;
    8. import com.alibaba.datax.plugin.rdbms.util.DataBaseType;
    9. import java.util.List;
    10. /**
    11. * Des: 达梦读取插件
    12. * Author: SiQiangMing 2022/9/8 16:13
    13. */
    14. public class DmReader extends Reader {
    15. private static final DataBaseType DATABASE_TYPE = DataBaseType.Dm;
    16. /**
    17. * Des: 静态内部类,执行job相关操作
    18. * Author: SiQiangMing 2022/9/8 18:09
    19. */
    20. public static class Job extends Reader.Job {
    21. private Configuration originalConfig;
    22. private CommonRdbmsReader.Job commonRdbmsReaderMaster;
    23. @Override
    24. public void init() {
    25. this.originalConfig = super.getPluginJobConf();
    26. int fetchSize = this.originalConfig.getInt(com.alibaba.datax.plugin.rdbms.reader.Constant.FETCH_SIZE,
    27. Constant.DEFAULT_FETCH_SIZE);
    28. if (fetchSize < 1) {
    29. throw DataXException.asDataXException(DBUtilErrorCode.REQUIRED_VALUE,
    30. String.format("您配置的fetchSize有误,根据DataX的设计,fetchSize : [%d] 设置值不能小于 1.", fetchSize));
    31. }
    32. this.originalConfig.set(com.alibaba.datax.plugin.rdbms.reader.Constant.FETCH_SIZE, fetchSize);
    33. this.commonRdbmsReaderMaster = new CommonRdbmsReader.Job(DATABASE_TYPE);
    34. this.commonRdbmsReaderMaster.init(this.originalConfig);
    35. }
    36. @Override
    37. public void post() {
    38. this.commonRdbmsReaderMaster.post(this.originalConfig);
    39. }
    40. @Override
    41. public void destroy() {
    42. this.commonRdbmsReaderMaster.destroy(this.originalConfig);
    43. }
    44. @Override
    45. public List split(int adviceNumber) {
    46. return this.commonRdbmsReaderMaster.split(this.originalConfig, adviceNumber);
    47. }
    48. }
    49. /**
    50. * Des: 静态内部类,执行job相关操作
    51. * Author: SiQiangMing 2022/9/8 18:11
    52. */
    53. public static class Task extends Reader.Task {
    54. private Configuration readerSliceConfig;
    55. private CommonRdbmsReader.Task commonRdbmsReaderSlave;
    56. @Override
    57. public void init() {
    58. this.readerSliceConfig = super.getPluginJobConf();
    59. this.commonRdbmsReaderSlave = new CommonRdbmsReader.Task(DATABASE_TYPE, super.getTaskGroupId(), super.getTaskId());
    60. this.commonRdbmsReaderSlave.init(this.readerSliceConfig);
    61. }
    62. @Override
    63. public void startRead(RecordSender recordSender) {
    64. int fetchSize = this.readerSliceConfig.getInt(com.alibaba.datax.plugin.rdbms.reader.Constant.FETCH_SIZE);
    65. this.commonRdbmsReaderSlave.startRead(this.readerSliceConfig, recordSender,
    66. super.getTaskPluginCollector(), fetchSize);
    67. }
    68. @Override
    69. public void post() {
    70. this.commonRdbmsReaderSlave.post(this.readerSliceConfig);
    71. }
    72. @Override
    73. public void destroy() {
    74. this.commonRdbmsReaderSlave.destroy(this.readerSliceConfig);
    75. }
    76. }
    77. }

    8、plugin.json,这里面的name就是插件名,别和其他的重复了就行,后面要用

    1. {
    2. "name": "dmreader",
    3. "class": "com.alibaba.datax.plugin.reader.dmreader.DmReader",
    4. "description": "useScene: prod. mechanism: Jdbc connection using the database, execute select sql, retrieve data from the ResultSet. warn: The more you know about the database, the less problems you encounter.",
    5. "developer": "SiQiangMing"
    6. }

    9、package.xml这个是打包的配置,从mysql那边拷贝过来后,修改target和outputDirectory值

    1. <assembly
    2. xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    5. <id></id>
    6. <formats>
    7. <format>dir</format>
    8. </formats>
    9. <includeBaseDirectory>false</includeBaseDirectory>
    10. <fileSets>
    11. <fileSet>
    12. <directory>src/main/resources</directory>
    13. <includes>
    14. <include>plugin.json</include>
    15. <include>plugin_job_template.json</include>
    16. </includes>
    17. <outputDirectory>plugin/reader/dmreader</outputDirectory>
    18. </fileSet>
    19. <fileSet>
    20. <directory>target/</directory>
    21. <includes>
    22. <include>dmreader-0.0.1-SNAPSHOT.jar</include>
    23. </includes>
    24. <outputDirectory>plugin/reader/dmreader</outputDirectory>
    25. </fileSet>
    26. <fileSet>
    27. <directory>src/main/libs</directory>
    28. <includes>
    29. <include>*.*</include>
    30. </includes>
    31. <outputDirectory>plugin/reader/dmreader/libs</outputDirectory>
    32. </fileSet>
    33. </fileSets>
    34. <dependencySets>
    35. <dependencySet>
    36. <useProjectArtifact>false</useProjectArtifact>
    37. <outputDirectory>plugin/reader/dmreader/libs</outputDirectory>
    38. <scope>runtime</scope>
    39. </dependencySet>
    40. </dependencySets>
    41. </assembly>

    10、然后修改doc/dmreader.md和resource/plugin_job_template.json,这都不是重点了。这样就完事了,后来发现他们好像rdbmsreader就支持达梦,不过我没有使用,你们可以试试。

    三、生成环境运行与调试

    1、上传datax压缩包datax.tar到linux服务器

    2、解压datax压缩包到/usr/local下

            tar -xvf /路径/datax.tar -C /usr/local

    3、删除隐藏文件

    rm -rf /usr/local/datax/plugin/*/._*

    4、验证datax是否部署成功

    cd /usr/local/datax/bin

    python datax.py ../job/job.json

    四、调试过程遇到的问题

    在调试过程中遇到过一些问题,记不太清了,简单记录一下

    1、读取表的时候字段不要写类型,

    2、hdfs写入用户权限的问题,变量传递到job.json的问题。

    4、写入hdfs分区表的时候,需要load加载数据

    load data inpath "/user/hive/warehouse/hdfswriter.db/star/day=2022-09" into table star partition(day="day=2022-09");

  • 相关阅读:
    云原生技术-微服务SpringCloud(1)
    宏任务,微任务的几个经验的例子
    【机器学习算法】聚类分析-1 聚类是什么,我们如何确定类别间的相似性或者相异性
    第15届台州学院校赛题解
    git fetch 和 git pull 的区别
    5.springcloudalibaba nacos 2.2.3源码下载并且注册服务到nacos
    1100w播放、45w涨粉!黑马UP在B站20天逆袭登顶!
    vue的计算属性(computed)
    英语单词(二)
    如何使用 Apifox 来管理测试你的接口
  • 原文地址:https://blog.csdn.net/siqiangming/article/details/126769458