• kettle基于快照的CDC


    一、转换的输入输出需求

    ➢第一步将student_cdc表中的数据复制到student_cdc_sanp1表中,使 student_cdc_sanp1作为student_cdc表的第一个快照,同时将数据输出到 student_cdc_sync表中。

    ➢第二步对student_cdc中的数据进行插入、更新、删除操作

    ➢第三步将student_cdc表中的数据复制到student_cdc_sanp2表中,使 student_cdc_sanp2作为student_cdc表的第二个快照。

    ➢通过比较student_cdc_sanp1和student_cdc_sanp2表中的数据找出增量数据, 并将增量更新到student_cdc_sync表中

    效果图如下:

     表输入

    1.连接数据库

    点击新建

    1. SELECT 学号, 姓名, 性别, 班级, 年龄, 成绩, 身高, 手机,
    2. 插入时间, 更新时间, CURDATE() AS 导入时间 FROM student_cdc_snap1

    表输入 2

    1. SELECT 学号, 姓名, 性别, 班级, 年龄, 成绩, 身高, 手机,
    2. 插入时间, 更新时间, CURDATE() AS 导入时间 FROM student_cdc_snap2

    合并记录

     

    数据同步

     

     运行

    运行成功

    数据库预期表

     

    数据库脚本

    1. CREATE DATABASE `world`
    2. USE `world`;
    3. /*Table structure for table `student_cdc` */
    4. DROP TABLE IF EXISTS `student_cdc`;
    5. CREATE TABLE `student_cdc` (
    6. `学号` int(11) NOT NULL,
    7. `姓名` varchar(45) DEFAULT NULL,
    8. `性别` varchar(45) DEFAULT NULL,
    9. `班级` varchar(45) DEFAULT NULL,
    10. `年龄` varchar(45) DEFAULT NULL,
    11. `成绩` varchar(45) DEFAULT NULL,
    12. `身高` varchar(45) DEFAULT NULL,
    13. `手机` varchar(45) DEFAULT NULL,
    14. `插入时间` date DEFAULT NULL,
    15. `更新时间` date DEFAULT NULL
    16. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    17. /*Data for the table `student_cdc` */
    18. insert into `student_cdc`(`学号`,`姓名`,`性别`,`班级`,`年龄`,`成绩`,`身高`,`手机`,`插入时间`,`更新时间`) values (2,'李二','男','1701','17','80','175','18946554572','2018-08-06','2018-08-06'),(3,'谢逊','男','1702','18','95','169','18946554573','2018-08-06','2018-08-06'),(4,'赵玲','女','1702','19','86','180','18946554575','2018-08-06','2018-08-06'),(5,'张明','男','1704','20','85','185','18946554575','2018-08-07','2018-08-07'),(6,'张三','女','1704','18','82','169','18946554576','2018-08-06','2018-08-07'),(0,'李四','男','1701','17','82','170','18946554571','2023-10-09','2023-10-09');
    19. /*Table structure for table `student_cdc_snap1` */
    20. DROP TABLE IF EXISTS `student_cdc_snap1`;
    21. CREATE TABLE `student_cdc_snap1` (
    22. `学号` int(11) NOT NULL,
    23. `姓名` varchar(45) DEFAULT NULL,
    24. `性别` varchar(45) DEFAULT NULL,
    25. `班级` varchar(45) DEFAULT NULL,
    26. `年龄` varchar(45) DEFAULT NULL,
    27. `成绩` varchar(45) DEFAULT NULL,
    28. `身高` varchar(45) DEFAULT NULL,
    29. `手机` varchar(45) DEFAULT NULL,
    30. `插入时间` date DEFAULT NULL,
    31. `更新时间` date DEFAULT NULL
    32. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    33. /*Data for the table `student_cdc_snap1` */
    34. insert into `student_cdc_snap1`(`学号`,`姓名`,`性别`,`班级`,`年龄`,`成绩`,`身高`,`手机`,`插入时间`,`更新时间`) values (1,'张一','男','1701','16','78','170','18946554571','2018-08-06','2018-08-06'),(2,'李二','男','1701','17','80','175','18946554572','2018-08-06','2018-08-06'),(3,'谢逊','男','1702','18','95','169','18946554573','2018-08-06','2018-08-06'),(4,'赵玲','女','1702','19','86','180','18946554575','2018-08-06','2018-08-06'),(5,'张明','男','1704','20','85','185','18946554575','2018-08-07','2018-08-07'),(6,'张三','女','1704','18','92','169','18946554576','2018-08-06','2018-08-07');
    35. /*Table structure for table `student_cdc_snap2` */
    36. DROP TABLE IF EXISTS `student_cdc_snap2`;
    37. CREATE TABLE `student_cdc_snap2` (
    38. `学号` int(11) NOT NULL,
    39. `姓名` varchar(45) DEFAULT NULL,
    40. `性别` varchar(45) DEFAULT NULL,
    41. `班级` varchar(45) DEFAULT NULL,
    42. `年龄` varchar(45) DEFAULT NULL,
    43. `成绩` varchar(45) DEFAULT NULL,
    44. `身高` varchar(45) DEFAULT NULL,
    45. `手机` varchar(45) DEFAULT NULL,
    46. `插入时间` date DEFAULT NULL,
    47. `更新时间` date DEFAULT NULL
    48. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    49. /*Data for the table `student_cdc_snap2` */
    50. insert into `student_cdc_snap2`(`学号`,`姓名`,`性别`,`班级`,`年龄`,`成绩`,`身高`,`手机`,`插入时间`,`更新时间`) values (1,'张一','男','1701','16','78','170','18946554571','2018-08-06','2018-08-06'),(2,'李二','男','1701','17','80','175','18946554572','2018-08-06','2018-08-06'),(3,'谢逊','男','1702','18','95','169','18946554573','2018-08-06','2018-08-06'),(4,'赵玲','女','1702','19','86','180','18946554575','2018-08-06','2018-08-06'),(5,'张明','男','1704','20','85','185','18946554575','2018-08-07','2018-08-07'),(6,'张三','女','1704','18','82','169','18946554576','2018-08-06','2018-08-07'),(0,'李四','男','1701','17','82','170','18946554571','2023-10-09','2023-10-09');
    51. /*Table structure for table `student_cdc_sync` */
    52. DROP TABLE IF EXISTS `student_cdc_sync`;
    53. CREATE TABLE `student_cdc_sync` (
    54. `ID` int(11) NOT NULL AUTO_INCREMENT,
    55. `学号` int(11) NOT NULL,
    56. `姓名` varchar(45) DEFAULT NULL,
    57. `性别` varchar(45) DEFAULT NULL,
    58. `班级` varchar(45) DEFAULT NULL,
    59. `年龄` varchar(45) DEFAULT NULL,
    60. `成绩` varchar(45) DEFAULT NULL,
    61. `身高` varchar(45) DEFAULT NULL,
    62. `手机` varchar(45) DEFAULT NULL,
    63. `插入时间` date DEFAULT NULL,
    64. `更新时间` date DEFAULT NULL,
    65. PRIMARY KEY (`ID`)
    66. ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
    67. /*Data for the table `student_cdc_sync` */
    68. insert into `student_cdc_sync`(`ID`,`学号`,`姓名`,`性别`,`班级`,`年龄`,`成绩`,`身高`,`手机`,`插入时间`,`更新时间`) values (1,1,'张一','男','1701','16','78','170','18946554571','2018-08-06','2018-08-06'),(2,2,'李二','男','1701','17','80','175','18946554572','2018-08-06','2018-08-06'),(3,3,'谢逊','男','1702','18','95','169','18946554573','2018-08-06','2018-08-06'),(4,4,'赵玲','女','1702','19','86','180','18946554575','2018-08-06','2018-08-06'),(5,5,'张明','男','1704','20','85','185','18946554575','2018-08-07','2018-08-07'),(6,6,'张三','女','1704','18','92','169','18946554576','2018-08-06','2018-08-07');
    69. /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
    70. /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
    71. /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
    72. /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

  • 相关阅读:
    leetcode143-Reorder List
    软件测试月薪28K大厂面试题 (经面试官允许可以拿走试卷)
    adb 命令速查(下)
    golang - 控制协程并发数的3种方法
    WebDAV之葫芦儿·派盘+书藏家
    【数据分析实战】金融评分卡建立
    别再乱看教程了!从源码剖析JVM类加载机制,打通双亲委派机制!
    字符数组基础知识
    【附安装包】3ds Max2023安装教程
    CentOS中实现基于Docker部署BI数据分析
  • 原文地址:https://blog.csdn.net/m0_55834564/article/details/133750228