|
12 | 12 | threshold_value: int, |
13 | 13 | alert_priority: DataQualityRuleAlertPriority, |
14 | 14 | dimension: DataQualityDimension, |
| 15 | + custom_sql_return_type: Optional[DataQualityRuleCustomSQLReturnType] = None, |
15 | 16 | description: Optional[str] = None, |
16 | 17 | ) -> DataQualityRule: |
17 | 18 | validate_required_fields( |
|
47 | 48 | alert_priority=alert_priority, |
48 | 49 | dimension=dimension, |
49 | 50 | custom_sql=custom_sql, |
| 51 | + custom_sql_return_type=custom_sql_return_type, |
50 | 52 | description=description, |
51 | 53 | column=None, |
52 | 54 | threshold_unit=None, |
|
64 | 66 | threshold_compare_operator: DataQualityRuleThresholdCompareOperator, |
65 | 67 | threshold_value: int, |
66 | 68 | alert_priority: DataQualityRuleAlertPriority, |
| 69 | + threshold_unit: Optional[DataQualityRuleThresholdUnit] = None, |
67 | 70 | ) -> DataQualityRule: |
68 | 71 | validate_required_fields( |
69 | 72 | [ |
|
93 | 96 | alert_priority=alert_priority, |
94 | 97 | rule_name=None, |
95 | 98 | column=None, |
96 | | - threshold_unit=None, |
| 99 | + threshold_unit=threshold_unit, |
97 | 100 | dimension=None, |
98 | 101 | custom_sql=None, |
99 | 102 | description=None, |
|
138 | 141 | ) |
139 | 142 | template_config = client.dq_template_config_cache.get_template_config(rule_type) |
140 | 143 |
|
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.ASSET_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] |
| 144 | + asset_for_validation, target_table_asset = ( |
| 145 | + DataQualityRule.Attributes._fetch_assets_for_row_scope_validation( |
| 146 | + client, asset, rule_conditions, row_scope_filtering_enabled |
| 147 | + ) |
| 148 | + ) |
155 | 149 |
|
156 | 150 | validated_threshold_operator = ( |
157 | 151 | DataQualityRule.Attributes._validate_template_features( |
|
161 | 155 | template_config, |
162 | 156 | threshold_compare_operator, |
163 | 157 | asset_for_validation, |
| 158 | + target_table_asset, |
164 | 159 | ) |
165 | 160 | ) |
166 | 161 |
|
|
202 | 197 | threshold_unit: Optional[DataQualityRuleThresholdUnit] = None, |
203 | 198 | dimension: Optional[DataQualityDimension] = None, |
204 | 199 | custom_sql: Optional[str] = None, |
| 200 | + custom_sql_return_type: Optional[DataQualityRuleCustomSQLReturnType] = None, |
205 | 201 | rule_name: Optional[str] = None, |
206 | 202 | description: Optional[str] = None, |
207 | 203 | rule_conditions: Optional[str] = None, |
|
224 | 220 | .include_on_results(DataQualityRule.DQ_RULE_ALERT_PRIORITY) |
225 | 221 | .include_on_results(DataQualityRule.DISPLAY_NAME) |
226 | 222 | .include_on_results(DataQualityRule.DQ_RULE_CUSTOM_SQL) |
| 223 | + .include_on_results(DataQualityRule.DQ_RULE_CUSTOM_SQL_RETURN_TYPE) |
227 | 224 | .include_on_results(DataQualityRule.USER_DESCRIPTION) |
228 | 225 | .include_on_results(DataQualityRule.DQ_RULE_DIMENSION) |
229 | 226 | .include_on_results(DataQualityRule.DQ_RULE_CONFIG_ARGUMENTS) |
|
242 | 239 | search_result = results.current_page()[0] |
243 | 240 |
|
244 | 241 | retrieved_custom_sql = search_result.dq_rule_custom_s_q_l # type: ignore[attr-defined] |
| 242 | + retrieved_custom_sql_return_type = ( |
| 243 | + search_result.dq_rule_custom_s_q_l_return_type # type: ignore[attr-defined] |
| 244 | + ) |
245 | 245 | retrieved_rule_name = search_result.display_name |
246 | 246 | retrieved_dimension = search_result.dq_rule_dimension # type: ignore[attr-defined] |
247 | 247 | retrieved_column = search_result.dq_rule_base_column # type: ignore[attr-defined] |
|
279 | 279 | template_config = client.dq_template_config_cache.get_template_config( |
280 | 280 | retrieved_rule_type |
281 | 281 | ) |
| 282 | + |
| 283 | + final_rule_conditions = rule_conditions or ( |
| 284 | + search_result.dq_rule_config_arguments.dq_rule_config_rule_conditions # type: ignore[attr-defined] |
| 285 | + if search_result.dq_rule_config_arguments is not None # type: ignore[attr-defined] |
| 286 | + else None |
| 287 | + ) |
| 288 | + |
| 289 | + final_row_scope_filtering_enabled = ( |
| 290 | + row_scope_filtering_enabled or retrieved_row_scope_filtering_enabled |
| 291 | + ) |
| 292 | + if retrieved_asset: |
| 293 | + retrieved_asset, target_table_asset = ( |
| 294 | + DataQualityRule.Attributes._fetch_assets_for_row_scope_validation( |
| 295 | + client, |
| 296 | + retrieved_asset, |
| 297 | + final_rule_conditions, |
| 298 | + final_row_scope_filtering_enabled, |
| 299 | + ) |
| 300 | + ) |
| 301 | + else: |
| 302 | + target_table_asset = None |
| 303 | + |
282 | 304 | validated_threshold_operator = ( |
283 | 305 | DataQualityRule.Attributes._validate_template_features( |
284 | 306 | retrieved_rule_type, |
285 | 307 | rule_conditions, |
286 | | - row_scope_filtering_enabled, |
| 308 | + final_row_scope_filtering_enabled, |
287 | 309 | template_config, |
288 | 310 | threshold_compare_operator or retrieved_threshold_compare_operator, |
289 | 311 | retrieved_asset, |
| 312 | + target_table_asset, |
290 | 313 | ) |
291 | 314 | ) |
292 | 315 |
|
|
310 | 333 | ), |
311 | 334 | dq_rule_base_dataset_qualified_name=retrieved_asset.qualified_name, |
312 | 335 | dq_rule_alert_priority=alert_priority or retrieved_alert_priority, |
313 | | - dq_rule_row_scope_filtering_enabled=row_scope_filtering_enabled |
314 | | - or retrieved_row_scope_filtering_enabled, |
| 336 | + dq_rule_row_scope_filtering_enabled=final_row_scope_filtering_enabled, |
315 | 337 | dq_rule_base_dataset=retrieved_asset, |
316 | 338 | qualified_name=qualified_name, |
317 | 339 | dq_rule_dimension=dimension or retrieved_dimension, |
|
329 | 351 | if custom_sql is not None: |
330 | 352 | attr_dq.dq_rule_custom_s_q_l = custom_sql |
331 | 353 | attr_dq.display_name = rule_name or retrieved_rule_name |
| 354 | + attr_dq.dq_rule_custom_s_q_l_return_type = ( |
| 355 | + custom_sql_return_type or retrieved_custom_sql_return_type |
| 356 | + ) |
332 | 357 | if description is not None: |
333 | 358 | attr_dq.user_description = description or retrieved_description |
334 | 359 |
|
|
0 commit comments