7
7
from datetime import datetime
8
8
from typing import TYPE_CHECKING , ClassVar , List , Optional , Set , overload
9
9
10
+ from pyatlan .utils import init_guid , validate_required_fields ,ErrorCode
11
+ import json
12
+ import uuid
13
+ import time
14
+
10
15
from pydantic .v1 import Field , validator
11
16
12
17
from pyatlan .model .enums import (
25
30
RelationField ,
26
31
TextField ,
27
32
)
33
+
28
34
from 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
34
35
35
36
from .data_quality import DataQuality
36
- # from fluent_search import FluentSearch
37
37
38
38
if TYPE_CHECKING :
39
39
from pyatlan .model .assets import Column
40
+ from pyatlan .client .atlan import AtlanClient
41
+
40
42
41
43
42
44
class alpha_DQRule (DataQuality ):
@@ -46,7 +48,7 @@ class alpha_DQRule(DataQuality):
46
48
def custom_sql_creator (
47
49
cls ,
48
50
* ,
49
- # client: AtlanClient,
51
+ client : AtlanClient ,
50
52
rule_name : str ,
51
53
asset : Asset ,
52
54
custom_sql : str ,
@@ -61,8 +63,8 @@ def custom_sql_creator(
61
63
[rule_name , asset , threshold_compare_operator , threshold_value , alert_priority ,dimension , custom_sql ],
62
64
)
63
65
64
- attributes = alpha_DQRule .Attributes .create (
65
- # client=client,
66
+ attributes = alpha_DQRule .Attributes .creator (
67
+ client = client ,
66
68
rule_name = rule_name ,
67
69
rule_type = "Custom SQL" ,
68
70
asset = asset ,
@@ -82,7 +84,7 @@ def custom_sql_creator(
82
84
def table_level_rule_creator (
83
85
cls ,
84
86
* ,
85
- # client:AtlanClient,
87
+ client :AtlanClient ,
86
88
rule_type : str ,
87
89
asset : Asset ,
88
90
threshold_compare_operator : alpha_DQRuleThresholdCompareOperator ,
@@ -94,7 +96,7 @@ def table_level_rule_creator(
94
96
[rule_type , asset , threshold_compare_operator , threshold_value , alert_priority ],
95
97
)
96
98
97
- attributes = alpha_DQRule .Attributes .create (
99
+ attributes = alpha_DQRule .Attributes .creator (
98
100
client = client ,
99
101
rule_type = rule_type ,
100
102
asset = asset ,
@@ -115,7 +117,7 @@ def table_level_rule_creator(
115
117
def column_level_rule_creator (
116
118
cls ,
117
119
* ,
118
- # client:AtlanClient,
120
+ client :AtlanClient ,
119
121
rule_type : str ,
120
122
asset : Asset ,
121
123
column_qualified_name : str ,
@@ -129,7 +131,7 @@ def column_level_rule_creator(
129
131
[rule_type , asset , column_qualified_name , threshold_compare_operator , threshold_value , alert_priority ],
130
132
)
131
133
132
- attributes = alpha_DQRule .Attributes .create (
134
+ attributes = alpha_DQRule .Attributes .creator (
133
135
client = client ,
134
136
rule_type = rule_type ,
135
137
asset = asset ,
@@ -878,10 +880,10 @@ def replace_char(c):
878
880
879
881
@classmethod
880
882
@init_guid
881
- def create (
883
+ def creator (
882
884
cls ,
883
885
* ,
884
- # client: AtlanClient,
886
+ client : AtlanClient ,
885
887
rule_name :str ,
886
888
rule_type : str ,
887
889
asset : Asset ,
@@ -894,19 +896,34 @@ def create(
894
896
custom_sql : Optional [str ] = None ,
895
897
description : Optional [str ] = None ,
896
898
) -> 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)
910
927
911
928
config_arguments_raw = alpha_DQRule .Attributes ._generate_config_arguments_raw (
912
929
is_alert_enabled = True ,
@@ -939,8 +956,8 @@ def create(
939
956
alpha_dq_rule_base_dataset = asset ,
940
957
qualified_name = f"{ asset .qualified_name } /rule/{ str (cls ._generate_uuid ())} " ,
941
958
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 ),
944
961
)
945
962
946
963
if column_qualified_name is not None :
0 commit comments