77from datetime import datetime
88from typing import TYPE_CHECKING , ClassVar , List , Optional , Set , overload
99
10+ from pyatlan .utils import init_guid , validate_required_fields ,ErrorCode
11+ import json
12+ import uuid
13+ import time
14+
1015from pydantic .v1 import Field , validator
1116
1217from pyatlan .model .enums import (
2530 RelationField ,
2631 TextField ,
2732)
33+
2834from pyatlan .model .structs import alpha_DQRuleConfigArguments , alpha_DQRuleThresholdObject
29- from pyatlan .utils import init_guid , validate_required_fields
30- # from pyatlan.client.atlan import AtlanClient
31- import json
32- import uuid
33- import time
3435
3536from .data_quality import DataQuality
36- # from fluent_search import FluentSearch
3737
3838if TYPE_CHECKING :
3939 from pyatlan .model .assets import Column
40+ from pyatlan .client .atlan import AtlanClient
41+
4042
4143
4244class alpha_DQRule (DataQuality ):
@@ -46,7 +48,7 @@ class alpha_DQRule(DataQuality):
4648 def custom_sql_creator (
4749 cls ,
4850 * ,
49- # client: AtlanClient,
51+ client : AtlanClient ,
5052 rule_name : str ,
5153 asset : Asset ,
5254 custom_sql : str ,
@@ -61,8 +63,8 @@ def custom_sql_creator(
6163 [rule_name , asset , threshold_compare_operator , threshold_value , alert_priority ,dimension , custom_sql ],
6264 )
6365
64- attributes = alpha_DQRule .Attributes .create (
65- # client=client,
66+ attributes = alpha_DQRule .Attributes .creator (
67+ client = client ,
6668 rule_name = rule_name ,
6769 rule_type = "Custom SQL" ,
6870 asset = asset ,
@@ -82,7 +84,7 @@ def custom_sql_creator(
8284 def table_level_rule_creator (
8385 cls ,
8486 * ,
85- # client:AtlanClient,
87+ client :AtlanClient ,
8688 rule_type : str ,
8789 asset : Asset ,
8890 threshold_compare_operator : alpha_DQRuleThresholdCompareOperator ,
@@ -94,7 +96,7 @@ def table_level_rule_creator(
9496 [rule_type , asset , threshold_compare_operator , threshold_value , alert_priority ],
9597 )
9698
97- attributes = alpha_DQRule .Attributes .create (
99+ attributes = alpha_DQRule .Attributes .creator (
98100 client = client ,
99101 rule_type = rule_type ,
100102 asset = asset ,
@@ -115,7 +117,7 @@ def table_level_rule_creator(
115117 def column_level_rule_creator (
116118 cls ,
117119 * ,
118- # client:AtlanClient,
120+ client :AtlanClient ,
119121 rule_type : str ,
120122 asset : Asset ,
121123 column_qualified_name : str ,
@@ -129,7 +131,7 @@ def column_level_rule_creator(
129131 [rule_type , asset , column_qualified_name , threshold_compare_operator , threshold_value , alert_priority ],
130132 )
131133
132- attributes = alpha_DQRule .Attributes .create (
134+ attributes = alpha_DQRule .Attributes .creator (
133135 client = client ,
134136 rule_type = rule_type ,
135137 asset = asset ,
@@ -878,10 +880,10 @@ def replace_char(c):
878880
879881 @classmethod
880882 @init_guid
881- def create (
883+ def creator (
882884 cls ,
883885 * ,
884- # client: AtlanClient,
886+ client : AtlanClient ,
885887 rule_name :str ,
886888 rule_type : str ,
887889 asset : Asset ,
@@ -894,19 +896,34 @@ def create(
894896 custom_sql : Optional [str ] = None ,
895897 description : Optional [str ] = None ,
896898 ) -> alpha_DQRule .Attributes :
897- # request = (
898- # FluentSearch()
899- # .where(Asset.TYPE_NAME.eq("alpha_DQRuleTemplate"))
900- # .include_on_results(Asset.NAME)
901- # .include_on_results(Asset.DISPLAY_NAME)
902- # .include_on_results(Asset.QUALIFIED_NAME)
903- # ).to_request() #
904- # for result in client.asset.search(request):
905- # if result.display_name == rule_type:
906- # template_rule_name = result.name
907- # template_qualified_name = result.qualified_name
908- # if dimension is None:
909- # dimension = result.alpha_dq_rule_dimension
899+ from pyatlan .model .fluent_search import FluentSearch
900+
901+ request = (
902+ FluentSearch ()
903+ .where (Asset .TYPE_NAME .eq (alpha_DQRuleTemplate .__name__ ))
904+ .include_on_results (alpha_DQRuleTemplate .NAME )
905+ .include_on_results (alpha_DQRuleTemplate .QUALIFIED_NAME )
906+ .include_on_results (alpha_DQRuleTemplate .DISPLAY_NAME )
907+ .include_on_results (alpha_DQRuleTemplate .ALPHADQ_RULE_TEMPLATE_DIMENSION )
908+ .include_on_results (alpha_DQRuleTemplate .ALPHADQ_RULE_TEMPLATE_CONFIG )
909+ ).to_request ()
910+ for result in client .asset .search (request ):
911+ if result .display_name == rule_type :
912+ template_rule_name = result .name
913+ template_qualified_name = result .qualified_name
914+
915+ if dimension is None :
916+ dimension = result .alpha_dq_rule_template_dimension
917+
918+ if threshold_unit is None :
919+ threashold_object = result .alpha_dq_rule_template_config .alpha_dq_rule_template_config_threshold_object
920+ threashold_object_json = json .loads (threashold_object )
921+ properties = threashold_object_json .get ('properties' , {})
922+ threshold_unit_field = properties .get ('alpha_dqRuleTemplateConfigThresholdUnit' , {})
923+ default_value = threshold_unit_field .get ('default' )
924+ threshold_unit = default_value
925+ # else:
926+ # raise ErrorCode.DQ_RULE_NOT_FOUND.exception_with_parameters(result.display_name)
910927
911928 config_arguments_raw = alpha_DQRule .Attributes ._generate_config_arguments_raw (
912929 is_alert_enabled = True ,
@@ -939,8 +956,8 @@ def create(
939956 alpha_dq_rule_base_dataset = asset ,
940957 qualified_name = f"{ asset .qualified_name } /rule/{ str (cls ._generate_uuid ())} " ,
941958 alpha_dq_rule_dimension = dimension ,
942- # alpha_dq_rule_template_name=template_rule_name,
943- # alpha_dq_rule_template=alpha_DQRuleTemplate.ref_by_qualified_name(qualified_name=template_qualified_name),
959+ alpha_dq_rule_template_name = template_rule_name ,
960+ alpha_dq_rule_template = alpha_DQRuleTemplate .ref_by_qualified_name (qualified_name = template_qualified_name ),
944961 )
945962
946963 if column_qualified_name is not None :
0 commit comments