Data quality inspection is an important part of the data processing process. After data synchronization and data processing, it is usually necessary to check the accuracy of the data, such as comparing the difference in the number of data between the source table and the target table, or checking according to a certain rule that calculate a certain column and compare the standard value and the calculated value to judge. At present, there is no such type of data quality check in the task type of DS, so it is necessary to add a new data quality task type so that the data quality check task can be directly added when defining the workflow, so that the entire data processing process is more complete.
For data quality inspection tasks, the core functions are rule management, specific task execution, and execution result alarms. To achieve a lightweight data quality, the following functions must be met:
The complete rules should include connector information, executed SQL statements, the type of comparison value, the type of inspection, etc., that is, the parameters needed to define a data quality task can be obtained through the rules
The main responsibility of rule parser is to obtain an parameter that conforms to the execution of the data quality task by parsing the parameter value input by the user and the rule definition.
Based on the existing task execution method of DolphinScheduler, a more appropriate way is to use Spark as the execution engine for data quality tasks, pass specific execution SQL to the Spark job to run through configuration, and write the execution results to the specified storage engine
Each rule configure alertrules, when the check result is abnormal, an alertoccurs. Use DS's alert module for alarm

Data quality tasks do not support separate definition and scheduled scheduling, which can be defined and scheduled in the workflow
The data quality task definition UI interface will automatically generated by the front-end component according to a JSON string.


| column | type | comment |
| :---------- | :----- | :---------------------------------- |
| id | int | id |
| name | string | rule name |
| type | int | rule type:single-table/multi-table |
| rule_json | text | rule definition |
| create_time | date | create time |
| update_time | date | update time |
| column | type | comment |
| :--------------- | :----- | :------------------------------------ |
| id | int | id |
| task_id | long | Task ID |
| task_instance_id | long | TaskInstance ID |
| rule_type | int | rule type |
| statistics_value | double | statistics value |
| comparsion_value | double | comparsion value |
| check_type | int | check type,fixed value or percentage |
| threshold | double | threshold |
| operator | int | operator:>,<,=,>=,<= |
| create_time | date | create time |
| update_time | date | update time |
1)Connector Parameter Parser
To get the information of datasource including url, database, table, username, password according the datasource_id and constructed information of connector
2)Replace the placeholders in executeSQL to construct an executeSQL list
3)Construct writer configuration, including construct writer connector configuration and saveSQL
if(comparsionType == FIXED){
map.put("${comparsion_name}","fixed_value")
sql = "select ${comparsion_name} as comparsion_value from ${staticsTableName}
} else {
sql = "select ${comparsion_name} as comparsion_value from ${statics_table_Name} full join ${comparsion_table_Name}
}
resultSQL = sql.replacePlaceholder(map)
Finally, it will be constructed into the json string parameter and passed to the Spark application
DataQualityParameter
DataQualityTask
1)The data quality task is actually a Spark task. The main responsibilities of this task are as follows:
2)The execute mode has the follow options
issue: DataQuality Application
pr: DataQuality Common Entity
数据质量检查是数据处理流程中比较重要的环节,在数据同步和数据处理后通常是需要检查数据的准确性,例如比较源表和目标表之间的数据条数差,或者根据某个规则对某一列进行计算,将标准值和计算值进行比较判断。目前在 DS 的任务类型没有数据质量检查这样的类型,所以需要新增数据质量任务类型,以便于在定义工作流的时候可以直接添加数据质量检查任务,让整个数据处理流程更加的完整。
对于数据质量检查任务来说,核心的功能就是规则管理、具体的任务执行以及执行结果告警,实现一个轻量级的数据质量需要满足以下功能:
完整的规则应该包括 connector 信息、执行的 sql 语句、比较值的类型,检查的类型等,即通过规则可以获取定义一个数据质量任务所需要的参数
规则解析主要职责是通过解析用户输入的参数值和规则定义得到一个符合数据质量任务运行的输入参数
基于 DolphinScheduler 现有的任务执行方式,比较合适的方式就是使用 Spark 作为数据质量任务的执行引擎,通过配置的方式将具体的执行 SQL 传入 Spark 作业来运行,并将执行的结果写到指定的存储引擎中
每个规则都会配置告警规则,当检查结果为异常的话,则会进行告警。使用 DolphinScheduler 的告警模块进行告警
select ${statistics_name} as statistics_value,${comparsion_name} as coparsion_value from ${statistics_execute_sql} full join ${comparsion_execute_sql}

数据质量任务不支持单独定义和定时调度,可以通过在工作流中定义和定时调度
数据质量任务定义 UI 界面会根据不同规则的参数生成 JSON 串由前端组件自动生成


| 字段 | 类型 | 解释 |
| :---------- | :----- | :-------------------------- |
| id | int | id |
| name | string | 规则名称 |
| type | int | 规则类型:单表规则/跨表规则 |
| rule_json | text | 规则定义 |
| create_time | date | 创建时间 |
| update_time | date | 更新时间 |
| 字段 | 类型 | 解释 |
| :--------------- | :----- | :--------------------------------------------------- |
| id | int | id |
| task_id | long | 任务 ID |
| task_instance_id | long | 任务实例 ID |
| rule_type | int | 规则类型 |
| statistics_value | double | 计算的指标值 |
| comparsion_value | double | 比对的指标值 |
| check_type | int | 检测类型,数值比较或者百分比 |
| threshold | double | 阈值 |
| operator | int | 操作符:大于,小于,等于,不等于,大于等于,小于等于 |
| create_time | date | 创建时间 |
| update_time | date | 更新时间 |
1) 规则使用的流程分析
2)规则解析具体内容
根据 datasource_id 拿到相关的数据源信息,包括 url,database,table,username,password,构造 connector 配置
if(comparsionType == FIXED){
map.put("${comparsion_name}","fixed_value")
sql = "select ${comparsion_name} as comparsion_value from ${staticsTableName}
} else {
sql = "select ${comparsion_name} as comparsion_value from ${statics_table_Name} full join ${comparsion_table_Name}
}
resultSQL = sql.replacePlaceholder(map)
3)最终会构造成json 格式 的参数传给 Spark 应用
DataQualityParameter
DataQualityTask
1)数据质量任务实际上是一个 Spark 任务,这个任务的主要责任是如下:
2)运行方式可如下:
issue: DataQuality Application
pr: DataQuality Common Entity
good feature
LGTM
Essential functions of big data ETL System~~Looking forward to going online soon
Essential functions of big data ETL System~~Looking forward to going online soon
+1
Version 1.0
Data quality type task development, including front end and back end (development completed)
Automatic generation of rule input items by selecting rules in front-end interface (development completed)
Provide a variety of detection methods (developed)
Provide multiple failure strategies (development completed)
The main responsibility of the executor with spark as the computing engine is to run data quality detection SQL (developed)
Built in multiple detection rules, including single table null value detection, cross table accuracy detection, cross table value comparison and single table custom SQL detection, etc. (developed)
Quality inspection results view, including front end and back end (development completed)
Rule management, only support view (development completed)
Data source only supports JDBC and hive (developed)
Version 2.0 (Time to be determined)
Optimize the user experience of front-end input items, introduce metadata management of multiple data sources, select tables and columns, etc. (to be developed)
Provide custom rule template, support single table rule customization (to be developed)
New rules modification and deletion (to be developed)
Support abnormal data export (to be developed)
Support multiple data source detection, such as file, ES, etc. (to be developed)
Support to run data quality inspection task independently (to be developed)
1.0 版本 (本地开发已完成95%以上,尚未提PR)



2.0 版本 (时间待定)
+1
+1
+1
@zixi0825 大佬,想请教一下怎么才能将您完成的功能跑起来?
@zixi0825 大佬,想请教一下怎么才能将您完成的功能跑起来?
It is not completed yet
Most helpful comment
Essential functions of big data ETL System~~Looking forward to going online soon