数据质量平台社区版,支持 SpringEL 表达式计算引擎对数据进行质量检测。
EL 表达式计算结果只能是
true或false。
获取变量
在 EL 中,使用 #column 来获取每条检测数据中该列对应的值。
其中:
column代表数据库列名- 区分大小写
示例
需要检查的字段:
- 人员薪水:
salary - 基础工资:
base_salary - 岗位津贴:
work_salary - 发薪日:
send_salary_date
其中 send_salary_date 为字符串类型。
获取字段值的表达式:
#salary
#base_salary
#work_salary
运算符
注意:表达式中的单引号
'和感叹号!必须使用英文符号。
算术运算符
| 符号 | 描述 | 示例 |
|---|---|---|
| + | 加法 | #a == (#b + #c) |
| - | 减法 | #a == (#b - #c) |
| * | 乘法 | #a == (#b * #c) |
| /、div | 除法 | #a == (#b / #c) |
| %、mod | 取模运算 | #a == (#b % #c) |
| ^ | 幂运算 | #a == (#b ^ #c) |
关系运算符
| 符号 | 描述 | 示例 |
|---|---|---|
| ==、eq | 等于 | #a == #b |
| !=、ne | 不等于 | #a != #b |
| <、lt | 小于 | #a < #b |
| <=、le | 小于等于 | #a <= #b |
| >、gt | 大于 | #a > #b |
| >=、ge | 大于等于 | #a >= #b |
逻辑运算符
| 符号 | 描述 | 示例 |
|---|---|---|
| &&、and | 与 | #a == #b && #a == #c |
| ||、or | 或 | #a == #b || #a == #c |
| !、not | 非 | !true、!false |
正则表达式
| 符号 | 描述 | 示例 |
|---|---|---|
| matches | 检查一个值是否满足正则表达式 | #a matches '\d{4}-\d{2}-\d{2}' |
其他常用语法
| 语法 | 描述 | 示例 |
|---|---|---|
| length() | 获取字符串长度 | #a.length() == 8 |
| toString() | 数字转字符串 | #a.toString().length() == 8 |
| contains() | 判断字符串是否包含指定内容 | #a.contains('2000') |
| null | 判断为空 | #a == null |
| '' | 判断空字符串 | #a == '' |
空值判断
检查一个值是否为空:
#a == null and #a == ''
说明:
- 值为
null - 空字符串
- 空数组
- 空集合
均视为空。
示例
场景描述
需要检查的字段:
| 字段名称 | 字段编码 | 类型 |
|---|---|---|
| 人员薪水 | salary | 整数 |
| 基础工资 | base_salary | 整数 |
| 岗位津贴 | work_salary | 整数 |
| 发薪日 | send_salary_date | 字符串 |
| 人员职称 | position | 字符串 |
| 人员在职状态 | status | 字符串 |
| 人员姓名 | name | 字符串 |
约束条件:
- position:初级 / 中级 / 高级
- status:在职 / 离职
1. 人员薪水等于基础工资和岗位津贴之和
#salary == (#base_salary + #work_salary)
2. 基础工资等于人员薪水减去岗位津贴
#base_salary == (#salary - #work_salary)
3. 岗位津贴为 0 时,薪水与津贴乘积为 0
0 == (#salary * #work_salary)
4. 岗位津贴为 0 时,薪水与津贴相除结果为 1
1 == (#salary / #work_salary)
5. 人员薪水对 1000 取模结果为 1
1 == (#salary % 1000)
6. 人员薪水的平方计算
#salary ^ 2 == (#salary * #salary)
7. 人员薪水等于基础工资
#salary == #base_salary
8. 人员薪水不等于基础工资
#salary != #base_salary
9. 基础工资小于人员薪水
#base_salary < #salary
10. 人员薪水大于基础工资且大于岗位津贴
#salary > #base_salary && #salary > #work_salary
11. 人员薪水大于基础工资或者大于岗位津贴
#salary > #base_salary || #salary > #work_salary
12. 发薪日格式为 yyyy-MM-dd
#send_salary_date matches '\d{4}-\d{2}-\d{2}'
13. 人员姓名不能为空
#name != null and #name != ''
14. 人员在职状态必须为在职
#status == '在职'
15. 人员职称长度为 2
#position.length() == 2