acryl-datahub-cloud 0.3.12.4rc2__py3-none-any.whl → 0.3.13rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of acryl-datahub-cloud might be problematic. Click here for more details.

Files changed (35) hide show
  1. acryl_datahub_cloud/_codegen_config.json +1 -1
  2. acryl_datahub_cloud/lineage_features/source.py +8 -2
  3. acryl_datahub_cloud/metadata/_urns/urn_defs.py +112 -0
  4. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/identity/__init__.py +2 -0
  5. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/metadata/key/__init__.py +4 -0
  6. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/module/__init__.py +27 -0
  7. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/settings/global/__init__.py +4 -0
  8. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/template/__init__.py +25 -0
  9. acryl_datahub_cloud/metadata/schema.avsc +443 -0
  10. acryl_datahub_cloud/metadata/schema_classes.py +682 -1
  11. acryl_datahub_cloud/metadata/schemas/CorpUserSettings.avsc +41 -0
  12. acryl_datahub_cloud/metadata/schemas/DataHubPageModuleKey.avsc +21 -0
  13. acryl_datahub_cloud/metadata/schemas/DataHubPageModuleProperties.avsc +200 -0
  14. acryl_datahub_cloud/metadata/schemas/DataHubPageTemplateKey.avsc +21 -0
  15. acryl_datahub_cloud/metadata/schemas/DataHubPageTemplateProperties.avsc +175 -0
  16. acryl_datahub_cloud/metadata/schemas/DataJobInputOutput.avsc +8 -0
  17. acryl_datahub_cloud/metadata/schemas/GlobalSettingsInfo.avsc +62 -0
  18. acryl_datahub_cloud/metadata/schemas/MetadataChangeEvent.avsc +9 -0
  19. acryl_datahub_cloud/metadata/schemas/UpstreamLineage.avsc +9 -0
  20. acryl_datahub_cloud/sdk/assertion/__init__.py +49 -0
  21. acryl_datahub_cloud/sdk/assertion/assertion_base.py +65 -806
  22. acryl_datahub_cloud/sdk/assertion/freshness_assertion.py +201 -0
  23. acryl_datahub_cloud/sdk/assertion/smart_freshness_assertion.py +165 -0
  24. acryl_datahub_cloud/sdk/assertion/smart_volume_assertion.py +162 -0
  25. acryl_datahub_cloud/sdk/assertion/sql_assertion.py +256 -0
  26. acryl_datahub_cloud/sdk/assertion/volume_assertion.py +156 -0
  27. acryl_datahub_cloud/sdk/assertion_input/assertion_input.py +0 -344
  28. acryl_datahub_cloud/sdk/assertion_input/smart_freshness_assertion_input.py +220 -0
  29. acryl_datahub_cloud/sdk/assertion_input/smart_volume_assertion_input.py +191 -0
  30. acryl_datahub_cloud/sdk/assertions_client.py +6 -2
  31. {acryl_datahub_cloud-0.3.12.4rc2.dist-info → acryl_datahub_cloud-0.3.13rc1.dist-info}/METADATA +48 -46
  32. {acryl_datahub_cloud-0.3.12.4rc2.dist-info → acryl_datahub_cloud-0.3.13rc1.dist-info}/RECORD +35 -22
  33. {acryl_datahub_cloud-0.3.12.4rc2.dist-info → acryl_datahub_cloud-0.3.13rc1.dist-info}/WHEEL +0 -0
  34. {acryl_datahub_cloud-0.3.12.4rc2.dist-info → acryl_datahub_cloud-0.3.13rc1.dist-info}/entry_points.txt +0 -0
  35. {acryl_datahub_cloud-0.3.12.4rc2.dist-info → acryl_datahub_cloud-0.3.13rc1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,201 @@
1
+ import logging
2
+ from datetime import datetime
3
+ from typing import Optional, Union
4
+
5
+ from typing_extensions import Self
6
+
7
+ from acryl_datahub_cloud.sdk.assertion.assertion_base import (
8
+ AssertionMode,
9
+ _AssertionPublic,
10
+ _HasSchedule,
11
+ )
12
+ from acryl_datahub_cloud.sdk.assertion_input.assertion_input import (
13
+ DEFAULT_DETECTION_MECHANISM,
14
+ AssertionIncidentBehavior,
15
+ DetectionMechanism,
16
+ TimeWindowSizeInputTypes,
17
+ _DetectionMechanismTypes,
18
+ )
19
+ from acryl_datahub_cloud.sdk.entities.assertion import Assertion
20
+ from acryl_datahub_cloud.sdk.entities.monitor import Monitor
21
+ from acryl_datahub_cloud.sdk.errors import SDKNotYetSupportedError
22
+ from datahub.metadata import schema_classes as models
23
+ from datahub.metadata.urns import AssertionUrn, CorpUserUrn, DatasetUrn, TagUrn
24
+
25
+ logger = logging.getLogger(__name__)
26
+
27
+
28
+ class FreshnessAssertion(_HasSchedule, _AssertionPublic):
29
+ """
30
+ A class that represents a freshness assertion.
31
+ """
32
+
33
+ def __init__(
34
+ self,
35
+ *,
36
+ urn: AssertionUrn,
37
+ dataset_urn: DatasetUrn,
38
+ display_name: str,
39
+ mode: AssertionMode,
40
+ schedule: models.CronScheduleClass,
41
+ freshness_schedule_check_type: Union[
42
+ str, models.FreshnessAssertionScheduleTypeClass
43
+ ],
44
+ lookback_window: Optional[TimeWindowSizeInputTypes],
45
+ tags: list[TagUrn],
46
+ incident_behavior: list[AssertionIncidentBehavior],
47
+ detection_mechanism: Optional[
48
+ _DetectionMechanismTypes
49
+ ] = DEFAULT_DETECTION_MECHANISM,
50
+ created_by: Optional[CorpUserUrn] = None,
51
+ created_at: Union[datetime, None] = None,
52
+ updated_by: Optional[CorpUserUrn] = None,
53
+ updated_at: Optional[datetime] = None,
54
+ ):
55
+ """
56
+ Initialize a freshness assertion.
57
+
58
+ Note: Values can be accessed, but not set on the assertion object.
59
+ To update an assertion, use the `upsert_*` method.
60
+ Args:
61
+ urn: The urn of the assertion.
62
+ dataset_urn: The urn of the dataset that the assertion is for.
63
+ display_name: The display name of the assertion.
64
+ mode: The mode of the assertion (active, inactive).
65
+ schedule: The schedule of the assertion.
66
+ freshness_schedule_check_type: The type of freshness schedule check to be used for the assertion.
67
+ lookback_window: The lookback window to be used for the assertion.
68
+ tags: The tags applied to the assertion.
69
+ incident_behavior: Whether to raise or resolve an incident when the assertion fails / passes.
70
+ detection_mechanism: The detection mechanism of the assertion.
71
+ created_by: The urn of the user that created the assertion.
72
+ created_at: The timestamp of when the assertion was created.
73
+ updated_by: The urn of the user that updated the assertion.
74
+ updated_at: The timestamp of when the assertion was updated.
75
+ """
76
+ _HasSchedule.__init__(self, schedule=schedule)
77
+ _AssertionPublic.__init__(
78
+ self,
79
+ urn=urn,
80
+ dataset_urn=dataset_urn,
81
+ display_name=display_name,
82
+ mode=mode,
83
+ incident_behavior=incident_behavior,
84
+ detection_mechanism=detection_mechanism,
85
+ created_by=created_by,
86
+ created_at=created_at,
87
+ updated_by=updated_by,
88
+ updated_at=updated_at,
89
+ tags=tags,
90
+ )
91
+ self._freshness_schedule_check_type = freshness_schedule_check_type
92
+ self._lookback_window = lookback_window
93
+
94
+ @property
95
+ def freshness_schedule_check_type(
96
+ self,
97
+ ) -> Union[str, models.FreshnessAssertionScheduleTypeClass]:
98
+ return self._freshness_schedule_check_type
99
+
100
+ @property
101
+ def lookback_window(self) -> Optional[TimeWindowSizeInputTypes]:
102
+ return self._lookback_window
103
+
104
+ @staticmethod
105
+ def _get_freshness_schedule_check_type(
106
+ assertion: Assertion,
107
+ ) -> Union[str, models.FreshnessAssertionScheduleTypeClass]:
108
+ if assertion.info is None:
109
+ raise SDKNotYetSupportedError(
110
+ f"Assertion {assertion.urn} does not have a freshness assertion info, which is not supported"
111
+ )
112
+ if isinstance(assertion.info, models.FreshnessAssertionInfoClass):
113
+ if assertion.info.schedule is None:
114
+ raise SDKNotYetSupportedError(
115
+ f"Traditional freshness assertion {assertion.urn} does not have a schedule, which is not supported"
116
+ )
117
+ return assertion.info.schedule.type
118
+ else:
119
+ raise SDKNotYetSupportedError(
120
+ f"Assertion {assertion.urn} is not a freshness assertion"
121
+ )
122
+
123
+ @staticmethod
124
+ def _get_lookback_window(
125
+ assertion: Assertion,
126
+ ) -> Optional[models.FixedIntervalScheduleClass]:
127
+ if assertion.info is None:
128
+ raise SDKNotYetSupportedError(
129
+ f"Assertion {assertion.urn} does not have a freshness assertion info, which is not supported"
130
+ )
131
+ if isinstance(assertion.info, models.FreshnessAssertionInfoClass):
132
+ if assertion.info.schedule is None:
133
+ raise SDKNotYetSupportedError(
134
+ f"Traditional freshness assertion {assertion.urn} does not have a schedule, which is not supported"
135
+ )
136
+ return assertion.info.schedule.fixedInterval
137
+ else:
138
+ raise SDKNotYetSupportedError(
139
+ f"Assertion {assertion.urn} is not a freshness assertion"
140
+ )
141
+
142
+ @staticmethod
143
+ def _get_detection_mechanism(
144
+ assertion: Assertion,
145
+ monitor: Monitor,
146
+ default: Optional[_DetectionMechanismTypes] = DEFAULT_DETECTION_MECHANISM,
147
+ ) -> Optional[_DetectionMechanismTypes]:
148
+ """Get the detection mechanism for freshness assertions."""
149
+ parameters = _AssertionPublic._get_validated_detection_context(
150
+ monitor,
151
+ assertion,
152
+ models.AssertionEvaluationParametersTypeClass.DATASET_FRESHNESS,
153
+ models.FreshnessAssertionInfoClass,
154
+ default,
155
+ )
156
+ if parameters is None:
157
+ return default
158
+ if parameters.datasetFreshnessParameters is None:
159
+ logger.warning(
160
+ f"Monitor does not have datasetFreshnessParameters, defaulting detection mechanism to {DEFAULT_DETECTION_MECHANISM}"
161
+ )
162
+ return default
163
+ source_type = parameters.datasetFreshnessParameters.sourceType
164
+ if source_type == models.DatasetFreshnessSourceTypeClass.INFORMATION_SCHEMA:
165
+ return DetectionMechanism.INFORMATION_SCHEMA
166
+ elif source_type == models.DatasetFreshnessSourceTypeClass.AUDIT_LOG:
167
+ return DetectionMechanism.AUDIT_LOG
168
+ elif source_type == models.DatasetFreshnessSourceTypeClass.FIELD_VALUE:
169
+ return _AssertionPublic._get_field_value_detection_mechanism(
170
+ assertion, parameters
171
+ )
172
+ elif source_type == models.DatasetFreshnessSourceTypeClass.DATAHUB_OPERATION:
173
+ return DetectionMechanism.DATAHUB_OPERATION
174
+ elif source_type == models.DatasetFreshnessSourceTypeClass.FILE_METADATA:
175
+ raise SDKNotYetSupportedError("FILE_METADATA DatasetFreshnessSourceType")
176
+ else:
177
+ raise SDKNotYetSupportedError(f"DatasetFreshnessSourceType {source_type}")
178
+
179
+ @classmethod
180
+ def _from_entities(cls, assertion: Assertion, monitor: Monitor) -> Self:
181
+ """
182
+ Create a freshness assertion from the assertion and monitor entities.
183
+ """
184
+ return cls(
185
+ urn=assertion.urn,
186
+ dataset_urn=assertion.dataset,
187
+ display_name=assertion.description or "",
188
+ mode=cls._get_mode(monitor),
189
+ schedule=cls._get_schedule(monitor),
190
+ freshness_schedule_check_type=cls._get_freshness_schedule_check_type(
191
+ assertion
192
+ ),
193
+ lookback_window=cls._get_lookback_window(assertion),
194
+ incident_behavior=cls._get_incident_behavior(assertion),
195
+ detection_mechanism=cls._get_detection_mechanism(assertion, monitor),
196
+ created_by=cls._get_created_by(assertion),
197
+ created_at=cls._get_created_at(assertion),
198
+ updated_by=cls._get_updated_by(assertion),
199
+ updated_at=cls._get_updated_at(assertion),
200
+ tags=cls._get_tags(assertion),
201
+ )
@@ -0,0 +1,165 @@
1
+ import logging
2
+ from datetime import datetime
3
+ from typing import Optional, Union
4
+
5
+ from typing_extensions import Self
6
+
7
+ from acryl_datahub_cloud.sdk.assertion.assertion_base import (
8
+ AssertionMode,
9
+ _AssertionPublic,
10
+ _HasSchedule,
11
+ _HasSmartFunctionality,
12
+ )
13
+ from acryl_datahub_cloud.sdk.assertion_input.assertion_input import (
14
+ ASSERTION_MONITOR_DEFAULT_TRAINING_LOOKBACK_WINDOW_DAYS,
15
+ DEFAULT_DETECTION_MECHANISM,
16
+ DEFAULT_SCHEDULE,
17
+ DEFAULT_SENSITIVITY,
18
+ AssertionIncidentBehavior,
19
+ DetectionMechanism,
20
+ ExclusionWindowTypes,
21
+ InferenceSensitivity,
22
+ _DetectionMechanismTypes,
23
+ )
24
+ from acryl_datahub_cloud.sdk.entities.assertion import Assertion
25
+ from acryl_datahub_cloud.sdk.entities.monitor import Monitor
26
+ from acryl_datahub_cloud.sdk.errors import SDKNotYetSupportedError
27
+ from datahub.metadata import schema_classes as models
28
+ from datahub.metadata.urns import AssertionUrn, CorpUserUrn, DatasetUrn, TagUrn
29
+
30
+ logger = logging.getLogger(__name__)
31
+
32
+
33
+ class SmartFreshnessAssertion(_HasSchedule, _HasSmartFunctionality, _AssertionPublic):
34
+ """
35
+ A class that represents a smart freshness assertion.
36
+ """
37
+
38
+ def __init__(
39
+ self,
40
+ *,
41
+ urn: AssertionUrn,
42
+ dataset_urn: DatasetUrn,
43
+ display_name: str,
44
+ mode: AssertionMode,
45
+ schedule: models.CronScheduleClass = DEFAULT_SCHEDULE,
46
+ sensitivity: InferenceSensitivity = DEFAULT_SENSITIVITY,
47
+ exclusion_windows: list[ExclusionWindowTypes],
48
+ training_data_lookback_days: int = ASSERTION_MONITOR_DEFAULT_TRAINING_LOOKBACK_WINDOW_DAYS,
49
+ incident_behavior: list[AssertionIncidentBehavior],
50
+ detection_mechanism: Optional[
51
+ _DetectionMechanismTypes
52
+ ] = DEFAULT_DETECTION_MECHANISM,
53
+ tags: list[TagUrn],
54
+ created_by: Optional[CorpUserUrn] = None,
55
+ created_at: Union[datetime, None] = None,
56
+ updated_by: Optional[CorpUserUrn] = None,
57
+ updated_at: Optional[datetime] = None,
58
+ ):
59
+ """
60
+ Initialize a smart freshness assertion.
61
+
62
+ Note: Values can be accessed, but not set on the assertion object.
63
+ To update an assertion, use the `upsert_*` method.
64
+ Args:
65
+ urn: The urn of the assertion.
66
+ dataset_urn: The urn of the dataset that the assertion is for.
67
+ display_name: The display name of the assertion.
68
+ mode: The mode of the assertion (active, inactive).
69
+ schedule: The schedule of the assertion.
70
+ sensitivity: The sensitivity of the assertion (low, medium, high).
71
+ exclusion_windows: The exclusion windows of the assertion.
72
+ training_data_lookback_days: The max number of days of data to use for training the assertion.
73
+ incident_behavior: Whether to raise or resolve an incident when the assertion fails / passes.
74
+ detection_mechanism: The detection mechanism of the assertion.
75
+ tags: The tags applied to the assertion.
76
+ created_by: The urn of the user that created the assertion.
77
+ created_at: The timestamp of when the assertion was created.
78
+ updated_by: The urn of the user that updated the assertion.
79
+ updated_at: The timestamp of when the assertion was updated.
80
+ """
81
+ # Initialize the mixins first
82
+ _HasSchedule.__init__(self, schedule=schedule)
83
+ _HasSmartFunctionality.__init__(
84
+ self,
85
+ sensitivity=sensitivity,
86
+ exclusion_windows=exclusion_windows,
87
+ training_data_lookback_days=training_data_lookback_days,
88
+ )
89
+ # Then initialize the parent class
90
+ _AssertionPublic.__init__(
91
+ self,
92
+ urn=urn,
93
+ dataset_urn=dataset_urn,
94
+ display_name=display_name,
95
+ mode=mode,
96
+ incident_behavior=incident_behavior,
97
+ detection_mechanism=detection_mechanism,
98
+ created_by=created_by,
99
+ created_at=created_at,
100
+ updated_by=updated_by,
101
+ updated_at=updated_at,
102
+ tags=tags,
103
+ )
104
+
105
+ @classmethod
106
+ def _from_entities(cls, assertion: Assertion, monitor: Monitor) -> Self:
107
+ """
108
+ Create a smart freshness assertion from the assertion and monitor entities.
109
+
110
+ Note: This is a private method since it is intended to be called internally by the client.
111
+ """
112
+ return cls(
113
+ urn=assertion.urn,
114
+ dataset_urn=assertion.dataset,
115
+ display_name=assertion.description or "",
116
+ mode=cls._get_mode(monitor),
117
+ schedule=cls._get_schedule(monitor),
118
+ sensitivity=cls._get_sensitivity(monitor),
119
+ exclusion_windows=cls._get_exclusion_windows(monitor),
120
+ training_data_lookback_days=cls._get_training_data_lookback_days(monitor),
121
+ incident_behavior=cls._get_incident_behavior(assertion),
122
+ detection_mechanism=cls._get_detection_mechanism(assertion, monitor),
123
+ created_by=cls._get_created_by(assertion),
124
+ created_at=cls._get_created_at(assertion),
125
+ updated_by=cls._get_updated_by(assertion),
126
+ updated_at=cls._get_updated_at(assertion),
127
+ tags=cls._get_tags(assertion),
128
+ )
129
+
130
+ @staticmethod
131
+ def _get_detection_mechanism(
132
+ assertion: Assertion,
133
+ monitor: Monitor,
134
+ default: Optional[_DetectionMechanismTypes] = DEFAULT_DETECTION_MECHANISM,
135
+ ) -> Optional[_DetectionMechanismTypes]:
136
+ """Get the detection mechanism for freshness assertions."""
137
+ parameters = _AssertionPublic._get_validated_detection_context(
138
+ monitor,
139
+ assertion,
140
+ models.AssertionEvaluationParametersTypeClass.DATASET_FRESHNESS,
141
+ models.FreshnessAssertionInfoClass,
142
+ default,
143
+ )
144
+ if parameters is None:
145
+ return default
146
+ if parameters.datasetFreshnessParameters is None:
147
+ logger.warning(
148
+ f"Monitor does not have datasetFreshnessParameters, defaulting detection mechanism to {DEFAULT_DETECTION_MECHANISM}"
149
+ )
150
+ return default
151
+ source_type = parameters.datasetFreshnessParameters.sourceType
152
+ if source_type == models.DatasetFreshnessSourceTypeClass.INFORMATION_SCHEMA:
153
+ return DetectionMechanism.INFORMATION_SCHEMA
154
+ elif source_type == models.DatasetFreshnessSourceTypeClass.AUDIT_LOG:
155
+ return DetectionMechanism.AUDIT_LOG
156
+ elif source_type == models.DatasetFreshnessSourceTypeClass.FIELD_VALUE:
157
+ return _AssertionPublic._get_field_value_detection_mechanism(
158
+ assertion, parameters
159
+ )
160
+ elif source_type == models.DatasetFreshnessSourceTypeClass.DATAHUB_OPERATION:
161
+ return DetectionMechanism.DATAHUB_OPERATION
162
+ elif source_type == models.DatasetFreshnessSourceTypeClass.FILE_METADATA:
163
+ raise SDKNotYetSupportedError("FILE_METADATA DatasetFreshnessSourceType")
164
+ else:
165
+ raise SDKNotYetSupportedError(f"DatasetFreshnessSourceType {source_type}")
@@ -0,0 +1,162 @@
1
+ import logging
2
+ from datetime import datetime
3
+ from typing import Optional, Union
4
+
5
+ from typing_extensions import Self
6
+
7
+ from acryl_datahub_cloud.sdk.assertion.assertion_base import (
8
+ AssertionMode,
9
+ _AssertionPublic,
10
+ _HasSchedule,
11
+ _HasSmartFunctionality,
12
+ )
13
+ from acryl_datahub_cloud.sdk.assertion_input.assertion_input import (
14
+ ASSERTION_MONITOR_DEFAULT_TRAINING_LOOKBACK_WINDOW_DAYS,
15
+ DEFAULT_DETECTION_MECHANISM,
16
+ DEFAULT_SENSITIVITY,
17
+ AssertionIncidentBehavior,
18
+ DetectionMechanism,
19
+ ExclusionWindowTypes,
20
+ InferenceSensitivity,
21
+ _DetectionMechanismTypes,
22
+ )
23
+ from acryl_datahub_cloud.sdk.entities.assertion import Assertion
24
+ from acryl_datahub_cloud.sdk.entities.monitor import Monitor
25
+ from acryl_datahub_cloud.sdk.errors import SDKNotYetSupportedError
26
+ from datahub.metadata import schema_classes as models
27
+ from datahub.metadata.urns import AssertionUrn, CorpUserUrn, DatasetUrn, TagUrn
28
+
29
+ logger = logging.getLogger(__name__)
30
+
31
+
32
+ class SmartVolumeAssertion(_HasSchedule, _HasSmartFunctionality, _AssertionPublic):
33
+ """
34
+ A class that represents a smart volume assertion.
35
+ """
36
+
37
+ def __init__(
38
+ self,
39
+ *,
40
+ urn: AssertionUrn,
41
+ dataset_urn: DatasetUrn,
42
+ display_name: str,
43
+ mode: AssertionMode,
44
+ schedule: models.CronScheduleClass,
45
+ sensitivity: InferenceSensitivity = DEFAULT_SENSITIVITY,
46
+ exclusion_windows: list[ExclusionWindowTypes],
47
+ training_data_lookback_days: int = ASSERTION_MONITOR_DEFAULT_TRAINING_LOOKBACK_WINDOW_DAYS,
48
+ incident_behavior: list[AssertionIncidentBehavior],
49
+ detection_mechanism: Optional[
50
+ _DetectionMechanismTypes
51
+ ] = DEFAULT_DETECTION_MECHANISM,
52
+ tags: list[TagUrn],
53
+ created_by: Optional[CorpUserUrn] = None,
54
+ created_at: Union[datetime, None] = None,
55
+ updated_by: Optional[CorpUserUrn] = None,
56
+ updated_at: Optional[datetime] = None,
57
+ ):
58
+ """
59
+ Initialize a smart volume assertion.
60
+
61
+ Note: Values can be accessed, but not set on the assertion object.
62
+ To update an assertion, use the `upsert_*` method.
63
+ Args:
64
+ urn: The urn of the assertion.
65
+ dataset_urn: The urn of the dataset that the assertion is for.
66
+ display_name: The display name of the assertion.
67
+ mode: The mode of the assertion (active, inactive).
68
+ schedule: The schedule of the assertion.
69
+ sensitivity: The sensitivity of the assertion (low, medium, high).
70
+ exclusion_windows: The exclusion windows of the assertion.
71
+ training_data_lookback_days: The max number of days of data to use for training the assertion.
72
+ incident_behavior: Whether to raise or resolve an incident when the assertion fails / passes.
73
+ detection_mechanism: The detection mechanism of the assertion.
74
+ tags: The tags applied to the assertion.
75
+ created_by: The urn of the user that created the assertion.
76
+ created_at: The timestamp of when the assertion was created.
77
+ updated_by: The urn of the user that updated the assertion.
78
+ updated_at: The timestamp of when the assertion was updated.
79
+ """
80
+ # Initialize the mixins first
81
+ _HasSchedule.__init__(self, schedule=schedule)
82
+ _HasSmartFunctionality.__init__(
83
+ self,
84
+ sensitivity=sensitivity,
85
+ exclusion_windows=exclusion_windows,
86
+ training_data_lookback_days=training_data_lookback_days,
87
+ )
88
+ # Then initialize the parent class
89
+ _AssertionPublic.__init__(
90
+ self,
91
+ urn=urn,
92
+ dataset_urn=dataset_urn,
93
+ display_name=display_name,
94
+ mode=mode,
95
+ incident_behavior=incident_behavior,
96
+ detection_mechanism=detection_mechanism,
97
+ created_by=created_by,
98
+ created_at=created_at,
99
+ updated_by=updated_by,
100
+ updated_at=updated_at,
101
+ tags=tags,
102
+ )
103
+
104
+ @classmethod
105
+ def _from_entities(cls, assertion: Assertion, monitor: Monitor) -> Self:
106
+ """
107
+ Create a smart freshness assertion from the assertion and monitor entities.
108
+
109
+ Note: This is a private method since it is intended to be called internally by the client.
110
+ """
111
+ return cls(
112
+ urn=assertion.urn,
113
+ dataset_urn=assertion.dataset,
114
+ display_name=assertion.description or "",
115
+ mode=cls._get_mode(monitor),
116
+ schedule=cls._get_schedule(monitor),
117
+ sensitivity=cls._get_sensitivity(monitor),
118
+ exclusion_windows=cls._get_exclusion_windows(monitor),
119
+ training_data_lookback_days=cls._get_training_data_lookback_days(monitor),
120
+ incident_behavior=cls._get_incident_behavior(assertion),
121
+ detection_mechanism=cls._get_detection_mechanism(assertion, monitor),
122
+ created_by=cls._get_created_by(assertion),
123
+ created_at=cls._get_created_at(assertion),
124
+ updated_by=cls._get_updated_by(assertion),
125
+ updated_at=cls._get_updated_at(assertion),
126
+ tags=cls._get_tags(assertion),
127
+ )
128
+
129
+ @staticmethod
130
+ def _get_detection_mechanism(
131
+ assertion: Assertion,
132
+ monitor: Monitor,
133
+ default: Optional[_DetectionMechanismTypes] = DEFAULT_DETECTION_MECHANISM,
134
+ ) -> Optional[_DetectionMechanismTypes]:
135
+ """Get the detection mechanism for volume assertions."""
136
+ parameters = _AssertionPublic._get_validated_detection_context(
137
+ monitor,
138
+ assertion,
139
+ models.AssertionEvaluationParametersTypeClass.DATASET_VOLUME,
140
+ models.VolumeAssertionInfoClass,
141
+ default,
142
+ )
143
+ if parameters is None:
144
+ return default
145
+ if parameters.datasetVolumeParameters is None:
146
+ logger.warning(
147
+ f"Monitor does not have datasetVolumeParameters, defaulting detection mechanism to {DEFAULT_DETECTION_MECHANISM}"
148
+ )
149
+ if default is None:
150
+ return DEFAULT_DETECTION_MECHANISM
151
+ else:
152
+ return default
153
+ source_type = parameters.datasetVolumeParameters.sourceType
154
+ if source_type == models.DatasetVolumeSourceTypeClass.INFORMATION_SCHEMA:
155
+ return DetectionMechanism.INFORMATION_SCHEMA
156
+ elif source_type == models.DatasetVolumeSourceTypeClass.QUERY:
157
+ additional_filter = _AssertionPublic._get_additional_filter(assertion)
158
+ return DetectionMechanism.QUERY(additional_filter=additional_filter)
159
+ elif source_type == models.DatasetVolumeSourceTypeClass.DATAHUB_DATASET_PROFILE:
160
+ return DetectionMechanism.DATASET_PROFILE
161
+ else:
162
+ raise SDKNotYetSupportedError(f"DatasetVolumeSourceType {source_type}")