Skip to content

Commit 44fce93

Browse files
committed
feat: add row scope filter column check for incremental rules
1 parent c527116 commit 44fce93

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

pyatlan/errors.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,13 @@ class ErrorCode(Enum):
661661
"Ensure your rule conditions are valid and match the expected format.",
662662
InvalidRequestError,
663663
)
664+
DQ_ROW_SCOPE_FILTER_COLUMN_MISSING = (
665+
400,
666+
"ATLAN-PYTHON-400-075",
667+
"Row scope filter column not configured for asset '{0}'.",
668+
"please configure the row scope filter column first.",
669+
InvalidRequestError,
670+
)
664671
AUTHENTICATION_PASSTHROUGH = (
665672
401,
666673
"ATLAN-PYTHON-401-000",

pyatlan/model/assets/core/alpha__d_q_rule.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
if TYPE_CHECKING:
4343
from pyatlan.client.atlan import AtlanClient
44-
from pyatlan.model.assets import Column
44+
from pyatlan.model.assets import Asset, Column
4545

4646

4747
class alpha_DQRule(DataQuality):
@@ -185,13 +185,30 @@ def column_level_rule_creator(
185185
],
186186
)
187187
template_config = client.dq_template_config_cache.get_template_config(rule_type)
188+
189+
asset_for_validation = asset
190+
if row_scope_filtering_enabled and asset.qualified_name:
191+
from pyatlan.model.fluent_search import FluentSearch
192+
193+
search_request = (
194+
FluentSearch()
195+
.where(Asset.QUALIFIED_NAME.eq(asset.qualified_name))
196+
.include_on_results(
197+
Asset.ALPHAASSET_DQ_ROW_SCOPE_FILTER_COLUMN_QUALIFIED_NAME
198+
)
199+
).to_request()
200+
results = client.asset.search(search_request)
201+
if results.count == 1:
202+
asset_for_validation = results.current_page()[0]
203+
188204
threshold_compare_operator = (
189205
alpha_DQRule.Attributes._validate_template_features(
190206
rule_type,
191207
rule_conditions,
192208
row_scope_filtering_enabled,
193209
template_config,
194210
threshold_compare_operator,
211+
asset_for_validation,
195212
)
196213
)
197214

@@ -311,6 +328,7 @@ def updater(
311328
row_scope_filtering_enabled,
312329
template_config,
313330
threshold_compare_operator or retrieved_threshold_compare_operator,
331+
retrieved_asset,
314332
)
315333
)
316334

@@ -1093,6 +1111,7 @@ def _validate_template_features(
10931111
threshold_compare_operator: Optional[
10941112
alpha_DQRuleThresholdCompareOperator
10951113
] = None,
1114+
asset: Optional[Asset] = None,
10961115
) -> alpha_DQRuleThresholdCompareOperator:
10971116
if not template_config or not template_config.get("config"):
10981117
return
@@ -1116,6 +1135,15 @@ def _validate_template_features(
11161135
rule_type, "row scope filtering"
11171136
)
11181137

1138+
if asset and not getattr(
1139+
asset,
1140+
"alpha_asset_d_q_row_scope_filter_column_qualified_name",
1141+
None,
1142+
):
1143+
raise ErrorCode.DQ_ROW_SCOPE_FILTER_COLUMN_MISSING.exception_with_parameters(
1144+
getattr(asset, "qualified_name", "unknown")
1145+
)
1146+
11191147
if rule_conditions:
11201148
allowed_rule_conditions = (
11211149
alpha_DQRule.Attributes._get_template_config_value(

pyatlan/model/assets/core/asset.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,15 @@ def __setattr__(self, name, value):
11431143
"""
11441144
Internal Popularity score for this asset.
11451145
"""
1146+
ALPHAASSET_DQ_ROW_SCOPE_FILTER_COLUMN_QUALIFIED_NAME: ClassVar[KeywordField] = (
1147+
KeywordField(
1148+
"alpha_assetDQRowScopeFilterColumnQualifiedName",
1149+
"alpha_assetDQRowScopeFilterColumnQualifiedName",
1150+
)
1151+
)
1152+
"""
1153+
Qualified name of the column to be used for row scope filter
1154+
"""
11461155
ALPHAASSET_DQ_SCHEDULE_TYPE: ClassVar[KeywordField] = KeywordField(
11471156
"alpha_assetDQScheduleType", "alpha_assetDQScheduleType"
11481157
)
@@ -1510,6 +1519,7 @@ def __setattr__(self, name, value):
15101519
"application_field_qualified_name",
15111520
"asset_user_defined_type",
15121521
"asset_internal_popularity_score",
1522+
"alpha_asset_d_q_row_scope_filter_column_qualified_name",
15131523
"alpha_asset_d_q_schedule_type",
15141524
"alpha_asset_d_q_schedule_crontab",
15151525
"alpha_asset_d_q_schedule_time_zone",
@@ -3561,6 +3571,24 @@ def asset_internal_popularity_score(
35613571
asset_internal_popularity_score
35623572
)
35633573

3574+
@property
3575+
def alpha_asset_d_q_row_scope_filter_column_qualified_name(self) -> Optional[str]:
3576+
return (
3577+
None
3578+
if self.attributes is None
3579+
else self.attributes.alpha_asset_d_q_row_scope_filter_column_qualified_name
3580+
)
3581+
3582+
@alpha_asset_d_q_row_scope_filter_column_qualified_name.setter
3583+
def alpha_asset_d_q_row_scope_filter_column_qualified_name(
3584+
self, alpha_asset_d_q_row_scope_filter_column_qualified_name: Optional[str]
3585+
):
3586+
if self.attributes is None:
3587+
self.attributes = self.Attributes()
3588+
self.attributes.alpha_asset_d_q_row_scope_filter_column_qualified_name = (
3589+
alpha_asset_d_q_row_scope_filter_column_qualified_name
3590+
)
3591+
35643592
@property
35653593
def alpha_asset_d_q_schedule_type(self) -> Optional[alpha_DQScheduleType]:
35663594
return (
@@ -4451,6 +4479,9 @@ class Attributes(Referenceable.Attributes):
44514479
asset_internal_popularity_score: Optional[float] = Field(
44524480
default=None, description=""
44534481
)
4482+
alpha_asset_d_q_row_scope_filter_column_qualified_name: Optional[str] = Field(
4483+
default=None, description=""
4484+
)
44544485
alpha_asset_d_q_schedule_type: Optional[alpha_DQScheduleType] = Field(
44554486
default=None, description=""
44564487
)

0 commit comments

Comments
 (0)