|
113 | 113 | alert_priority: alpha_DQRuleAlertPriority, |
114 | 114 | threshold_compare_operator: Optional[ |
115 | 115 | alpha_DQRuleThresholdCompareOperator |
116 | | - ] = alpha_DQRuleThresholdCompareOperator.LESS_THAN_EQUAL, |
| 116 | + ] = None, |
117 | 117 | threshold_unit: Optional[alpha_DQRuleThresholdUnit] = None, |
| 118 | + rule_conditions: Optional[str] = None, |
| 119 | + row_scope_filtering_enabled: Optional[bool] = False, |
118 | 120 | ) -> alpha_DQRule: |
119 | 121 | validate_required_fields( |
120 | 122 | [ |
121 | 123 | "client", |
122 | 124 | "rule_type", |
123 | 125 | "asset", |
124 | 126 | "column", |
125 | | - "threshold_compare_operator", |
126 | 127 | "threshold_value", |
127 | 128 | "alert_priority", |
128 | 129 | ], |
|
131 | 132 | rule_type, |
132 | 133 | asset, |
133 | 134 | column, |
134 | | - threshold_compare_operator, |
135 | 135 | threshold_value, |
136 | 136 | alert_priority, |
137 | 137 | ], |
138 | 138 | ) |
| 139 | + template_config = client.dq_template_config_cache.get_template_config(rule_type) |
| 140 | + |
| 141 | + asset_for_validation = asset |
| 142 | + if row_scope_filtering_enabled and asset.qualified_name: |
| 143 | + from pyatlan.model.fluent_search import FluentSearch |
| 144 | + |
| 145 | + search_request = ( |
| 146 | + FluentSearch() |
| 147 | + .where(Asset.QUALIFIED_NAME.eq(asset.qualified_name)) |
| 148 | + .include_on_results( |
| 149 | + Asset.ALPHAASSET_DQ_ROW_SCOPE_FILTER_COLUMN_QUALIFIED_NAME |
| 150 | + ) |
| 151 | + ).to_request() |
| 152 | + results = client.asset.search(search_request) |
| 153 | + if results.count == 1: |
| 154 | + asset_for_validation = results.current_page()[0] |
| 155 | + |
| 156 | + validated_threshold_operator = ( |
| 157 | + alpha_DQRule.Attributes._validate_template_features( |
| 158 | + rule_type, |
| 159 | + rule_conditions, |
| 160 | + row_scope_filtering_enabled, |
| 161 | + template_config, |
| 162 | + threshold_compare_operator, |
| 163 | + asset_for_validation, |
| 164 | + ) |
| 165 | + ) |
| 166 | + |
| 167 | + final_threshold_compare_operator = ( |
| 168 | + validated_threshold_operator |
| 169 | + or threshold_compare_operator |
| 170 | + or alpha_DQRuleThresholdCompareOperator.LESS_THAN_EQUAL |
| 171 | + ) |
139 | 172 |
|
140 | 173 | attributes = alpha_DQRule.Attributes.creator( |
141 | 174 | client=client, |
142 | 175 | rule_type=rule_type, |
143 | 176 | asset=asset, |
144 | 177 | column=column, |
145 | | - threshold_compare_operator=threshold_compare_operator, |
| 178 | + threshold_compare_operator=final_threshold_compare_operator, |
146 | 179 | threshold_value=threshold_value, |
147 | 180 | alert_priority=alert_priority, |
148 | 181 | threshold_unit=threshold_unit, |
149 | 182 | rule_name=None, |
150 | 183 | dimension=None, |
151 | 184 | custom_sql=None, |
152 | 185 | description=None, |
| 186 | + rule_conditions=rule_conditions, |
| 187 | + row_scope_filtering_enabled=row_scope_filtering_enabled, |
153 | 188 | ) |
154 | 189 | return cls(attributes=attributes) |
155 | 190 |
|
|
169 | 204 | custom_sql: Optional[str] = None, |
170 | 205 | rule_name: Optional[str] = None, |
171 | 206 | description: Optional[str] = None, |
| 207 | + rule_conditions: Optional[str] = None, |
| 208 | + row_scope_filtering_enabled: Optional[bool] = False, |
172 | 209 | ) -> SelfAsset: |
173 | 210 | from pyatlan.model.fluent_search import FluentSearch |
174 | 211 |
|
|
190 | 227 | .include_on_results(alpha_DQRule.USER_DESCRIPTION) |
191 | 228 | .include_on_results(alpha_DQRule.ALPHADQ_RULE_DIMENSION) |
192 | 229 | .include_on_results(alpha_DQRule.ALPHADQ_RULE_CONFIG_ARGUMENTS) |
| 230 | + .include_on_results(alpha_DQRule.ALPHADQ_RULE_ROW_SCOPE_FILTERING_ENABLED) |
193 | 231 | .include_on_results(alpha_DQRule.ALPHADQ_RULE_SOURCE_SYNC_STATUS) |
194 | 232 | .include_on_results(alpha_DQRule.ALPHADQ_RULE_STATUS) |
195 | 233 | ).to_request() |
|
208 | 246 | retrieved_dimension = search_result.alpha_dq_rule_dimension # type: ignore[attr-defined] |
209 | 247 | retrieved_column = search_result.alpha_dq_rule_base_column # type: ignore[attr-defined] |
210 | 248 | retrieved_alert_priority = search_result.alpha_dq_rule_alert_priority # type: ignore[attr-defined] |
| 249 | + retrieved_row_scope_filtering_enabled = ( |
| 250 | + search_result.alpha_dq_rule_row_scope_filtering_enabled # type: ignore[attr-defined] |
| 251 | + ) |
211 | 252 | retrieved_description = search_result.user_description |
212 | 253 | retrieved_asset = search_result.alpha_dq_rule_base_dataset # type: ignore[attr-defined] |
213 | 254 | retrieved_template_rule_name = search_result.alpha_dq_rule_template_name # type: ignore[attr-defined] |
|
234 | 275 | else None |
235 | 276 | ) # type: ignore[attr-defined] |
236 | 277 |
|
| 278 | + retrieved_rule_type = retrieved_template_rule_name |
| 279 | + template_config = client.dq_template_config_cache.get_template_config( |
| 280 | + retrieved_rule_type |
| 281 | + ) |
| 282 | + validated_threshold_operator = ( |
| 283 | + alpha_DQRule.Attributes._validate_template_features( |
| 284 | + retrieved_rule_type, |
| 285 | + rule_conditions, |
| 286 | + row_scope_filtering_enabled, |
| 287 | + template_config, |
| 288 | + threshold_compare_operator or retrieved_threshold_compare_operator, |
| 289 | + retrieved_asset, |
| 290 | + ) |
| 291 | + ) |
| 292 | + |
| 293 | + final_compare_operator = ( |
| 294 | + validated_threshold_operator |
| 295 | + or threshold_compare_operator |
| 296 | + or retrieved_threshold_compare_operator |
| 297 | + or alpha_DQRuleThresholdCompareOperator.LESS_THAN_EQUAL |
| 298 | + ) |
| 299 | + |
237 | 300 | config_arguments_raw = alpha_DQRule.Attributes._generate_config_arguments_raw( |
238 | 301 | is_alert_enabled=True, |
239 | 302 | custom_sql=custom_sql or retrieved_custom_sql, |
240 | 303 | display_name=rule_name or retrieved_rule_name, |
241 | 304 | dimension=dimension or retrieved_dimension, |
242 | | - compare_operator=threshold_compare_operator |
243 | | - or retrieved_threshold_compare_operator, |
| 305 | + compare_operator=final_compare_operator, |
244 | 306 | threshold_value=threshold_value or retrieved_threshold_value, |
245 | 307 | threshold_unit=threshold_unit or retrieved_threshold_unit, |
246 | 308 | column=retrieved_column, |
247 | 309 | dq_priority=alert_priority or retrieved_alert_priority, |
248 | 310 | description=description or retrieved_description, |
| 311 | + rule_conditions=rule_conditions, |
| 312 | + row_scope_filtering_enabled=row_scope_filtering_enabled, |
249 | 313 | ) |
250 | 314 |
|
251 | 315 | attr_dq = cls.Attributes( |
252 | 316 | name="", |
253 | 317 | alpha_dq_rule_config_arguments=alpha_DQRuleConfigArguments( |
254 | 318 | alpha_dq_rule_threshold_object=alpha_DQRuleThresholdObject( |
255 | | - alpha_dq_rule_threshold_compare_operator=threshold_compare_operator |
256 | | - or retrieved_threshold_compare_operator, |
| 319 | + alpha_dq_rule_threshold_compare_operator=final_compare_operator, |
257 | 320 | alpha_dq_rule_threshold_value=threshold_value |
258 | 321 | or retrieved_threshold_value, |
259 | 322 | alpha_dq_rule_threshold_unit=threshold_unit |
260 | 323 | or retrieved_threshold_unit, |
261 | 324 | ), |
262 | 325 | alpha_dq_rule_config_arguments_raw=config_arguments_raw, |
| 326 | + alpha_dq_rule_config_rule_conditions=rule_conditions, |
263 | 327 | ), |
264 | 328 | alpha_dq_rule_base_dataset_qualified_name=retrieved_asset.qualified_name, |
265 | 329 | alpha_dq_rule_alert_priority=alert_priority or retrieved_alert_priority, |
| 330 | + alpha_dq_rule_row_scope_filtering_enabled=row_scope_filtering_enabled |
| 331 | + or retrieved_row_scope_filtering_enabled, |
266 | 332 | alpha_dq_rule_base_dataset=retrieved_asset, |
267 | 333 | qualified_name=qualified_name, |
268 | 334 | alpha_dq_rule_dimension=dimension or retrieved_dimension, |
|
0 commit comments