join_validator
join_validator ¶
Validate data-model relationship JOIN keys by sampling real data.
For each relationship in a DataModelTemplate, queries the underlying
source datasets for the join-key columns and checks:
- Overlap — do the sampled values from the left key appear in the right key (and vice versa)? Low overlap signals a wrong column choice.
- Distinctness — are the values unique on the assumed "one" side? Duplicates on the dimension side signal a wrong cardinality direction.
- Cardinality hint — compares duplicate ratios to suggest which side is the dimension (one) and which is the fact (many).
Usage::
results = await model.Model.validate_relationships(context=ctx)
for r in results:
if not r.is_valid:
print(f" WARNING: {r.relationship.left} -> {r.relationship.right}: {r.warnings}")
JoinValidationResult
dataclass
¶
JoinValidationResult(
relationship: DataModelRelationship,
left_object: str = "",
right_object: str = "",
left_column: str = "",
right_column: str = "",
left_sample_size: int = 0,
right_sample_size: int = 0,
left_distinct_count: int = 0,
right_distinct_count: int = 0,
overlap_count: int = 0,
overlap_ratio: float = 0.0,
left_duplicate_ratio: float = 0.0,
right_duplicate_ratio: float = 0.0,
suggested_one_side: str | None = None,
is_valid: bool = True,
warnings: list[str] = list(),
)
Result of validating a single relationship's join keys.
Attributes:
| Name | Type | Description |
|---|---|---|
relationship |
DataModelRelationship
|
The relationship that was validated. |
left_object |
str
|
Name of the left object. |
right_object |
str
|
Name of the right object. |
left_column |
str
|
Join key column on the left side. |
right_column |
str
|
Join key column on the right side. |
left_sample_size |
int
|
Number of values sampled from the left side. |
right_sample_size |
int
|
Number of values sampled from the right side. |
left_distinct_count |
int
|
Number of distinct values in the left sample. |
right_distinct_count |
int
|
Number of distinct values in the right sample. |
overlap_count |
int
|
Number of distinct values that appear on both sides. |
overlap_ratio |
float
|
overlap_count / min(left_distinct, right_distinct). |
left_duplicate_ratio |
float
|
Fraction of left sample that are duplicates. |
right_duplicate_ratio |
float
|
Fraction of right sample that are duplicates. |
suggested_one_side |
str | None
|
"left" or "right" — which side looks like the dimension (one) side based on distinctness. |
is_valid |
bool
|
True if the join appears correct (good overlap, no cardinality red flags). |
warnings |
list[str]
|
Human-readable warning messages. |
validate_relationships
async
¶
validate_relationships(
auth: DomoAuth,
template: DataModelTemplate,
*,
sample_size: int = 100,
context: RouteContext | None = None,
**context_kwargs
) -> list[JoinValidationResult]
Validate all relationships in a data model by sampling real data.
For each relationship, samples sample_size values from each join-key
column on both sides, then checks overlap and distinctness.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auth
|
DomoAuth
|
DomoAuth instance for the Domo instance. |
required |
template
|
DataModelTemplate
|
The data model template to validate. |
required |
sample_size
|
int
|
Number of rows to sample per join key (default 100). |
100
|
context
|
RouteContext | None
|
Optional RouteContext. |
None
|
**context_kwargs
|
Additional context parameters. |
{}
|
Returns:
| Type | Description |
|---|---|
list[JoinValidationResult]
|
List of JoinValidationResult, one per relationship. |
Source code in src/crew_dcs/classes/DomoDataset/join_validator.py
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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |