Constraints API Reference
qualink.constraints — All built-in constraint classes and the Assertion predicate.
from qualink.constraints import Assertion, CompletenessConstraint, UniquenessConstraint
All constraints extend Constraint (ABC) and implement:
async evaluate(ctx, table_name) → ConstraintResultname() → strmetadata() → ConstraintMetadata(optional)
qualink.constraints.approx_count_distinct
class ApproxCountDistinctConstraint(Constraint)
Validates that the approximate distinct count of *column* satisfies *assertion*.
| Param | Type | Default |
|---|---|---|
column |
str |
— |
assertion |
Assertion |
— |
hint |
str |
"" |
qualink.constraints.approx_quantile
class ApproxQuantileConstraint(Constraint)
Validates that an approximate quantile of *column* satisfies *assertion*.
| Param | Type | Default |
|---|---|---|
column |
str |
— |
quantile |
float |
— |
assertion |
Assertion |
— |
hint |
str |
"" |
qualink.constraints.assertion
class Assertion
Reusable predicate that tests a numeric metric value.
| Field | Type | Default |
|---|---|---|
_op |
_Op |
required |
_value |
float |
0.0 |
_upper |
float |
0.0 |
_fn |
`Callable[[float], bool] | None` |
_label |
str |
"" |
qualink.constraints.column_count
class ColumnCountConstraint(Constraint)
Validates that the number of columns in the table satisfies *assertion*.
| Param | Type | Default |
|---|---|---|
assertion |
Assertion |
— |
qualink.constraints.column_exists
class ColumnExistsConstraint(Constraint)
Validates that *column* exists in the table schema.
| Param | Type | Default |
|---|---|---|
column |
str |
— |
hint |
str |
"" |
qualink.constraints.completeness
class CompletenessConstraint(Constraint)
Validates that the completeness fraction of *column* satisfies *assertion*.
| Param | Type | Default |
|---|---|---|
column |
str |
— |
assertion |
Assertion |
— |
qualink.constraints.compliance
class ComplianceConstraint(Constraint)
Validates that the fraction of rows where *predicate* is true satisfies *assertion*.
| Param | Type | Default |
|---|---|---|
name_label |
str |
— |
predicate |
str |
— |
assertion |
Assertion |
— |
hint |
str |
"" |
qualink.constraints.correlation
class CorrelationConstraint(Constraint)
Validates that the Pearson correlation of *column_a* and *column_b* satisfies *assertion*.
| Param | Type | Default |
|---|---|---|
column_a |
str |
— |
column_b |
str |
— |
assertion |
Assertion |
— |
hint |
str |
"" |
qualink.constraints.custom_sql
class CustomSqlConstraint(Constraint)
Validates that *sql_expression* holds true for all rows.
The expression is evaluated as a WHERE-clause predicate; the constraint passes when the ratio of matching rows equals 1.0.
| Param | Type | Default |
|---|---|---|
sql_expression |
str |
— |
hint |
str |
"" |
qualink.constraints.distinctness
class DistinctnessConstraint(Constraint)
Validates that the distinctness ratio of *columns* satisfies *assertion*.
Distinctness = COUNT(DISTINCT cols) / COUNT(*)
| Param | Type | Default |
|---|---|---|
columns |
list[str] |
— |
assertion |
Assertion |
— |
hint |
str |
"" |
qualink.constraints.format
class FormatType(Enum)
Pre-defined format categories or a free-form regex.
| Member | Value |
|---|---|
FormatType.REGEX |
'regex' |
FormatType.EMAIL |
'email' |
FormatType.URL |
'url' |
FormatType.PHONE |
'phone' |
FormatType.CREDIT_CARD |
'credit_card' |
FormatType.SSN |
'ssn' |
FormatType.IPV4 |
'ipv4' |
class FormatConstraint(Constraint)
Validates that at least *threshold* fraction of *column* values match a pattern.
| Param | Type | Default |
|---|---|---|
column |
str |
— |
format_type |
FormatType |
— |
pattern |
`str | None` |
threshold |
float |
1.0 |
qualink.constraints.max_length
class MaxLengthConstraint(Constraint)
Validates that the maximum string length of *column* satisfies *assertion*.
| Param | Type | Default |
|---|---|---|
column |
str |
— |
assertion |
Assertion |
— |
hint |
str |
"" |
qualink.constraints.min_length
class MinLengthConstraint(Constraint)
Validates that the minimum string length of *column* satisfies *assertion*.
| Param | Type | Default |
|---|---|---|
column |
str |
— |
assertion |
Assertion |
— |
hint |
str |
"" |
qualink.constraints.pattern_match
class PatternMatchConstraint(Constraint)
Validates that the fraction of *column* values matching *pattern* satisfies *assertion*.
| Param | Type | Default |
|---|---|---|
column |
str |
— |
pattern |
str |
— |
assertion |
Assertion |
— |
hint |
str |
"" |
qualink.constraints.referential_integrity
class ReferentialIntegrityConstraint(Constraint)
Validates referential integrity between two tables via ReferentialIntegrity.
| Param | Type | Default |
|---|---|---|
child_table |
str |
— |
child_column |
str |
— |
parent_table |
str |
— |
parent_column |
str |
— |
assertion |
Assertion |
— |
hint |
str |
"" |
qualink.constraints.row_count_match
class RowCountMatchConstraint(Constraint)
Validates row count match between two tables via RowCountMatch.
| Param | Type | Default |
|---|---|---|
table_a |
str |
— |
table_b |
str |
— |
assertion |
Assertion |
— |
hint |
str |
"" |
qualink.constraints.schema_match
class SchemaMatchConstraint(Constraint)
Validates schema match between two tables via SchemaMatch.
| Param | Type | Default |
|---|---|---|
table_a |
str |
— |
table_b |
str |
— |
assertion |
Assertion |
— |
hint |
str |
"" |
qualink.constraints.size
class SizeConstraint(Constraint)
Validates that the row count of the table satisfies *assertion*.
| Param | Type | Default |
|---|---|---|
assertion |
Assertion |
— |
qualink.constraints.statistics
class StatisticType(Enum)
The aggregate function to compute before applying an assertion.
Uses DataFusion built-in aggregate functions directly: https://datafusion.apache.org/user-guide/sql/aggregate_functions.html
| Member | Value |
|---|---|
StatisticType.MIN |
'MIN' |
StatisticType.MAX |
'MAX' |
StatisticType.MEAN |
'AVG' |
StatisticType.SUM |
'SUM' |
StatisticType.STDDEV |
'STDDEV' |
StatisticType.MEDIAN |
'MEDIAN' |
Properties:
sql_fn: str
class StatisticalConstraint(Constraint)
Computes a SQL aggregate on *column* and asserts against *assertion*.
| Param | Type | Default |
|---|---|---|
column |
str |
— |
stat_type |
StatisticType |
— |
assertion |
Assertion |
— |
qualink.constraints.unique_value_ratio
class UniqueValueRatioConstraint(Constraint)
Validates that the unique-value ratio of *columns* satisfies *assertion*.
UniqueValueRatio = (values appearing exactly once) / COUNT(DISTINCT values)
| Param | Type | Default |
|---|---|---|
columns |
list[str] |
— |
assertion |
Assertion |
— |
hint |
str |
"" |
qualink.constraints.uniqueness
class UniquenessConstraint(Constraint)
Validates that the uniqueness ratio of *columns* satisfies *assertion*.
| Param | Type | Default |
|---|---|---|
columns |
list[str] |
— |
assertion |
`Assertion | None` |
threshold |
`float | None` |