Using Data Quality Rules in Astera
The Data Quality Rules object found in the Data Profiling section of the Toolbox is used to apply one or more conditions, called Data Quality Rules, against incoming records. Records that do not meet the data quality rule criteria will be assigned the ‘Error’ status and may be optionally excluded from processing by the downstream objects.
Data Quality Rules is a record-level component which means that it does not require the entire dataset to flow through it. In other words, you can map a single or a couple of fields to the Data Quality Rules component to set up quality validation criteria and the transformed records can be mapped further in the dataflow.
Video
Steps to Use the Data Quality Rules in a Dataflow
Let’s understand the application and usage of Data Quality Rules with the following example.
Here we have sample data of employees of a fictitious organization which we have retrieved using an Excel Workbook Source.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2F3083465318-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsR50Wa7EwZGlmPSAMkkf%252Fuploads%252F8mCAuLaLRLq1IJvg9Tky%252F1_data.png%3Falt%3Dmedia%26token%3D8952cbc1-eea7-4daf-bdb2-c53099f213f7&width=768&dpr=4&quality=100&sign=1973a5e8&sv=1)
If we look at the preview of the Employee_Report dataset, the values in the SalariedFlag column specify whether an employee is salaried in terms of 0 and 1.
1 = the employee is salaried
0 = the employee is non-salaried and therefore is eligible for overtime.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2F3083465318-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsR50Wa7EwZGlmPSAMkkf%252Fuploads%252F4CBeNK8kjaIjT2lUufKY%252F2_data_preview.png%3Falt%3Dmedia%26token%3Def860f2f-05ae-4ad3-953b-5e3d6efad8ac&width=768&dpr=4&quality=100&sign=f914cf22&sv=1)
We can apply data quality rules to these values and identify which employees are not salaried and therefore, are eligible for overtime. The Data Quality Rules object will process all records and those that do not match the criteria will be returned with an error. This means that in this example, the salaried employees with the salary flag ‘True’ will return an error, whereas the records of employees with the salary flag ‘False’ will pass the data quality rule.
To do this, drag the Data Quality Rules object from the Data Profiling section in the Toolbox and drop it onto the dataflow designer.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2F3083465318-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsR50Wa7EwZGlmPSAMkkf%252Fuploads%252FH14V4Y6D2VPoIaVqBUTN%252Fdata_quality_gif.gif%3Falt%3Dmedia%26token%3De2d7d782-54c4-4311-b359-657cc10965fd&width=768&dpr=4&quality=100&sign=bdb4d887&sv=1)
Now, map the SalariedFlag field to the Data Quality Rules object.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2F3083465318-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsR50Wa7EwZGlmPSAMkkf%252Fuploads%252FuyyE1heGSdblyxLXNcK1%252Fdata_quality_mapping_gif.gif%3Falt%3Dmedia%26token%3D0931ea7c-bf4f-44fa-8aa6-f5772a848cab&width=768&dpr=4&quality=100&sign=13057d0f&sv=1)
Right-click on the Data Quality Rules object and select Properties from the context menu.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2F3083465318-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsR50Wa7EwZGlmPSAMkkf%252Fuploads%252FGj00KCOMP8JPjuZC9Hsd%252F3_properties.png%3Falt%3Dmedia%26token%3D68e9e310-7207-4394-b7c1-dcce5352e4a6&width=768&dpr=4&quality=100&sign=e7bef8a&sv=1)
This will open a new window. This is the Layout Builder, where you can see the ‘SalariedFlag’ field we have mapped from our source.
Click Next to proceed to the Data Quality Rules window.
Once a new rule is added, the options on this window will activate and the rule will be added to the grid.
Let’s explore these options one by one:
Description: The Description field contains the name or description of the rule. By default, the rules are termed as Rule1, Rule2 and so on, depending on the number of rules you add. But you can also rename the rules for better understanding and convenience.
In our case, as we want to set a data quality criteria to identify non-salaried employees, we can rename the rule as “NonSalariedEmployeesRule.”
Attach rule to the field: This is a drop-down list using which you can attach a rule to a particular field. You can see that there is a root node named Data Quality Rules.
Listed within the Data Quality Rules node are the fields mapped to the Data Quality Rules object. Here we have only one field mapped to which we want to apply this rule. In case you want to apply a rule to the whole dataset, you can simply double-click on the Data Quality Rules root node and the rule will be applied to all fields mapped to the Data Quality Rules object.
In this case, we will map the rule to the SalariedFlag field.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2F3083465318-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsR50Wa7EwZGlmPSAMkkf%252Fuploads%252FKYSdKCsFn4PTef5e59eC%252F8_attach_rule_to_field.png%3Falt%3Dmedia%26token%3D0fc058b4-775c-4837-b907-e11b920b3fd0&width=768&dpr=4&quality=100&sign=f0a32002&sv=1)
Expression box: This is where you can type in the expression for your rule.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2F3083465318-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsR50Wa7EwZGlmPSAMkkf%252Fuploads%252FXGp3SVuXQcxMFMBvS1pt%252F9_expressiom_box.png%3Falt%3Dmedia%26token%3D740dc0b9-ee0f-4529-b660-b80f16b737f6&width=768&dpr=4&quality=100&sign=34be1640&sv=1)
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2F3083465318-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsR50Wa7EwZGlmPSAMkkf%252Fuploads%252F5AJGWSk2q0uDldOmoioJ%252F10_functions.png%3Falt%3Dmedia%26token%3Da3a1bd79-fe9f-4015-a8bc-a3bf999df8a1&width=768&dpr=4&quality=100&sign=a074dea7&sv=1)
In this example, we want to validate records with the Salary Flag ‘False.’ To do this we will write the expression:
‘SalariedFlag = 0’ in the Expression field.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2F3083465318-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsR50Wa7EwZGlmPSAMkkf%252Fuploads%252FNp2vJaBusGSEa7vrgCFC%252F11_expression.png%3Falt%3Dmedia%26token%3Dde793cc3-c6f7-4e62-9287-0f88ac1123af&width=768&dpr=4&quality=100&sign=219ce756&sv=1)
Observe that, simultaneously, Astera shows you a compile status of your expression below the expression box.
It says ‘Successful’ so we can click OK. Alternatively, it will give you an error if the expression is incorrect and you will have to correct the expression before clicking OK.
Show Message: We can also write a message to show up with the errors, which can also be written to the error log. Let’s write a message:
‘Salaried employees are not eligible for overtime.’
This message will help identify why a particular record was marked erroneous. And in case multiple rules are applied, the message will point out which rule was not qualified by a particular record.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2F3083465318-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsR50Wa7EwZGlmPSAMkkf%252Fuploads%252FCtHlOCeIsgjZmzbyhbSw%252F12_error_message.png%3Falt%3Dmedia%26token%3D6a56009a-58a5-4715-befb-39781107e385&width=768&dpr=4&quality=100&sign=650ebb13&sv=1)
Next, we have two checkboxes:
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2F3083465318-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsR50Wa7EwZGlmPSAMkkf%252Fuploads%252FtY2HVx4aTE8ea75T2CAl%252F13_status.png%3Falt%3Dmedia%26token%3Dea12b427-880f-47ff-8fc7-237d9e10de70&width=768&dpr=4&quality=100&sign=7d033336&sv=1)
Active – to activate a rule.
Is Error – when this is checked, all records that return an error will not be written to a target. Which means that only the records that have passed the data quality rule will flow further in the dataflow pipeline.
However, if we uncheck this option, it will automatically check the Warning checkbox. This will return the records that failed to match the rule with a warning and will be written to a target.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2F3083465318-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsR50Wa7EwZGlmPSAMkkf%252Fuploads%252FNrh5jk1sqoGWAB3BB5dX%252F14_warning.png%3Falt%3Dmedia%26token%3D771465de-4656-448c-a21b-d35766e8b552&width=768&dpr=4&quality=100&sign=3bbb011c&sv=1)
In this case, let’s keep the errors as errors by checking the Is Error box.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2F3083465318-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsR50Wa7EwZGlmPSAMkkf%252Fuploads%252Fy5YSjhCMiDWYUc1ELOti%252F15.png%3Falt%3Dmedia%26token%3D5a1264e5-3b66-4f18-b54c-52d7ec227708&width=768&dpr=4&quality=100&sign=29267298&sv=1)
Now we have set up a data quality rule.
You can add as many rules as you want by clicking this button and similarly, you can also delete a rule by pointing it in the grid and then right-click > Delete. In this example, we will work with a single rule which has been set, so let’s go ahead and click OK.
Now, let’s look at the preview. Right-click on the Data Quality Rules object and select Preview Output from the context menu.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2F3083465318-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsR50Wa7EwZGlmPSAMkkf%252Fuploads%252FWSBSabIblsNU4tBsQWaC%252F16_output.png%3Falt%3Dmedia%26token%3Df5ab8562-7bf3-4d7a-ba70-4eeb30e0bc79&width=768&dpr=4&quality=100&sign=7cc37441&sv=1)
You can see that the records that have matched the rule, the records with ‘False’ salary flag, have been validated. On the other hand, the records that failed to match the rule, the records with the ‘True’ flag, have returned an error, denoted by a red warning sign.
If you move the cursor over this warning sign, it will show the error message in the tooltip. This is especially useful in cases where you have applied more than one rule and you want to track which records have failed to match which rule or when you want to store the erroneous records in an error log.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2F3083465318-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsR50Wa7EwZGlmPSAMkkf%252Fuploads%252FIdaiXLMGBrBr4aRH1zrL%252F18_message.png%3Falt%3Dmedia%26token%3Dc0de4d7c-4c6a-4279-abfc-7125b031fc9e&width=768&dpr=4&quality=100&sign=27bdae40&sv=1)
So now that we have validated the records against our data quality rule, we can map it to a target which is a Delimited File Destination in this case. We will name this file ‘Employees eligible for overtime,’ so the records of employees with the ‘False’ salaried flag will be passing through the Data Quality Rules object and consequently be mapped to the destination file. Let’s do the mapping.
Now, if we open the Properties window of the destination file, you can see the option, Do Not Process Records With Errors on the last window. It is checked by default in all target formats in Astera. Therefore, when we run this dataflow, all records that have matched the data quality rule will be written to the destination file, whereas records that failed to match the rule and returned an error will be omitted.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2F3083465318-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsR50Wa7EwZGlmPSAMkkf%252Fuploads%252F6Goo62q94eo5DLS9vGxX%252F20_general.png%3Falt%3Dmedia%26token%3D18e74bc7-27e7-4a64-b42b-f5b4175014dd&width=768&dpr=4&quality=100&sign=149f8522&sv=1)
The records that fail to match the data quality rule can be written and stored in a separate error log. Click here to learn how you can store erroneous records using a Record Level Log object.
Last updated