# 数据源Doris到目标Doris数据同步
本示例主要演示从Doris读取数据,写入Doris库中。
主要步骤如下:
# 准备数据
- 创建 Doris 源数据库 testdb,在源数据库 testdb 中创建一个表 orderinfo。
drop table if exists `orderinfo`;
CREATE TABLE `orderinfo` (
`ordercode` varchar(32) NOT NULL COMMENT "订单号",
`amount` int(11) NULL COMMENT "数量",
`price` varchar(32) NULL COMMENT "价格",
`manufacturer2` varchar(100) NULL COMMENT "厂商",
`createtime` date NULL COMMENT "创建时间",
`createuser` varchar(32) NULL COMMENT "创建人",
`updatetime` datetime NULL COMMENT "更新时间"
) ENGINE=OLAP
UNIQUE KEY(`ordercode`)
DISTRIBUTED BY HASH(`ordercode`)
PROPERTIES ('replication_num'='1');
INSERT INTO orderinfo
(ordercode, amount, price, manufacturer2, createtime, createuser, updatetime)
VALUES('001', 1000, '5000', '星云制造', '2023-10-25', '张无忌4', '2024-01-04 12:00:00');
INSERT INTO orderinfo
(ordercode, amount, price, manufacturer2, createtime, createuser, updatetime)
VALUES('002', 50022, '1000', '西安金属', '2018-12-13', '张无忌4', '2018-12-13 00:00:00');
INSERT INTO orderinfo
(ordercode, amount, price, manufacturer2, createtime, createuser, updatetime)
VALUES('003', 1500, '7000', '枫禾林木', '2018-12-13', '魏雨', '2024-01-11 00:00:00');
INSERT INTO orderinfo
(ordercode, amount, price, manufacturer2, createtime, createuser, updatetime)
VALUES('004', 1000, '75000', '星峰', '2019-01-13', '王林', '2019-01-13 12:23:01');
INSERT INTO orderinfo
(ordercode, amount, price, manufacturer2, createtime, createuser, updatetime)
VALUES('005', 1300, '8000', '天威科技', '2018-12-13', '王林', '2018-12-13 00:00:00');
INSERT INTO orderinfo
(ordercode, amount, price, manufacturer2, createtime, createuser, updatetime)
VALUES('006', 2000, '5000', '微云科', '2023-10-25', '王林', '2023-10-25 00:00:00');
INSERT INTO orderinfo
(ordercode, amount, price, manufacturer2, createtime, createuser, updatetime)
VALUES('007', 3000, '9001', '西安金属', '2024-12-13', '王强', '2020-12-13 11:11:11');
INSERT INTO orderinfo
(ordercode, amount, price, manufacturer2, createtime, createuser, updatetime)
VALUES('008', 12300, '11589', '星峰', '2018-12-13', '王强', '2024-02-04 12:00:00');
INSERT INTO orderinfo
(ordercode, amount, price, manufacturer2, createtime, createuser, updatetime)
VALUES('009', 5100, '22909', '星云制造', '2018-12-13', '魏雨', '2018-12-13 23:59:59');
INSERT INTO orderinfo
(ordercode, amount, price, manufacturer2, createtime, createuser, updatetime)
VALUES('010', 1800, '15900', '天威科技', '2018-12-13', '魏雨', '2018-12-13 00:00:00');
- 创建 Doris 目标数据库 testdb2,在目标数据库 testdb2中创建一个表 orderinfo,如果表已经存在可以忽略该步骤。
drop table if exists `orderinfo`;
CREATE TABLE `orderinfo2` (
`ordercode` varchar(32) NOT NULL COMMENT "订单号",
`amount` int(11) NULL COMMENT "数量",
`price` varchar(32) NULL COMMENT "价格",
`manufacturer2` varchar(100) NULL COMMENT "厂商",
`createtime` date NULL COMMENT "创建时间",
`createuser` varchar(32) NULL COMMENT "创建人",
`updatetime` datetime NULL COMMENT "更新时间"
) ENGINE=OLAP
UNIQUE KEY(`ordercode`)
DISTRIBUTED BY HASH(`ordercode`)
PROPERTIES ('replication_num'='1');
# 新建同步作业
点击数据同步上的【...】,选择弹出菜单【新建数据同步作业】,作业名称为:doris-doris。
# 拖拽图元
依次拖拽数据源中的Doris Source组件和目标中的Doris Sink组件,依次连线。如下图所示:
# 配置组件属性
1、双击"Doris Source"组件,根据下图所示步骤依次配置。
2、双击"Doris Sink"组件,根据下图所示步骤依次配置。
3、Ctrl+S保存该模型。
# 运行
点击【运行】按钮,可以运行已经开发完毕的场景,在日志栏可以看运行日志及运行结果。
# 查看数据
从SQL客户端中查看Doris目标表。
# 提交版本
当草稿运行正常后,点击【提交】按钮可以将该版本提交到作业调度,每次修改提交都会生成新的版本,可以看到提交的历史版本,并可以随意切换版本。
提交后的版本,可以在作业调度中进行"定时"调度配置。