Skip to content

pysparky_data_quality.validation

Immutable definitions and ordered collections of row validation rules.

Attributes

NameDescription
NullPolicyNo description.

Classes

NameDescription
DataValidatorImmutable, ordered collection of uniquely named validation rules.
ValidationRuleA named boolean Column expression with an explicit SQL NULL policy.

NullPolicyattributemodule attribute#

NullPolicy = Literal['fail', 'pass']

DataValidatorclassdataclass#

class DataValidator(rules: Iterable[ValidationRule] = ())

Immutable, ordered collection of uniquely named validation rules.

The registry stores expressions only. It does not accept a DataFrame, create a SparkSession, or trigger Spark work.

rulesproperty#

rules: tuple[ValidationRule, ...]

Rules in their declared evaluation and reporting order.

annotatemethod#

def annotate(dataframe: DataFrame) -> DataFrame

Add one boolean result column per rule without running an action.

Each result column uses its rule’s name. Existing columns are preserved in order. Names that collide under case-insensitive comparison are rejected so behavior does not depend on Spark’s resolver setting.

splitmethod#

def split(dataframe: DataFrame) -> tuple[DataFrame, DataFrame]

Return lazy (valid, invalid) frames with the original schema.

A row is valid only when every normalized rule predicate is true. With no rules, the empty conjunction is true and all rows are valid. The two outputs are mutually exclusive and collectively exhaustive.

validatemethod#

def validate(dataframe: DataFrame) -> ValidationReport

Evaluate row rules in one explicit action and return a report.

Each rule result includes total and failed row counts. Empty validators return an empty report without scanning the DataFrame. Spark failures become error results; invalid Python definitions still raise.

with_rulemethod#

def with_rule(rule: ValidationRule) -> DataValidator

Return a new validator with rule appended, preserving this instance.

ValidationRuleclassdataclass#

class ValidationRule(name: str, condition: Column, null_policy: NullPolicy = 'fail')

A named boolean Column expression with an explicit SQL NULL policy.

condition must be a boolean PySpark Column. Its raw SQL result may be true, false, or NULL. Calling predicate maps a NULL result to false by default, or to true when null_policy is "pass". This constructs a lazy Column expression and performs no Spark action.

conditionattributeinstance attribute#

condition: Column

nameattributeinstance attribute#

name: str

null_policyattributeclass attributeinstance attribute#

null_policy: NullPolicy = 'fail'

predicatemethod#

def predicate() -> Column

Return a boolean Column with the configured NULL policy applied.