Skip to content

Commit 44381eb

Browse files
committed
feat: enhance table level to accept rule_conditions
1 parent 2764ec9 commit 44381eb

3 files changed

Lines changed: 70 additions & 16 deletions

File tree

pyatlan/generator/templates/methods/asset/data_quality_rule.jinja2

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,64 @@
6363
client: AtlanClient,
6464
rule_type: DataQualityRuleTemplateType,
6565
asset: Asset,
66-
threshold_compare_operator: DataQualityRuleThresholdCompareOperator,
6766
threshold_value: int,
6867
alert_priority: DataQualityRuleAlertPriority,
68+
threshold_compare_operator: Optional[
69+
DataQualityRuleThresholdCompareOperator
70+
] = None,
6971
threshold_unit: Optional[DataQualityRuleThresholdUnit] = None,
72+
rule_conditions: Optional[str] = None,
73+
row_scope_filtering_enabled: Optional[bool] = False,
7074
) -> DataQualityRule:
7175
validate_required_fields(
7276
[
7377
"client",
7478
"rule_type",
7579
"asset",
76-
"threshold_compare_operator",
7780
"threshold_value",
7881
"alert_priority",
7982
],
8083
[
8184
client,
8285
rule_type,
8386
asset,
84-
threshold_compare_operator,
8587
threshold_value,
8688
alert_priority,
8789
],
8890
)
91+
template_config = client.dq_template_config_cache.get_template_config(
92+
rule_type.value
93+
)
94+
95+
asset_for_validation, target_table_asset = (
96+
DataQualityRule.Attributes._fetch_assets_for_row_scope_validation(
97+
client, asset, rule_conditions, row_scope_filtering_enabled or False
98+
)
99+
)
100+
101+
validated_threshold_operator = (
102+
DataQualityRule.Attributes._validate_template_features(
103+
rule_type,
104+
rule_conditions,
105+
row_scope_filtering_enabled,
106+
template_config,
107+
threshold_compare_operator,
108+
asset_for_validation,
109+
target_table_asset,
110+
)
111+
)
112+
113+
final_threshold_compare_operator = (
114+
validated_threshold_operator
115+
or threshold_compare_operator
116+
or DataQualityRuleThresholdCompareOperator.LESS_THAN_EQUAL
117+
)
89118

90119
attributes = DataQualityRule.Attributes.creator(
91120
client=client,
92121
rule_type=rule_type,
93122
asset=asset,
94-
threshold_compare_operator=threshold_compare_operator,
123+
threshold_compare_operator=final_threshold_compare_operator,
95124
threshold_value=threshold_value,
96125
alert_priority=alert_priority,
97126
rule_name=None,
@@ -100,6 +129,8 @@
100129
dimension=None,
101130
custom_sql=None,
102131
description=None,
132+
rule_conditions=rule_conditions,
133+
row_scope_filtering_enabled=row_scope_filtering_enabled,
103134
)
104135
return cls(attributes=attributes)
105136

pyatlan/model/assets/core/data_quality_rule.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,35 +111,64 @@ def table_level_rule_creator(
111111
client: AtlanClient,
112112
rule_type: DataQualityRuleTemplateType,
113113
asset: Asset,
114-
threshold_compare_operator: DataQualityRuleThresholdCompareOperator,
115114
threshold_value: int,
116115
alert_priority: DataQualityRuleAlertPriority,
116+
threshold_compare_operator: Optional[
117+
DataQualityRuleThresholdCompareOperator
118+
] = None,
117119
threshold_unit: Optional[DataQualityRuleThresholdUnit] = None,
120+
rule_conditions: Optional[str] = None,
121+
row_scope_filtering_enabled: Optional[bool] = False,
118122
) -> DataQualityRule:
119123
validate_required_fields(
120124
[
121125
"client",
122126
"rule_type",
123127
"asset",
124-
"threshold_compare_operator",
125128
"threshold_value",
126129
"alert_priority",
127130
],
128131
[
129132
client,
130133
rule_type,
131134
asset,
132-
threshold_compare_operator,
133135
threshold_value,
134136
alert_priority,
135137
],
136138
)
139+
template_config = client.dq_template_config_cache.get_template_config(
140+
rule_type.value
141+
)
142+
143+
asset_for_validation, target_table_asset = (
144+
DataQualityRule.Attributes._fetch_assets_for_row_scope_validation(
145+
client, asset, rule_conditions, row_scope_filtering_enabled or False
146+
)
147+
)
148+
149+
validated_threshold_operator = (
150+
DataQualityRule.Attributes._validate_template_features(
151+
rule_type,
152+
rule_conditions,
153+
row_scope_filtering_enabled,
154+
template_config,
155+
threshold_compare_operator,
156+
asset_for_validation,
157+
target_table_asset,
158+
)
159+
)
160+
161+
final_threshold_compare_operator = (
162+
validated_threshold_operator
163+
or threshold_compare_operator
164+
or DataQualityRuleThresholdCompareOperator.LESS_THAN_EQUAL
165+
)
137166

138167
attributes = DataQualityRule.Attributes.creator(
139168
client=client,
140169
rule_type=rule_type,
141170
asset=asset,
142-
threshold_compare_operator=threshold_compare_operator,
171+
threshold_compare_operator=final_threshold_compare_operator,
143172
threshold_value=threshold_value,
144173
alert_priority=alert_priority,
145174
rule_name=None,
@@ -148,6 +177,8 @@ def table_level_rule_creator(
148177
dimension=None,
149178
custom_sql=None,
150179
description=None,
180+
rule_conditions=rule_conditions,
181+
row_scope_filtering_enabled=row_scope_filtering_enabled,
151182
)
152183
return cls(attributes=attributes)
153184

tests/unit/model/data_quality_rule_test.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,6 @@ def test_custom_sql_creator_with_missing_parameters_raise_value_error(
180180
DataQualityRuleAlertPriority.NORMAL,
181181
"asset is required",
182182
),
183-
(
184-
DataQualityRuleTemplateType.ROW_COUNT,
185-
Table.ref_by_qualified_name(qualified_name=DQ_TABLE_QUALIFIED_NAME),
186-
None,
187-
DQ_RULE_THRESHOLD_VALUE,
188-
DataQualityRuleAlertPriority.NORMAL,
189-
"threshold_compare_operator is required",
190-
),
191183
(
192184
DataQualityRuleTemplateType.ROW_COUNT,
193185
Table.ref_by_qualified_name(qualified_name=DQ_TABLE_QUALIFIED_NAME),

0 commit comments

Comments
 (0)