ZCBUS ETL函数测试(本次测试发布端为ORACLE)

一、测试表及全量数据(仅供参考,可根据个人情况更改)

create table customer_table(customer_id number(8) primary key,name varchar2(16),age number,phone varchar2(14),sex varchar2(8),area varchar2(10),create_time timestamp,op_time timestamp);
insert into customer_table values(1,'billson',12,'13124567890','man','shanghai',to_date('2017-05-01 16:11:13','yyyy-MM-dd HH24:mi:ss'),sysdate);
insert into customer_table values(2,'velian',18,'13054329876','man','shanghai',to_date('2017-05-09 09:41:35','yyyy-MM-dd HH24:mi:ss'),sysdate);
insert into customer_table values(3,'alise',43,'18711204567','woman','beijing',to_date('2018-08-23 13:53:20','yyyy-MM-dd HH24:mi:ss'),sysdate);
insert into customer_table values(4,'zhanghong',51,'18334259087','woman','beijing',to_date('2018-08-24 13:56:10','yyyy-MM-dd HH24:mi:ss'),sysdate);
insert into customer_table values(5,'wanggang',19,'18601101234','man','shenzhen',to_date('2019-05-12 14:30:25','yyyy-MM-dd HH24:mi:ss'),sysdate);
insert into customer_table values(6,'wanghong',26,'18601101235','woman','shenzhen',to_date('2019-07-10 08:03:45','yyyy-MM-dd HH24:mi:ss'),sysdate);
insert into customer_table values(7,'runtu',31,'13004099987','man','shanghai',to_date('2020-08-23 17:43:59','yyyy-MM-dd HH24:mi:ss'),sysdate);
insert into customer_table values(8,'fengqing',60,'13004099990','woman','beijing',to_date('2020-03-25 10:55:01','yyyy-MM-dd HH24:mi:ss'),sysdate);
insert into customer_table values(9,'meiye',65,'13004099991','man','shenzhen',to_date('2021-06-19 10:34:21','yyyy-MM-dd HH24:mi:ss'),sysdate);
insert into customer_table values(10,'lengmeng',22,'13004099992','woman','beijing',to_date('2012-02-28 20:38:12','yyyy-MM-dd HH24:mi:ss'),sysdate);
insert into customer_table values(11,'qiuqiu',32,'13004099988','woman','shenzhen',to_date('2020-02-18 11:23:50','yyyy-MM-dd HH24:mi:ss'),sysdate);
insert into customer_table values(12,'wangzha',15,'13004099989','man','beijing',to_date('2020-07-31 13:43:45','yyyy-MM-dd HH24:mi:ss'),sysdate);

二、增量数据(仅供参考,可根据个人情况更改)

##插入:

insert into customer_table values(13,'mixian',24,'13004099993','woman','shanghai',to_date('2016-07-21 12:43:43','yyyy-MM-dd HH24:mi:ss'),sysdate);

##更新:
update customer_table set sex='WomaN' where customer_id=2;
update customer_table set sex='MAN' where customer_id=4;

update customer_table set area=' BEIJING ' where customer_id =3;
update customer_table set area='   BEIJING' where customer_id=12;
update customer_table set area='BEIJING   ' where customer_id=4;
update customer_table set area='shenzhen' where customer_id =8;
update customer_table set customer_id=-7 where customer_id=7;
update customer_table set age=23.141592 where customer_id=-7;
update customer_table set age=0.9 where customer_id=10;
update customer_table set area='shanghai' where customer_id=10;
update customer_table set customer_id=7 where customer_id=-7;

##删除:
delete customer_table where customer_id=13;

三、ETL函数基本规则应用

## 数据过滤:

## 筛选出所有SEX等于大写man的数据,并允许对其做DML操作
PASS(sqltype=(on=insert,on=delete,on=update),condition=(sex=(@LOWER('MAN'))))

## 同上
PASS(sqltype=(on=insert,on=delete,on=update),condition=(sex='MAN'))

## 同上,不过条件改为sqlcondition
PASS(SQLTYPE(ON=INSERT,ON=UPDATE,ON=DELETE),SQLCONDITION=(select sex from test_caolh.a where sex=#sex#))
注:该SQLCONDITION的规则启用,有3处注意点:
    1、ETL规则配置时必须启用数据库
    2、在启用的数据库中新建一张test_caolh.a的表,test_caolh.a的表中存储有参考条件的值,如上ETL规则中test_caolh.a的表SEX中的值为man
    3、sex=#sex#:前面一个sex指的是test_caolh.a中的sex字段,后面一个#sex#为发布表customer_table的列名,列名可以不一致,如:
        PASS=(SQLTYPE=(ON=INSERT,IGNORE=UPDATE,ON=DELETE),SQLCONDITION=(select sex from test_caolh.a where sex=#area#))
        上面的sex匹配的则是发布表customer_table的area列(不能写成具体的值)


##数据转换:

##取消area字段内容左侧空格
COLMAP(column_name=area,optype=modify,data_type=string,function=(@LTRIM(area)))

##取消area字段内容右侧空格
COLMAP(column_name=area,optype=modify,data_type=string,function=(@RTRIM(area)))

##取消area字段内容两侧空格:
COLMAP(column_name=area,optype=modify,data_type=string,function=(@TRIM(area)))

##将sex字段内容改为大写
COLMAP(column_name=sex,optype=modify,data_type=string,function=(@UPPER(sex)))

##将sex字段内容改为小写
COLMAP(column_name=sex,optype=modify,data_type=string,function=(@LOWER(sex)))

##截取phnoe字段内容第1~5位的内容
COLMAP(column_name=phone,optype=modify,data_type=string,function=(@substr(phone,1,5)))

##将area字段内容与1,2,3,4,5,6,7拼接
COLMAP(column_name=area,optype=modify,data_type=string,function=(@CONCAT(area,'1','2','3','4','5','6','7')))

##将area字段内容与'beijing'比较,两边字符串相同,返回结果为0,如果左边大于右边,返回1,如果左边小于右边,返回-1
**注:是字符串的ASCII码比较**
COLMAP(column_name=area,optype=modify,data_type=string,function=(@STRCMP(area,'beijing')))

##与@STRCMP相同,只是忽略大小写
COLMAP(column_name=area,optype=modify,data_type=string,function=(@STRICMP(area,'SHENZHEN')))

##统计name字段内容的长度
COLMAP(column_name=name,optype=modify,data_type=string,function=(@LENGTH(name)))

##从phnoe字段内容第1个位置开始查找'0'第2次出现的位置
COLMAP(column_name=phone,optype=modify,data_type=string,function=(@INSTR(phone,'0',1,2)))

##将area字段中第一次匹配的'bei'替换成'nan'
COLMAP(column_name=area,optype=modify,data_type=string,function=(@REPLACE(area,'bei','nan')))

##将phone字段中所有的'0409'替换成'1100'
COLMAP(column_name=phone,optype=modify,data_type=string,function=(@REPLACEALL(phone,'0409','1100')))

##将@RANDOMSTRING(4)产生的随机4位字符串与area字段内容拼接
COLMAP(column_name=area,optype=modify,data_type=string,function=(@CONCAT(area,@RANDOMSTRING(4))))

##将sex字段内容反序输出
COLMAP(column_name=sex,optype=modify,data_type=string,function=(@STRINGREVERSE(sex)))

##将phone字段第4到第7位替换成'****'
COLMAP(column_name=phone,optype=modify,data_type=string,function=(@STRSUBPOINT(phone,4,7,'****')))

##将customer_id字段内容转换为字符型
COLMAP(column_name=customer_id,optype=modify,data_type=number,function=(@NUMSTR(customer_id)))

##将customer_id字段内容转换为二进制
COLMAP(column_name=customer_id,optype=modify,data_type=number,function=(@NUMBIN(customer_id)))

##将customer_id字段内容转换为16进制
COLMAP(column_name=customer_id,optype=modify,data_type=number,function=(@NUMHEX(customer_id)))

##将customer_id字段内容与(10%4)/2*3进行运算
COLMAP(column_name=customer_id,optype=modify,data_type=number,function=(@COMPUTE(customer_id+(10%4)/2*3)))

##将customer_id字段内容与@RANDOM(3)随机产生的3位数进行运算
COLMAP(column_name=customer_id,optype=modify,data_type=number,function=(@COMPUTE(customer_id+@RANDOM(3))))

##对customer_id字段内容取绝对值
COLMAP(column_name=customer_id,optype=modify,data_type=number,function=(@ABS(customer_id)))

##取大于或等于age字段的最小整数值
COLMAP(column_name=age,optype=modify,data_type=number,function=(@CEIL(age)))

##取小于或等于age字段的最大整数值
COLMAP(column_name=age,optype=modify,data_type=number,function=(@FLOOR(age)))

##将age字段除3取余数
COLMAP(column_name=age,optype=modify,data_type=number,function=(@MOD(age,3)))

##对age字段小数位第4位四舍五入取值
COLMAP(column_name=age,optype=modify,data_type=number,function=(@ROUND(age,4)))

##对age字段小数位第3位进行截取,不考虑四舍五入
COLMAP(column_name=age,optype=modify,data_type=number,function=(@TRUNC(age,3)))

##对age字段进行2次幂运算
COLMAP(column_name=age,optype=modify,data_type=number,function=(@POWER(age,2)))

##对age字段进行平方根运算取值
COLMAP(column_name=age,optype=modify,data_type=number,function=(@SQRT(age)))

##取age字段为底3的对数
COLMAP(column_name=age,optype=modify,data_type=number,function=(@LOG(age,3)))

##取age字段的正弦值
COLMAP(column_name=age,optype=modify,data_type=number,function=(@SIN(age)))

##取age字段的余弦值
COLMAP(column_name=age,optype=modify,data_type=number,function=(@COS(age)))

##取age字段的反正弦值
COLMAP(column_name=age,optype=modify,data_type=number,function=(@ASIN(age)))

##取age字段的反余弦值
COLMAP(column_name=age,optype=modify,data_type=number,function=(@ACOS(age)))

##将op_time改为系统当前日期
COLMAP(column_name=op_time,optype=modify,data_type=date,function=(@DATE()))

##将op_time改为系统当前日期时间
COLMAP(column_name=op_time,optype=modify,data_type=date,function=(@DATENOW()))

##添加一个abc字段,并取create_time字段与op_time字段的时间差值
COLMAP(column_name=abc,optype=add,data_type=date,function=(@DATEDIFF(create_time,op_time,'yyyy-MM-dd HH:mi:ss','s')))

##删除字段phone
COLMAP(column_name=phone,optype=drop)

##重命名字段phonemobile_phone
COLMAP(column_name=phone,optype=rename,after_column_name=mobile_phone)





##事件触发:


文档更新时间: 2022-04-06 23:04   作者:操李红