Data validator
DataValidator
dataclass
A class to validate data based on a set of validation rules.
Attributes:
Name | Type | Description |
---|---|---|
rules |
list[ValidationRule]
|
A list of validation rules. |
Examples:
ValidationRules = [
ValidationRule("first_name_check", F_.printable_only("first_name")),
ValidationRule("last_name_check", F_.printable_only("last_name")),
ValidationRule("address_check", F_.printable_only("address")),
ValidationRule("region_check", F_.printable_only("region")),
ValidationRule("code_check", [F_.two_character_only("code")]),
ValidationRule("postcode_check", F_.printable_only("postcode")),
]
validator = DataValidator(ValidationRules)
conditions = {
"first_name_check": F_.printable_only("first_name"),
"last_name_check": F_.printable_only("last_name"),
"address_check": F_.printable_only("address"),
"region_check": F_.printable_only("region"),
"code_check": [F_.two_character_only("code")],
"postcode_check": F_.printable_only("postcode"),
}
validator = DataValidator.from_dict(conditions)
Source code in pysparky/data_validator.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
query_map
property
apply_conditions(sdf)
Applies the combined conditions to the Spark DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sdf
|
DataFrame
|
The Spark DataFrame to which the conditions will be applied. |
required |
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
The Spark DataFrame with the conditions applied. |
Examples:
Source code in pysparky/data_validator.py
filter_invalid(sdf)
Filters out invalid rows from the Spark DataFrame based on the rules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sdf
|
DataFrame
|
The Spark DataFrame to be filtered. |
required |
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
The Spark DataFrame with invalid rows filtered out. |
Examples:
Source code in pysparky/data_validator.py
filter_valid(sdf)
Filters out valid rows from the Spark DataFrame based on the rules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sdf
|
DataFrame
|
The Spark DataFrame to be filtered. |
required |
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
The Spark DataFrame with valid rows filtered out. |
Examples:
Source code in pysparky/data_validator.py
from_dict(data)
classmethod
Creates a DataValidator instance from a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict[str, list[Column] | Column]
|
A dictionary where keys are rule names and values are lists of conditions or a single condition. |
required |
Returns:
Name | Type | Description |
---|---|---|
DataValidator |
DataValidator
|
An instance of DataValidator. |
Examples:
conditions = {
"first_name_check": F_.printable_only("first_name"),
"last_name_check": F_.printable_only("last_name"),
"address_check": F_.printable_only("address"),
"region_check": F_.printable_only("region"),
"code_check": [F_.two_character_only("code")],
"postcode_check": F_.printable_only("postcode"),
}
validator = DataValidator.from_dict(conditions)
Source code in pysparky/data_validator.py
ValidationRule
dataclass
A class to represent a validation rule.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the validation rule. |
conditions |
list[Column]
|
A list of conditions (Spark Columns) that make up the rule. |
combined_condition |
Column
|
The combined condition of all the conditions using logical AND. It will generate from conditions |
Examples:
ValidationRule("first_name_check", F_.printable_only("first_name")),