Skip to content

Commit dff2bb0

Browse files
committed
Creator coming to closure
1 parent 362da79 commit dff2bb0

File tree

3 files changed

+63
-30
lines changed

3 files changed

+63
-30
lines changed

pyatlan/errors.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,13 @@ class ErrorCode(Enum):
932932
"Verify the API token provided is a valid username for that token.",
933933
NotFoundError,
934934
)
935+
DQ_RULE_NOT_FOUND = (
936+
404,
937+
"ATLAN-PYTHON-404-029",
938+
"DQ rule with type {0} was not found.",
939+
"Verify you have provided a valid DQ rule type.",
940+
NotFoundError,
941+
)
935942
CONFLICT_PASSTHROUGH = (
936943
409,
937944
"ATLAN-PYTHON-409-000",

pyatlan/model/assets/core/alpha__d_q_rule.py

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
from datetime import datetime
88
from 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+
1015
from pydantic.v1 import Field, validator
1116

1217
from pyatlan.model.enums import (
@@ -25,18 +30,15 @@
2530
RelationField,
2631
TextField,
2732
)
33+
2834
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
3435

3536
from .data_quality import DataQuality
36-
# from fluent_search import FluentSearch
3737

3838
if TYPE_CHECKING:
3939
from pyatlan.model.assets import Column
40+
from pyatlan.client.atlan import AtlanClient
41+
4042

4143

4244
class 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:

pyatlan/model/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,20 @@ def encoders():
2525
}
2626

2727

28+
def convert_with_fixed_prefix(input_str, fixed_prefix='alpha_dq'):
29+
prefix = fixed_prefix
30+
remaining = input_str[len(prefix)+1:]
31+
parts = remaining.split('_')
32+
camel_part = ''.join(word.capitalize() for word in parts)
33+
return prefix + camel_part
34+
2835
def to_camel_case(value: str) -> str:
2936
if not isinstance(value, str):
3037
raise ValueError("Value must be a string")
3138
if value == "__root__":
3239
return value
40+
if value.startswith("alpha_dq"):
41+
return convert_with_fixed_prefix(value)
3342
if value in CAMEL_CASE_OVERRIDES:
3443
return CAMEL_CASE_OVERRIDES[value]
3544
value = "".join(word.capitalize() for word in value.split("_"))

0 commit comments

Comments
 (0)