Create a data quality rule
This section shows how you can design and build a SQL rule on the Rule Workbench.
Prerequisites
You have:
ROLE_ADMIN, ROLE_DATASET_RULES, or ROLE_VIEW_DATA
An existing dataset against which you want to write a rule.
Steps
Select a navigation method from the following tabs.
Click the
in the sidebar menu, then click Rule Builder.
The Dataset Rules page opens.
There are two ways to open the Rule Workbench.
From an existing rule on the Rules tab, click Actions, then click Edit. The Rule Workbench page opens with the preferences of your existing rule.
Click Add Rule in the upper-right corner to create a new rule. The Rule Workbench page opens.
Select a rule type from the Type drop-down list.
User Input
User Input rules are custom SQL statements that can be either short or long form, depending on the complexity.
Simple Rule (SQLG)
Simple rules are SQL statements that use just the condition and primary column name. For example, AMOUNT > 100
Simple Rules use Spark SQL syntax.
Freeform SQL (SQLF)
Freeform rules are complete SQL statements that are commonly used when more complex SQL rules are necessary. Freeform Rules can include multiple conditions, table joins, common table expressions (CTEs), and window statements, among other operations.
Freeform Rules use Spark SQL syntax. See Supported SQL functions for Pullup rules for more information on the supported and unsupported SQL functions.
Native SQL
Native rules use SQL statements with functions or expressions that may be specific to the underlying connection or database (Database SQL). For example, a Native SQL rule written on a dataset whose data resides in Snowflake uses the SQL query syntax native to Snowflake.
Remote files are not eligible for Native SQL rules.
Data Type
Data Type rules check for nulls, empty values, or specific data types.
Empty Check
Checks whether the target column has empty values or not.
Null Check
Checks whether the target column has NULL values or not.
Date Check
Checks whether the target column has only DATE values or not.
Int Check
Checks whether the target column has only integer values or not.
Double Check
Checks whether the target column has only DOUBLE values or not.
String Check
Checks whether the target column has only STRING values or not.
Mixed Type Check
Checks the dataType of the field.
Data Class
See the Data Class page for a list of out-of-the-box Data Class rules.
Template
See the Template page for a list of out-of-the-box Template rules.
Enter a name for your rule in the Rule Name input field.
Select a primary column from the Primary Col drop-down.
Optionally, click
to add a secondary dataset.
Enter the name of your secondary dataset in the search bar when the Add Secondary Dataset dialog appears, then click Add Secondary Dataset.
If you use snowflake_key_pair authentication for the secondary dataset, then add this to the Spark configuration file in the command line after the -conf parameter:spark.kubernetes.driverEnv.OWL_SCRATCH_DIR=/tmp/scratch,spark.kubernetes.executorEnv.OWL_SCRATCH_DIR=/tmp/scratch
Write your SQL query. When you select the Freeform rule type, as shown in the GIF below, the Workbench pre-populates the beginning of the query for you. For example, SELECT * FROM @<dataset name>. As you type, the Workbench provides a suggested options with common SQL operators and column names relative to your primary and secondary datasets.

Optionally, add a filter query in the Filter input field.
Click
Validate to validate your expression.
Optionally, click
to format your SQL query in a more readable layout.
Click Save to apply your rule to your dataset.
On the upper-right corner of the Findings page, click the Rules link in the metadata box.
The Dataset Rules page opens.
There are two ways to open the Rule Workbench.
From an existing rule on the Rules tab, click Actions, then click Edit. The Rule Workbench page opens with the preferences of your existing rule.
Click Add Rule in the upper-right corner to create a new rule. The Rule Workbench page opens.
Select a rule type from the Type drop-down list.
User Input
User Input rules are custom SQL statements that can be either short or long form, depending on the complexity.
Simple Rule (SQLG)
Simple rules are SQL statements that use just the condition and primary column name. For example, AMOUNT > 100
Simple Rules use Spark SQL syntax.
Freeform SQL (SQLF)
Freeform rules are complete SQL statements that are commonly used when more complex SQL rules are necessary. Freeform Rules can include multiple conditions, table joins, common table expressions (CTEs), and window statements, among other operations.
Freeform Rules use Spark SQL syntax. See Supported SQL functions for Pullup rules for more information on the supported and unsupported SQL functions.
Native SQL
Native rules use SQL statements with functions or expressions that may be specific to the underlying connection or database (Database SQL). For example, a Native SQL rule written on a dataset whose data resides in Snowflake uses the SQL query syntax native to Snowflake.
Remote files are not eligible for Native SQL rules.
Data Type
Data Type rules check for nulls, empty values, or specific data types.
Empty Check
Checks whether the target column has empty values or not.
Null Check
Checks whether the target column has NULL values or not.
Date Check
Checks whether the target column has only DATE values or not.
Int Check
Checks whether the target column has only integer values or not.
Double Check
Checks whether the target column has only DOUBLE values or not.
String Check
Checks whether the target column has only STRING values or not.
Mixed Type Check
Checks the dataType of the field.
Data Class
See the Data Class page for a list of out-of-the-box Data Class rules.
Template
See the Template page for a list of out-of-the-box Template rules.
Enter a name for your rule in the Rule Name input field.
Select a primary column from the Primary Col drop-down list.
Optionally, click
to add a secondary dataset.
Enter the name of your secondary dataset in the search bar when the Add Secondary Dataset dialog appears, then click Add Secondary Dataset.
Write your SQL query. When you select the Freeform rule type, as shown in the GIF below, the Workbench pre-populates the beginning of the query for you. For example, SELECT * FROM @<dataset name>. As you type, the Workbench provides a suggested options with common SQL operators and column names relative to your primary and secondary datasets.
Optionally, add a filter query in the Filter input field.
Click
Validate to validate your expression.
Optionally, click
to format your SQL query in a more readable layout.
Click Save to apply your rule to your dataset.
Configuring Rule Details
To configure rule details, click the in the upper-right corner of the Workbench to open the Rule Details modal.
The following table shows the settings when you set up a rule in the Rule Workbench.
DQ Dimension
Associate your rule with a DQ Dimension, as shown in the following table. This can be especially useful when you use the Collibra Platform integration and custom reporting. This is required if the MANDATORY_RULE_DIMENSION is set to TRUE.
Completeness: Completeness refers to the degree to which potential data contained in a dataset is reflected. Refers to the percentage of columns that have neither EMPTY nor NULL values.
Timeliness: Timeliness refers to the degree to which data is relevant and up-to-date at a certain point in time.
Uniqueness: Uniqueness refers to the degree to which data contains only one record of how an entity is identified. Refers to the cardinality of columns in your dataset.
Validity: Validity refers to the degree to which data conforms to its defining constraints or conditions, which can include data type, range, or format.
Consistency: Consistency refers to the degree to which data contains differing, contradicting, or conflicting entries.
Accuracy: Accuracy refers to the degree to which data correctly reflects its intended values.
Category
You can create and apply custom categories to your rule to group similar rules together. For example, you can create categories for "Rules for missing data" or "Rules to identify format issues".
Description
Provide a detailed description of your rule.
Purpose
Provide details about Collibra Platform assets associated with your rule in Data Quality & Observability (self-hosted). This allows you to see which assets should relate to your Data Quality Rule asset upon integration.
Preview Limit (Rows)
The maximum number of available rows to preview when you drill into a rule break record on the Findings page.
Set a value between 0-500 records. The default value is 6 records.
Run Time Limit (Minutes)
The maximum number of minutes any rule associated with a dataset can take to process before it times out and proceeds to the next activity in the job. If you increase this value to one greater than the previous maximum Run Time Limit of any rule associated with your dataset, it becomes the new maximum timeout limit.
Score
Provides three options, or presets, for calculating the rules score: Low, Medium, and High. Select an option to automatically populate the Points field and Percentage field (if applicable) with predefined values.
For more information, go to Understanding the rules score.
Scoring Type
Determines the methodology used to calculate the rules score: Percent or Absolute.
For more information, go to Understanding the rules score.
Points
A value between 0-100, representing the number of points deducted from the total quality score when a record violates your rule.
For more information, go to Understanding the rules score.
Percent
When you use the Percent scoring type, this can be a value between 0-100. This represents the ratio of the total number of breaking records over the total number of rows.
For more information, go to Understanding the rules score.
Tolerance
Specifies the tolerance threshold as a percentage.
For more information, go to Understanding the rules score.
Rule Status
The Active option is selected by default, indicating the rule is active. To deactivate the rule, uncheck this option.
Managing a Livy Session
You can preview the columns in your dataset to help you create SQL queries for rules on Pullup jobs. To do this, ensure that you allocate ample resources for Livy to run efficiently. Livy starts when you click Run Result Preview and has 1 core, 1 GB of memory, and 1 worker by default.
For large datasets that require increased processing resources, you may need to modify your Livy session to improve the loading time of your Result Preview. When you use Result Preview, there is a 500-row limit on the preview, regardless of the number of rows are in the results of your query.
Click Manage Session. The Manage Livy Session modal appears.
Enter the required information.
Cores
The number of executor cores for Spark processing. The minimum value is 1.
Memory
The amount of memory allocated for Spark processing. Allocate at least 1 GB of memory per Livy pod.
Workers
The number of executors available in your Livy session. The minimum value is 1.
When you increase the number of workers, an additional Livy session is created for each additional worker you specify. For example, if you increase your workers from 1 to 3, then 2 additional Livy sessions are created for a total of 3.
Choose whether to acknowledge that all cached preview data will be lost when you update your Livy session.
Click Update.
Working with COUNT and GROUP BY
Be careful when using COUNT and GROUP BY in Freeform SQL and Native SQL rules, because they may create unexpected or unintended results. For best results, keep in mind the following points:
COUNT. Returns the number of rows that meet the specified criteria. If used on its own, without additional operators and functions, COUNT will create a breaking rule by default.
GROUP BY. Does not function when used on its own. GROUP BY must be used as part of a group or aggregate function (SUM, COUNT, etc.).
A rule passes when it does not find any rows that meet a specified criteria, and it breaks when it finds rows that need a customer's attention. To create rules with this behavior, include WHERE and/or HAVING in the query. For example, you can use HAVING with both COUNT with GROUP BY to create the following query:
Supported SQL functions for Pullup rules
The following list shows the supported and unsupported functions for pattern matching in Pullup rules. Use only the supported functions when creating Freeform rules, and validate the syntax afterward.
Supported functions
LIKE
RLIKE
REGEXP
REGEXP_LIKE
Unsupported functions
Other variations of REGEXP, such as REGEXP_COUNTor REGEXP_REPLACE
QUALIFY
DATEADD
TRANSLATE
ROUND
FLOOR
Known limitations
An error can occur when you write a rule using REGEXP. To resolve this issue, use RLIKE instead.
The Result Preview does not show columns with alias names.
A Spark SQL parsing error occurs if your rule name includes consecutive hyphens (--), starts with a hyphen (-rule), or ends with a hyphen (rule-).
Avoid creating complex multi-rule conditions (AND/OR) with rules that require explicit backtick escaping.
Last updated
Was this helpful?