acryl-datahub-cloud 0.3.11rc0__py3-none-any.whl → 0.3.16.1rc0__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.
- acryl_datahub_cloud/_codegen_config.json +1 -1
- acryl_datahub_cloud/acryl_cs_issues/models.py +5 -3
- acryl_datahub_cloud/action_request/action_request_owner_source.py +36 -6
- acryl_datahub_cloud/datahub_forms_notifications/__init__.py +0 -0
- acryl_datahub_cloud/datahub_forms_notifications/forms_notifications_source.py +569 -0
- acryl_datahub_cloud/datahub_forms_notifications/get_feature_flag.gql +7 -0
- acryl_datahub_cloud/datahub_forms_notifications/get_search_results_total.gql +14 -0
- acryl_datahub_cloud/datahub_forms_notifications/query.py +17 -0
- acryl_datahub_cloud/datahub_forms_notifications/scroll_forms_for_notification.gql +29 -0
- acryl_datahub_cloud/datahub_forms_notifications/send_form_notification_request.gql +5 -0
- acryl_datahub_cloud/datahub_reporting/datahub_dataset.py +37 -13
- acryl_datahub_cloud/datahub_reporting/datahub_form_reporting.py +55 -24
- acryl_datahub_cloud/datahub_reporting/extract_graph.py +4 -3
- acryl_datahub_cloud/datahub_reporting/extract_sql.py +242 -51
- acryl_datahub_cloud/datahub_reporting/forms.py +1 -1
- acryl_datahub_cloud/datahub_reporting/forms_config.py +3 -2
- acryl_datahub_cloud/datahub_restore/source.py +3 -2
- acryl_datahub_cloud/datahub_usage_reporting/excluded.py +94 -0
- acryl_datahub_cloud/datahub_usage_reporting/query_builder.py +48 -8
- acryl_datahub_cloud/datahub_usage_reporting/usage_feature_reporter.py +518 -77
- acryl_datahub_cloud/elasticsearch/graph_service.py +76 -14
- acryl_datahub_cloud/graphql_utils.py +64 -0
- acryl_datahub_cloud/lineage_features/source.py +555 -49
- acryl_datahub_cloud/metadata/_urns/urn_defs.py +2296 -1900
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/actionworkflow/__init__.py +53 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/anomaly/__init__.py +2 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/application/__init__.py +19 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/assertion/__init__.py +4 -2
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/common/__init__.py +6 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/conversation/__init__.py +29 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/event/notification/settings/__init__.py +2 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/execution/__init__.py +2 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/file/__init__.py +19 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/form/__init__.py +8 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/identity/__init__.py +8 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/knowledge/__init__.py +33 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/logical/__init__.py +15 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/metadata/key/__init__.py +12 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/metadata/search/features/__init__.py +2 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/module/__init__.py +31 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/notification/__init__.py +19 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/platform/event/v1/__init__.py +4 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/role/__init__.py +2 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/settings/asset/__init__.py +19 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/settings/global/__init__.py +28 -0
- acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/template/__init__.py +31 -0
- acryl_datahub_cloud/metadata/schema.avsc +25091 -20557
- acryl_datahub_cloud/metadata/schema_classes.py +29269 -23863
- acryl_datahub_cloud/metadata/schemas/ActionRequestInfo.avsc +235 -2
- acryl_datahub_cloud/metadata/schemas/ActionWorkflowInfo.avsc +683 -0
- acryl_datahub_cloud/metadata/schemas/ActionWorkflowKey.avsc +21 -0
- acryl_datahub_cloud/metadata/schemas/Actors.avsc +38 -1
- acryl_datahub_cloud/metadata/schemas/ApplicationKey.avsc +31 -0
- acryl_datahub_cloud/metadata/schemas/ApplicationProperties.avsc +75 -0
- acryl_datahub_cloud/metadata/schemas/Applications.avsc +38 -0
- acryl_datahub_cloud/metadata/schemas/AssertionAnalyticsRunEvent.avsc +353 -215
- acryl_datahub_cloud/metadata/schemas/AssertionInfo.avsc +147 -20
- acryl_datahub_cloud/metadata/schemas/AssertionKey.avsc +1 -1
- acryl_datahub_cloud/metadata/schemas/AssertionRunEvent.avsc +166 -21
- acryl_datahub_cloud/metadata/schemas/{AssertionSummary.avsc → AssertionRunSummary.avsc} +15 -2
- acryl_datahub_cloud/metadata/schemas/AssertionsSummary.avsc +54 -0
- acryl_datahub_cloud/metadata/schemas/AssetSettings.avsc +63 -0
- acryl_datahub_cloud/metadata/schemas/BusinessAttributeInfo.avsc +7 -3
- acryl_datahub_cloud/metadata/schemas/ChartInfo.avsc +20 -6
- acryl_datahub_cloud/metadata/schemas/ChartKey.avsc +1 -0
- acryl_datahub_cloud/metadata/schemas/ConstraintInfo.avsc +12 -1
- acryl_datahub_cloud/metadata/schemas/ContainerKey.avsc +1 -0
- acryl_datahub_cloud/metadata/schemas/ContainerProperties.avsc +16 -5
- acryl_datahub_cloud/metadata/schemas/CorpGroupEditableInfo.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/CorpGroupInfo.avsc +7 -3
- acryl_datahub_cloud/metadata/schemas/CorpGroupKey.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/CorpGroupSettings.avsc +127 -2
- acryl_datahub_cloud/metadata/schemas/CorpUserEditableInfo.avsc +1 -1
- acryl_datahub_cloud/metadata/schemas/CorpUserInfo.avsc +18 -2
- acryl_datahub_cloud/metadata/schemas/CorpUserInvitationStatus.avsc +106 -0
- acryl_datahub_cloud/metadata/schemas/CorpUserKey.avsc +4 -1
- acryl_datahub_cloud/metadata/schemas/CorpUserSettings.avsc +304 -2
- acryl_datahub_cloud/metadata/schemas/CorpUserUsageFeatures.avsc +86 -0
- acryl_datahub_cloud/metadata/schemas/DashboardInfo.avsc +11 -5
- acryl_datahub_cloud/metadata/schemas/DashboardKey.avsc +1 -0
- acryl_datahub_cloud/metadata/schemas/DataFlowInfo.avsc +15 -5
- acryl_datahub_cloud/metadata/schemas/DataFlowKey.avsc +1 -0
- acryl_datahub_cloud/metadata/schemas/DataHubAiConversationInfo.avsc +256 -0
- acryl_datahub_cloud/metadata/schemas/DataHubAiConversationKey.avsc +22 -0
- acryl_datahub_cloud/metadata/schemas/DataHubFileInfo.avsc +234 -0
- acryl_datahub_cloud/metadata/schemas/DataHubFileKey.avsc +22 -0
- acryl_datahub_cloud/metadata/schemas/DataHubIngestionSourceKey.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/DataHubPageModuleKey.avsc +21 -0
- acryl_datahub_cloud/metadata/schemas/DataHubPageModuleProperties.avsc +308 -0
- acryl_datahub_cloud/metadata/schemas/DataHubPageTemplateKey.avsc +21 -0
- acryl_datahub_cloud/metadata/schemas/DataHubPageTemplateProperties.avsc +251 -0
- acryl_datahub_cloud/metadata/schemas/DataHubPolicyInfo.avsc +12 -1
- acryl_datahub_cloud/metadata/schemas/DataJobInfo.avsc +13 -4
- acryl_datahub_cloud/metadata/schemas/DataJobInputOutput.avsc +8 -0
- acryl_datahub_cloud/metadata/schemas/DataJobKey.avsc +1 -0
- acryl_datahub_cloud/metadata/schemas/DataPlatformInfo.avsc +3 -1
- acryl_datahub_cloud/metadata/schemas/DataPlatformInstanceProperties.avsc +5 -2
- acryl_datahub_cloud/metadata/schemas/DataProcessKey.avsc +4 -0
- acryl_datahub_cloud/metadata/schemas/DataProductKey.avsc +2 -0
- acryl_datahub_cloud/metadata/schemas/DataProductProperties.avsc +6 -3
- acryl_datahub_cloud/metadata/schemas/DataTypeInfo.avsc +5 -0
- acryl_datahub_cloud/metadata/schemas/DatasetKey.avsc +10 -2
- acryl_datahub_cloud/metadata/schemas/DatasetProperties.avsc +12 -5
- acryl_datahub_cloud/metadata/schemas/DatasetUsageStatistics.avsc +8 -0
- acryl_datahub_cloud/metadata/schemas/DocumentInfo.avsc +407 -0
- acryl_datahub_cloud/metadata/schemas/DocumentKey.avsc +35 -0
- acryl_datahub_cloud/metadata/schemas/DocumentSettings.avsc +79 -0
- acryl_datahub_cloud/metadata/schemas/DomainKey.avsc +2 -0
- acryl_datahub_cloud/metadata/schemas/DomainProperties.avsc +7 -3
- acryl_datahub_cloud/metadata/schemas/EditableContainerProperties.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/EditableDashboardProperties.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/EditableDataFlowProperties.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/EditableDataJobProperties.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/EditableDatasetProperties.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/EditableERModelRelationshipProperties.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/EditableMLFeatureProperties.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/EditableMLFeatureTableProperties.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/EditableMLModelGroupProperties.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/EditableMLModelProperties.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/EditableNotebookProperties.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/EditableSchemaMetadata.avsc +4 -2
- acryl_datahub_cloud/metadata/schemas/EntityTypeInfo.avsc +5 -0
- acryl_datahub_cloud/metadata/schemas/ExecutionRequestArtifactsLocation.avsc +16 -0
- acryl_datahub_cloud/metadata/schemas/ExecutionRequestKey.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/FormAssignmentStatus.avsc +36 -0
- acryl_datahub_cloud/metadata/schemas/FormInfo.avsc +6 -0
- acryl_datahub_cloud/metadata/schemas/FormKey.avsc +3 -1
- acryl_datahub_cloud/metadata/schemas/FormNotifications.avsc +69 -0
- acryl_datahub_cloud/metadata/schemas/FormSettings.avsc +30 -0
- acryl_datahub_cloud/metadata/schemas/GlobalSettingsInfo.avsc +416 -0
- acryl_datahub_cloud/metadata/schemas/GlobalTags.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/GlossaryNodeInfo.avsc +3 -1
- acryl_datahub_cloud/metadata/schemas/GlossaryNodeKey.avsc +1 -0
- acryl_datahub_cloud/metadata/schemas/GlossaryTermInfo.avsc +3 -1
- acryl_datahub_cloud/metadata/schemas/GlossaryTermKey.avsc +2 -0
- acryl_datahub_cloud/metadata/schemas/IcebergWarehouseInfo.avsc +4 -0
- acryl_datahub_cloud/metadata/schemas/IncidentActivityEvent.avsc +3 -3
- acryl_datahub_cloud/metadata/schemas/IncidentInfo.avsc +3 -3
- acryl_datahub_cloud/metadata/schemas/InferredMetadata.avsc +71 -1
- acryl_datahub_cloud/metadata/schemas/InputFields.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/InviteToken.avsc +26 -0
- acryl_datahub_cloud/metadata/schemas/LineageFeatures.avsc +67 -42
- acryl_datahub_cloud/metadata/schemas/LogicalParent.avsc +145 -0
- acryl_datahub_cloud/metadata/schemas/MLFeatureKey.avsc +4 -1
- acryl_datahub_cloud/metadata/schemas/MLFeatureTableKey.avsc +4 -1
- acryl_datahub_cloud/metadata/schemas/MLModelDeploymentKey.avsc +7 -1
- acryl_datahub_cloud/metadata/schemas/MLModelGroupKey.avsc +9 -1
- acryl_datahub_cloud/metadata/schemas/MLModelKey.avsc +9 -1
- acryl_datahub_cloud/metadata/schemas/MLModelProperties.avsc +4 -2
- acryl_datahub_cloud/metadata/schemas/MLPrimaryKeyKey.avsc +4 -1
- acryl_datahub_cloud/metadata/schemas/MetadataChangeEvent.avsc +418 -97
- acryl_datahub_cloud/metadata/schemas/MetadataChangeLog.avsc +62 -44
- acryl_datahub_cloud/metadata/schemas/MetadataChangeProposal.avsc +61 -0
- acryl_datahub_cloud/metadata/schemas/MonitorAnomalyEvent.avsc +54 -9
- acryl_datahub_cloud/metadata/schemas/MonitorInfo.avsc +163 -23
- acryl_datahub_cloud/metadata/schemas/MonitorKey.avsc +9 -1
- acryl_datahub_cloud/metadata/schemas/MonitorSuiteInfo.avsc +128 -3
- acryl_datahub_cloud/metadata/schemas/NotebookInfo.avsc +5 -2
- acryl_datahub_cloud/metadata/schemas/NotebookKey.avsc +1 -0
- acryl_datahub_cloud/metadata/schemas/NotificationRequest.avsc +91 -4
- acryl_datahub_cloud/metadata/schemas/Operation.avsc +17 -0
- acryl_datahub_cloud/metadata/schemas/Ownership.avsc +71 -1
- acryl_datahub_cloud/metadata/schemas/QuerySubjects.avsc +2 -13
- acryl_datahub_cloud/metadata/schemas/RelationshipChangeEvent.avsc +215 -0
- acryl_datahub_cloud/metadata/schemas/RoleProperties.avsc +3 -1
- acryl_datahub_cloud/metadata/schemas/SchemaFieldInfo.avsc +3 -1
- acryl_datahub_cloud/metadata/schemas/SchemaFieldKey.avsc +3 -0
- acryl_datahub_cloud/metadata/schemas/SchemaMetadata.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/SemanticContent.avsc +123 -0
- acryl_datahub_cloud/metadata/schemas/StructuredProperties.avsc +69 -0
- acryl_datahub_cloud/metadata/schemas/StructuredPropertyDefinition.avsc +15 -4
- acryl_datahub_cloud/metadata/schemas/StructuredPropertySettings.avsc +9 -0
- acryl_datahub_cloud/metadata/schemas/SubscriptionInfo.avsc +136 -5
- acryl_datahub_cloud/metadata/schemas/SubscriptionKey.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/SystemMetadata.avsc +61 -0
- acryl_datahub_cloud/metadata/schemas/TagProperties.avsc +3 -1
- acryl_datahub_cloud/metadata/schemas/TestInfo.avsc +2 -1
- acryl_datahub_cloud/metadata/schemas/UpstreamLineage.avsc +9 -0
- acryl_datahub_cloud/metadata/schemas/UsageFeatures.avsc +10 -0
- acryl_datahub_cloud/notifications/__init__.py +0 -0
- acryl_datahub_cloud/notifications/notification_recipient_builder.py +399 -0
- acryl_datahub_cloud/sdk/__init__.py +69 -0
- acryl_datahub_cloud/sdk/assertion/__init__.py +58 -0
- acryl_datahub_cloud/sdk/assertion/assertion_base.py +779 -0
- acryl_datahub_cloud/sdk/assertion/column_metric_assertion.py +191 -0
- acryl_datahub_cloud/sdk/assertion/column_value_assertion.py +431 -0
- acryl_datahub_cloud/sdk/assertion/freshness_assertion.py +201 -0
- acryl_datahub_cloud/sdk/assertion/schema_assertion.py +268 -0
- acryl_datahub_cloud/sdk/assertion/smart_column_metric_assertion.py +212 -0
- acryl_datahub_cloud/sdk/assertion/smart_freshness_assertion.py +165 -0
- acryl_datahub_cloud/sdk/assertion/smart_sql_assertion.py +156 -0
- acryl_datahub_cloud/sdk/assertion/smart_volume_assertion.py +162 -0
- acryl_datahub_cloud/sdk/assertion/sql_assertion.py +273 -0
- acryl_datahub_cloud/sdk/assertion/types.py +20 -0
- acryl_datahub_cloud/sdk/assertion/volume_assertion.py +156 -0
- acryl_datahub_cloud/sdk/assertion_client/__init__.py +0 -0
- acryl_datahub_cloud/sdk/assertion_client/column_metric.py +545 -0
- acryl_datahub_cloud/sdk/assertion_client/column_value.py +617 -0
- acryl_datahub_cloud/sdk/assertion_client/freshness.py +371 -0
- acryl_datahub_cloud/sdk/assertion_client/helpers.py +166 -0
- acryl_datahub_cloud/sdk/assertion_client/schema.py +358 -0
- acryl_datahub_cloud/sdk/assertion_client/smart_column_metric.py +540 -0
- acryl_datahub_cloud/sdk/assertion_client/smart_freshness.py +373 -0
- acryl_datahub_cloud/sdk/assertion_client/smart_sql.py +411 -0
- acryl_datahub_cloud/sdk/assertion_client/smart_volume.py +380 -0
- acryl_datahub_cloud/sdk/assertion_client/sql.py +410 -0
- acryl_datahub_cloud/sdk/assertion_client/volume.py +446 -0
- acryl_datahub_cloud/sdk/assertion_input/__init__.py +0 -0
- acryl_datahub_cloud/sdk/assertion_input/assertion_input.py +1470 -0
- acryl_datahub_cloud/sdk/assertion_input/column_assertion_constants.py +114 -0
- acryl_datahub_cloud/sdk/assertion_input/column_assertion_utils.py +284 -0
- acryl_datahub_cloud/sdk/assertion_input/column_metric_assertion_input.py +759 -0
- acryl_datahub_cloud/sdk/assertion_input/column_metric_constants.py +109 -0
- acryl_datahub_cloud/sdk/assertion_input/column_value_assertion_input.py +810 -0
- acryl_datahub_cloud/sdk/assertion_input/freshness_assertion_input.py +305 -0
- acryl_datahub_cloud/sdk/assertion_input/schema_assertion_input.py +413 -0
- acryl_datahub_cloud/sdk/assertion_input/smart_column_metric_assertion_input.py +793 -0
- acryl_datahub_cloud/sdk/assertion_input/smart_freshness_assertion_input.py +218 -0
- acryl_datahub_cloud/sdk/assertion_input/smart_sql_assertion_input.py +181 -0
- acryl_datahub_cloud/sdk/assertion_input/smart_volume_assertion_input.py +189 -0
- acryl_datahub_cloud/sdk/assertion_input/sql_assertion_input.py +320 -0
- acryl_datahub_cloud/sdk/assertion_input/volume_assertion_input.py +635 -0
- acryl_datahub_cloud/sdk/assertions_client.py +1074 -0
- acryl_datahub_cloud/sdk/entities/__init__.py +0 -0
- acryl_datahub_cloud/sdk/entities/assertion.py +439 -0
- acryl_datahub_cloud/sdk/entities/monitor.py +291 -0
- acryl_datahub_cloud/sdk/entities/subscription.py +100 -0
- acryl_datahub_cloud/sdk/errors.py +34 -0
- acryl_datahub_cloud/sdk/resolver_client.py +42 -0
- acryl_datahub_cloud/sdk/subscription_client.py +737 -0
- {acryl_datahub_cloud-0.3.11rc0.dist-info → acryl_datahub_cloud-0.3.16.1rc0.dist-info}/METADATA +55 -49
- {acryl_datahub_cloud-0.3.11rc0.dist-info → acryl_datahub_cloud-0.3.16.1rc0.dist-info}/RECORD +235 -142
- {acryl_datahub_cloud-0.3.11rc0.dist-info → acryl_datahub_cloud-0.3.16.1rc0.dist-info}/WHEEL +1 -1
- {acryl_datahub_cloud-0.3.11rc0.dist-info → acryl_datahub_cloud-0.3.16.1rc0.dist-info}/entry_points.txt +1 -0
- acryl_datahub_cloud/_sdk_extras/__init__.py +0 -4
- acryl_datahub_cloud/_sdk_extras/assertion.py +0 -15
- acryl_datahub_cloud/_sdk_extras/assertions_client.py +0 -23
- {acryl_datahub_cloud-0.3.11rc0.dist-info → acryl_datahub_cloud-0.3.16.1rc0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,779 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module contains the base classes and mixins for assertions.
|
|
3
|
+
|
|
4
|
+
The actual assertion classes are now split into separate files for better maintainability:
|
|
5
|
+
- SmartFreshnessAssertion -> smart_freshness_assertion.py
|
|
6
|
+
- SmartSqlAssertion -> smart_sql_assertion.py
|
|
7
|
+
- SmartVolumeAssertion -> smart_volume_assertion.py
|
|
8
|
+
- VolumeAssertion -> volume_assertion.py
|
|
9
|
+
- FreshnessAssertion -> freshness_assertion.py
|
|
10
|
+
- SqlAssertion -> sql_assertion.py
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import logging
|
|
14
|
+
from abc import ABC, abstractmethod
|
|
15
|
+
from datetime import datetime
|
|
16
|
+
from enum import Enum
|
|
17
|
+
from typing import TYPE_CHECKING, Optional, Union
|
|
18
|
+
|
|
19
|
+
from typing_extensions import Self
|
|
20
|
+
|
|
21
|
+
from acryl_datahub_cloud.sdk.assertion_input.assertion_input import (
|
|
22
|
+
ASSERTION_MONITOR_DEFAULT_TRAINING_LOOKBACK_WINDOW_DAYS,
|
|
23
|
+
DEFAULT_DETECTION_MECHANISM,
|
|
24
|
+
DEFAULT_SCHEDULE,
|
|
25
|
+
DEFAULT_SENSITIVITY,
|
|
26
|
+
AssertionIncidentBehavior,
|
|
27
|
+
DetectionMechanism,
|
|
28
|
+
ExclusionWindowTypes,
|
|
29
|
+
FixedRangeExclusionWindow,
|
|
30
|
+
InferenceSensitivity,
|
|
31
|
+
_DetectionMechanismTypes,
|
|
32
|
+
)
|
|
33
|
+
from acryl_datahub_cloud.sdk.assertion_input.column_metric_constants import (
|
|
34
|
+
MetricInputType,
|
|
35
|
+
OperatorInputType,
|
|
36
|
+
)
|
|
37
|
+
from acryl_datahub_cloud.sdk.assertion_input.smart_column_metric_assertion_input import (
|
|
38
|
+
SmartColumnMetricAssertionParameters,
|
|
39
|
+
)
|
|
40
|
+
from acryl_datahub_cloud.sdk.entities.assertion import Assertion
|
|
41
|
+
from acryl_datahub_cloud.sdk.entities.monitor import (
|
|
42
|
+
Monitor,
|
|
43
|
+
_get_nested_field_for_entity_with_default,
|
|
44
|
+
)
|
|
45
|
+
from acryl_datahub_cloud.sdk.errors import SDKNotYetSupportedError, SDKUsageError
|
|
46
|
+
from datahub.emitter.mce_builder import parse_ts_millis
|
|
47
|
+
from datahub.metadata import schema_classes as models
|
|
48
|
+
from datahub.metadata.urns import AssertionUrn, CorpUserUrn, DatasetUrn, TagUrn
|
|
49
|
+
|
|
50
|
+
logger = logging.getLogger(__name__)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class AssertionMode(Enum):
|
|
54
|
+
"""
|
|
55
|
+
The mode of an assertion, e.g. whether it is active or inactive.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
# Note: Modeled here after MonitorStatus but called AssertionMode in this user facing interface
|
|
59
|
+
# to keep all naming related to assertions.
|
|
60
|
+
ACTIVE = "ACTIVE"
|
|
61
|
+
INACTIVE = "INACTIVE"
|
|
62
|
+
# PASSIVE = "PASSIVE" # Not supported in the user facing interface.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class _HasSchedule:
|
|
66
|
+
"""
|
|
67
|
+
Mixin class that provides schedule functionality for assertions.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
def __init__(self, schedule: models.CronScheduleClass) -> None:
|
|
71
|
+
self._schedule = schedule
|
|
72
|
+
|
|
73
|
+
@property
|
|
74
|
+
def schedule(self) -> models.CronScheduleClass:
|
|
75
|
+
return self._schedule
|
|
76
|
+
|
|
77
|
+
@staticmethod
|
|
78
|
+
def _get_schedule(
|
|
79
|
+
monitor: Monitor, default: models.CronScheduleClass = DEFAULT_SCHEDULE
|
|
80
|
+
) -> models.CronScheduleClass:
|
|
81
|
+
"""Get the schedule from the monitor."""
|
|
82
|
+
assertion_evaluation_specs = _get_nested_field_for_entity_with_default(
|
|
83
|
+
monitor,
|
|
84
|
+
"info.assertionMonitor.assertions",
|
|
85
|
+
[],
|
|
86
|
+
)
|
|
87
|
+
if len(assertion_evaluation_specs) == 0:
|
|
88
|
+
return default
|
|
89
|
+
assertion_evaluation_spec = assertion_evaluation_specs[0]
|
|
90
|
+
schedule = assertion_evaluation_spec.schedule
|
|
91
|
+
if schedule is None:
|
|
92
|
+
return default
|
|
93
|
+
return schedule
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class _HasSmartFunctionality:
|
|
97
|
+
"""
|
|
98
|
+
Mixin class that provides smart functionality for assertions.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
def __init__(
|
|
102
|
+
self,
|
|
103
|
+
*,
|
|
104
|
+
sensitivity: InferenceSensitivity = DEFAULT_SENSITIVITY,
|
|
105
|
+
exclusion_windows: list[ExclusionWindowTypes],
|
|
106
|
+
training_data_lookback_days: int = ASSERTION_MONITOR_DEFAULT_TRAINING_LOOKBACK_WINDOW_DAYS,
|
|
107
|
+
) -> None:
|
|
108
|
+
"""
|
|
109
|
+
Initialize the smart functionality mixin.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
sensitivity: The sensitivity of the assertion (low, medium, high).
|
|
113
|
+
exclusion_windows: The exclusion windows of the assertion.
|
|
114
|
+
training_data_lookback_days: The max number of days of data to use for training the assertion.
|
|
115
|
+
incident_behavior: Whether to raise or resolve an incident when the assertion fails / passes.
|
|
116
|
+
detection_mechanism: The detection mechanism of the assertion.
|
|
117
|
+
**kwargs: Additional arguments to pass to the parent class (_Assertion).
|
|
118
|
+
"""
|
|
119
|
+
self._sensitivity = sensitivity
|
|
120
|
+
self._exclusion_windows = exclusion_windows
|
|
121
|
+
self._training_data_lookback_days = training_data_lookback_days
|
|
122
|
+
|
|
123
|
+
@property
|
|
124
|
+
def sensitivity(self) -> InferenceSensitivity:
|
|
125
|
+
return self._sensitivity
|
|
126
|
+
|
|
127
|
+
@property
|
|
128
|
+
def exclusion_windows(self) -> list[ExclusionWindowTypes]:
|
|
129
|
+
return self._exclusion_windows
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def training_data_lookback_days(self) -> int:
|
|
133
|
+
return self._training_data_lookback_days
|
|
134
|
+
|
|
135
|
+
@staticmethod
|
|
136
|
+
def _get_sensitivity(monitor: Monitor) -> InferenceSensitivity:
|
|
137
|
+
# 1. Check if the monitor has a sensitivity field
|
|
138
|
+
raw_sensitivity = _get_nested_field_for_entity_with_default(
|
|
139
|
+
monitor,
|
|
140
|
+
"info.assertionMonitor.settings.adjustmentSettings.sensitivity.level",
|
|
141
|
+
DEFAULT_SENSITIVITY,
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
# 2. Convert the raw sensitivity to the SDK sensitivity enum (1-3: LOW, 4-6: MEDIUM, 7-10: HIGH)
|
|
145
|
+
return InferenceSensitivity.parse(raw_sensitivity)
|
|
146
|
+
|
|
147
|
+
@staticmethod
|
|
148
|
+
def _get_exclusion_windows(monitor: Monitor) -> list[ExclusionWindowTypes]:
|
|
149
|
+
# 1. Check if the monitor has an exclusion windows field
|
|
150
|
+
raw_windows = monitor.exclusion_windows or []
|
|
151
|
+
|
|
152
|
+
# 2. Convert the raw exclusion windows to the SDK exclusion windows
|
|
153
|
+
exclusion_windows = []
|
|
154
|
+
for raw_window in raw_windows:
|
|
155
|
+
if raw_window.type == models.AssertionExclusionWindowTypeClass.FIXED_RANGE:
|
|
156
|
+
if raw_window.fixedRange is None:
|
|
157
|
+
logger.warning(
|
|
158
|
+
f"Monitor {monitor.urn} has a fixed range exclusion window with no fixed range, skipping"
|
|
159
|
+
)
|
|
160
|
+
continue
|
|
161
|
+
exclusion_windows.append(
|
|
162
|
+
FixedRangeExclusionWindow(
|
|
163
|
+
start=parse_ts_millis(raw_window.fixedRange.startTimeMillis),
|
|
164
|
+
end=parse_ts_millis(raw_window.fixedRange.endTimeMillis),
|
|
165
|
+
)
|
|
166
|
+
)
|
|
167
|
+
else:
|
|
168
|
+
raise SDKNotYetSupportedError(
|
|
169
|
+
f"AssertionExclusionWindowType {raw_window.type}"
|
|
170
|
+
)
|
|
171
|
+
return exclusion_windows
|
|
172
|
+
|
|
173
|
+
@staticmethod
|
|
174
|
+
def _get_training_data_lookback_days(monitor: Monitor) -> int:
|
|
175
|
+
retrieved = monitor.training_data_lookback_days
|
|
176
|
+
if (
|
|
177
|
+
retrieved is None
|
|
178
|
+
): # Explicitly check for None since retrieved can be 0 which is falsy
|
|
179
|
+
return ASSERTION_MONITOR_DEFAULT_TRAINING_LOOKBACK_WINDOW_DAYS
|
|
180
|
+
assert isinstance(retrieved, int)
|
|
181
|
+
return retrieved
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
class _HasColumnMetricFunctionality:
|
|
185
|
+
"""
|
|
186
|
+
Mixin class that provides column metric functionality for assertions.
|
|
187
|
+
"""
|
|
188
|
+
|
|
189
|
+
def __init__(
|
|
190
|
+
self,
|
|
191
|
+
column_name: str,
|
|
192
|
+
metric_type: MetricInputType,
|
|
193
|
+
operator: OperatorInputType,
|
|
194
|
+
criteria_parameters: Optional[SmartColumnMetricAssertionParameters] = None,
|
|
195
|
+
):
|
|
196
|
+
self._column_name = column_name
|
|
197
|
+
self._metric_type = metric_type
|
|
198
|
+
self._operator = operator
|
|
199
|
+
self._criteria_parameters = criteria_parameters
|
|
200
|
+
|
|
201
|
+
@property
|
|
202
|
+
def column_name(self) -> str:
|
|
203
|
+
return self._column_name
|
|
204
|
+
|
|
205
|
+
@property
|
|
206
|
+
def metric_type(self) -> MetricInputType:
|
|
207
|
+
return self._metric_type
|
|
208
|
+
|
|
209
|
+
@property
|
|
210
|
+
def operator(self) -> OperatorInputType:
|
|
211
|
+
return self._operator
|
|
212
|
+
|
|
213
|
+
@property
|
|
214
|
+
def criteria_parameters(self) -> Optional[SmartColumnMetricAssertionParameters]:
|
|
215
|
+
return self._criteria_parameters
|
|
216
|
+
|
|
217
|
+
@staticmethod
|
|
218
|
+
def _get_column_name(assertion: Assertion) -> str:
|
|
219
|
+
column_name = _get_nested_field_for_entity_with_default(
|
|
220
|
+
assertion,
|
|
221
|
+
field_path="info.fieldMetricAssertion.field.path",
|
|
222
|
+
default=None,
|
|
223
|
+
)
|
|
224
|
+
if column_name is None:
|
|
225
|
+
raise SDKUsageError(
|
|
226
|
+
f"Column name is required for column metric assertions. Assertion {assertion.urn} does not have a column name"
|
|
227
|
+
)
|
|
228
|
+
return column_name
|
|
229
|
+
|
|
230
|
+
@staticmethod
|
|
231
|
+
def _get_metric_type(assertion: Assertion) -> MetricInputType:
|
|
232
|
+
metric_type = _get_nested_field_for_entity_with_default(
|
|
233
|
+
assertion,
|
|
234
|
+
field_path="info.fieldMetricAssertion.metric",
|
|
235
|
+
default=None,
|
|
236
|
+
)
|
|
237
|
+
if metric_type is None:
|
|
238
|
+
raise SDKUsageError(
|
|
239
|
+
f"Metric type is required for column metric assertions. Assertion {assertion.urn} does not have a metric type"
|
|
240
|
+
)
|
|
241
|
+
return metric_type
|
|
242
|
+
|
|
243
|
+
@staticmethod
|
|
244
|
+
def _get_operator(assertion: Assertion) -> OperatorInputType:
|
|
245
|
+
operator = _get_nested_field_for_entity_with_default(
|
|
246
|
+
assertion,
|
|
247
|
+
field_path="info.fieldMetricAssertion.operator",
|
|
248
|
+
default=None,
|
|
249
|
+
)
|
|
250
|
+
if operator is None:
|
|
251
|
+
raise SDKUsageError(
|
|
252
|
+
f"Operator is required for column metric assertions. Assertion {assertion.urn} does not have an operator"
|
|
253
|
+
)
|
|
254
|
+
return operator
|
|
255
|
+
|
|
256
|
+
@staticmethod
|
|
257
|
+
def _get_criteria_parameters(
|
|
258
|
+
assertion: Assertion,
|
|
259
|
+
) -> Optional[SmartColumnMetricAssertionParameters]:
|
|
260
|
+
# First check if there's a single value parameter
|
|
261
|
+
value_param = _get_nested_field_for_entity_with_default(
|
|
262
|
+
assertion,
|
|
263
|
+
field_path="info.fieldMetricAssertion.parameters.value",
|
|
264
|
+
default=None,
|
|
265
|
+
)
|
|
266
|
+
if value_param is not None:
|
|
267
|
+
return value_param.value
|
|
268
|
+
|
|
269
|
+
# Then check for range parameters
|
|
270
|
+
min_value = _get_nested_field_for_entity_with_default(
|
|
271
|
+
assertion,
|
|
272
|
+
field_path="info.fieldMetricAssertion.parameters.minValue",
|
|
273
|
+
default=None,
|
|
274
|
+
)
|
|
275
|
+
max_value = _get_nested_field_for_entity_with_default(
|
|
276
|
+
assertion,
|
|
277
|
+
field_path="info.fieldMetricAssertion.parameters.maxValue",
|
|
278
|
+
default=None,
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
# If both range values exist, extract their values and return as tuple
|
|
282
|
+
if min_value is not None and max_value is not None:
|
|
283
|
+
if hasattr(min_value, "value"):
|
|
284
|
+
min_value = min_value.value
|
|
285
|
+
if hasattr(max_value, "value"):
|
|
286
|
+
max_value = max_value.value
|
|
287
|
+
return (min_value, max_value)
|
|
288
|
+
|
|
289
|
+
# If no parameters found, return None
|
|
290
|
+
return None
|
|
291
|
+
|
|
292
|
+
@staticmethod
|
|
293
|
+
def _get_criteria_parameters_with_type(
|
|
294
|
+
assertion: Assertion,
|
|
295
|
+
) -> Optional[tuple]:
|
|
296
|
+
"""
|
|
297
|
+
Get criteria parameters along with their type information from the backend.
|
|
298
|
+
|
|
299
|
+
Returns:
|
|
300
|
+
For single values: (value, type)
|
|
301
|
+
For ranges: ((min_value, max_value), (min_type, max_type))
|
|
302
|
+
None if no parameters found
|
|
303
|
+
"""
|
|
304
|
+
# First check if there's a single value parameter
|
|
305
|
+
value_param = _get_nested_field_for_entity_with_default(
|
|
306
|
+
assertion,
|
|
307
|
+
field_path="info.fieldMetricAssertion.parameters.value",
|
|
308
|
+
default=None,
|
|
309
|
+
)
|
|
310
|
+
if value_param is not None:
|
|
311
|
+
return (value_param.value, value_param.type)
|
|
312
|
+
|
|
313
|
+
# Then check for range parameters
|
|
314
|
+
min_param = _get_nested_field_for_entity_with_default(
|
|
315
|
+
assertion,
|
|
316
|
+
field_path="info.fieldMetricAssertion.parameters.minValue",
|
|
317
|
+
default=None,
|
|
318
|
+
)
|
|
319
|
+
max_param = _get_nested_field_for_entity_with_default(
|
|
320
|
+
assertion,
|
|
321
|
+
field_path="info.fieldMetricAssertion.parameters.maxValue",
|
|
322
|
+
default=None,
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
# If both range parameters exist, return values and types
|
|
326
|
+
if min_param is not None and max_param is not None:
|
|
327
|
+
return (
|
|
328
|
+
(min_param.value, max_param.value),
|
|
329
|
+
(min_param.type, max_param.type),
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
# If no parameters found, return None
|
|
333
|
+
return None
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
class _AssertionPublic(ABC):
|
|
337
|
+
"""
|
|
338
|
+
Abstract base class that represents a public facing assertion and contains the common properties of all assertions.
|
|
339
|
+
"""
|
|
340
|
+
|
|
341
|
+
# TODO: have the individual classes self-declare this
|
|
342
|
+
_SUPPORTED_WITH_FILTER_ASSERTION_TYPES = (
|
|
343
|
+
models.FreshnessAssertionInfoClass,
|
|
344
|
+
models.VolumeAssertionInfoClass,
|
|
345
|
+
models.FieldAssertionInfoClass,
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
def __init__(
|
|
349
|
+
self,
|
|
350
|
+
*,
|
|
351
|
+
urn: AssertionUrn,
|
|
352
|
+
dataset_urn: DatasetUrn,
|
|
353
|
+
display_name: str,
|
|
354
|
+
mode: AssertionMode,
|
|
355
|
+
tags: list[TagUrn],
|
|
356
|
+
incident_behavior: list[AssertionIncidentBehavior],
|
|
357
|
+
detection_mechanism: Optional[
|
|
358
|
+
_DetectionMechanismTypes
|
|
359
|
+
] = DEFAULT_DETECTION_MECHANISM,
|
|
360
|
+
created_by: Optional[CorpUserUrn] = None,
|
|
361
|
+
created_at: Union[datetime, None] = None,
|
|
362
|
+
updated_by: Optional[CorpUserUrn] = None,
|
|
363
|
+
updated_at: Optional[datetime] = None,
|
|
364
|
+
):
|
|
365
|
+
"""
|
|
366
|
+
Initialize the public facing assertion class.
|
|
367
|
+
|
|
368
|
+
Args:
|
|
369
|
+
urn: The urn of the assertion.
|
|
370
|
+
dataset_urn: The urn of the dataset that the assertion is for.
|
|
371
|
+
display_name: The display name of the assertion.
|
|
372
|
+
mode: The mode of the assertion (active, inactive).
|
|
373
|
+
tags: The tags of the assertion.
|
|
374
|
+
created_by: The urn of the user that created the assertion.
|
|
375
|
+
created_at: The timestamp of when the assertion was created.
|
|
376
|
+
updated_by: The urn of the user that updated the assertion.
|
|
377
|
+
updated_at: The timestamp of when the assertion was updated.
|
|
378
|
+
"""
|
|
379
|
+
self._urn = urn
|
|
380
|
+
self._dataset_urn = dataset_urn
|
|
381
|
+
self._display_name = display_name
|
|
382
|
+
self._mode = mode
|
|
383
|
+
self._incident_behavior = incident_behavior
|
|
384
|
+
self._detection_mechanism = detection_mechanism
|
|
385
|
+
self._created_by = created_by
|
|
386
|
+
self._created_at = created_at
|
|
387
|
+
self._updated_by = updated_by
|
|
388
|
+
self._updated_at = updated_at
|
|
389
|
+
self._tags = tags
|
|
390
|
+
|
|
391
|
+
@property
|
|
392
|
+
def urn(self) -> AssertionUrn:
|
|
393
|
+
return self._urn
|
|
394
|
+
|
|
395
|
+
@property
|
|
396
|
+
def dataset_urn(self) -> DatasetUrn:
|
|
397
|
+
return self._dataset_urn
|
|
398
|
+
|
|
399
|
+
@property
|
|
400
|
+
def display_name(self) -> str:
|
|
401
|
+
return self._display_name
|
|
402
|
+
|
|
403
|
+
@property
|
|
404
|
+
def mode(self) -> AssertionMode:
|
|
405
|
+
return self._mode
|
|
406
|
+
|
|
407
|
+
@property
|
|
408
|
+
def incident_behavior(self) -> list[AssertionIncidentBehavior]:
|
|
409
|
+
return self._incident_behavior
|
|
410
|
+
|
|
411
|
+
@property
|
|
412
|
+
def detection_mechanism(self) -> Optional[_DetectionMechanismTypes]:
|
|
413
|
+
return self._detection_mechanism
|
|
414
|
+
|
|
415
|
+
@property
|
|
416
|
+
def created_by(self) -> Optional[CorpUserUrn]:
|
|
417
|
+
return self._created_by
|
|
418
|
+
|
|
419
|
+
@property
|
|
420
|
+
def created_at(self) -> Union[datetime, None]:
|
|
421
|
+
return self._created_at
|
|
422
|
+
|
|
423
|
+
@property
|
|
424
|
+
def updated_by(self) -> Optional[CorpUserUrn]:
|
|
425
|
+
return self._updated_by
|
|
426
|
+
|
|
427
|
+
@property
|
|
428
|
+
def updated_at(self) -> Union[datetime, None]:
|
|
429
|
+
return self._updated_at
|
|
430
|
+
|
|
431
|
+
@property
|
|
432
|
+
def tags(self) -> list[TagUrn]:
|
|
433
|
+
return self._tags
|
|
434
|
+
|
|
435
|
+
@staticmethod
|
|
436
|
+
def _get_incident_behavior(assertion: Assertion) -> list[AssertionIncidentBehavior]:
|
|
437
|
+
incident_behaviors = []
|
|
438
|
+
for action in assertion.on_failure + assertion.on_success:
|
|
439
|
+
if action.type == models.AssertionActionTypeClass.RAISE_INCIDENT:
|
|
440
|
+
incident_behaviors.append(AssertionIncidentBehavior.RAISE_ON_FAIL)
|
|
441
|
+
elif action.type == models.AssertionActionTypeClass.RESOLVE_INCIDENT:
|
|
442
|
+
incident_behaviors.append(AssertionIncidentBehavior.RESOLVE_ON_PASS)
|
|
443
|
+
|
|
444
|
+
return incident_behaviors
|
|
445
|
+
|
|
446
|
+
@staticmethod
|
|
447
|
+
@abstractmethod
|
|
448
|
+
def _get_detection_mechanism(
|
|
449
|
+
assertion: Assertion,
|
|
450
|
+
monitor: Monitor,
|
|
451
|
+
default: Optional[_DetectionMechanismTypes] = DEFAULT_DETECTION_MECHANISM,
|
|
452
|
+
) -> Optional[_DetectionMechanismTypes]:
|
|
453
|
+
"""Get the detection mechanism from the monitor and assertion.
|
|
454
|
+
|
|
455
|
+
This method should be implemented by each assertion class to handle
|
|
456
|
+
its specific detection mechanism logic.
|
|
457
|
+
|
|
458
|
+
Args:
|
|
459
|
+
assertion: The assertion entity
|
|
460
|
+
monitor: The monitor entity
|
|
461
|
+
default: Default detection mechanism to return if none is found
|
|
462
|
+
|
|
463
|
+
Returns:
|
|
464
|
+
The detection mechanism or default if none is found
|
|
465
|
+
"""
|
|
466
|
+
pass
|
|
467
|
+
|
|
468
|
+
@staticmethod
|
|
469
|
+
def _has_valid_monitor_info(monitor: Monitor) -> bool:
|
|
470
|
+
"""Check if monitor has valid info and assertion monitor."""
|
|
471
|
+
|
|
472
|
+
def _warn_and_return_false(field_name: str) -> bool:
|
|
473
|
+
logger.warning(
|
|
474
|
+
f"Monitor {monitor.urn} does not have an `{field_name}` field, defaulting detection mechanism to {DEFAULT_DETECTION_MECHANISM}"
|
|
475
|
+
)
|
|
476
|
+
return False
|
|
477
|
+
|
|
478
|
+
if monitor.info is None:
|
|
479
|
+
return _warn_and_return_false("info")
|
|
480
|
+
if monitor.info.assertionMonitor is None:
|
|
481
|
+
return _warn_and_return_false("assertionMonitor")
|
|
482
|
+
if (
|
|
483
|
+
monitor.info.assertionMonitor.assertions is None
|
|
484
|
+
or len(monitor.info.assertionMonitor.assertions) == 0
|
|
485
|
+
):
|
|
486
|
+
return _warn_and_return_false("assertionMonitor.assertions")
|
|
487
|
+
|
|
488
|
+
return True
|
|
489
|
+
|
|
490
|
+
@staticmethod
|
|
491
|
+
def _get_assertion_parameters(
|
|
492
|
+
monitor: Monitor,
|
|
493
|
+
default: Optional[_DetectionMechanismTypes] = DEFAULT_DETECTION_MECHANISM,
|
|
494
|
+
) -> Optional[models.AssertionEvaluationParametersClass]:
|
|
495
|
+
"""Get the assertion parameters from the monitor."""
|
|
496
|
+
# We know these are not None from _has_valid_monitor_info check
|
|
497
|
+
assert (
|
|
498
|
+
monitor is not None
|
|
499
|
+
and monitor.info is not None
|
|
500
|
+
and monitor.info.assertionMonitor is not None
|
|
501
|
+
)
|
|
502
|
+
assertion_monitor = monitor.info.assertionMonitor
|
|
503
|
+
assert (
|
|
504
|
+
assertion_monitor is not None and assertion_monitor.assertions is not None
|
|
505
|
+
)
|
|
506
|
+
assertions = assertion_monitor.assertions
|
|
507
|
+
|
|
508
|
+
if assertions[0].parameters is None:
|
|
509
|
+
logger.warning(
|
|
510
|
+
f"Monitor {monitor.urn} does not have a assertionMonitor.assertions[0].parameters, defaulting detection mechanism to {default}"
|
|
511
|
+
)
|
|
512
|
+
return None
|
|
513
|
+
return assertions[0].parameters
|
|
514
|
+
|
|
515
|
+
@staticmethod
|
|
516
|
+
def _get_created_by(assertion: Assertion) -> Optional[CorpUserUrn]:
|
|
517
|
+
if assertion.source is None:
|
|
518
|
+
logger.warning(f"Assertion {assertion.urn} does not have a source")
|
|
519
|
+
return None
|
|
520
|
+
if isinstance(assertion.source, models.AssertionSourceClass):
|
|
521
|
+
if assertion.source.created is None:
|
|
522
|
+
logger.warning(
|
|
523
|
+
f"Assertion {assertion.urn} does not have a created by in the source"
|
|
524
|
+
)
|
|
525
|
+
return None
|
|
526
|
+
return CorpUserUrn.from_string(assertion.source.created.actor)
|
|
527
|
+
elif isinstance(assertion.source, models.AssertionSourceTypeClass):
|
|
528
|
+
logger.warning(
|
|
529
|
+
f"Assertion {assertion.urn} has a source type with no created by"
|
|
530
|
+
)
|
|
531
|
+
return None
|
|
532
|
+
return None
|
|
533
|
+
|
|
534
|
+
@staticmethod
|
|
535
|
+
def _get_created_at(assertion: Assertion) -> Union[datetime, None]:
|
|
536
|
+
if assertion.source is None:
|
|
537
|
+
logger.warning(f"Assertion {assertion.urn} does not have a source")
|
|
538
|
+
return None
|
|
539
|
+
if isinstance(assertion.source, models.AssertionSourceClass):
|
|
540
|
+
if assertion.source.created is None:
|
|
541
|
+
logger.warning(
|
|
542
|
+
f"Assertion {assertion.urn} does not have a created by in the source"
|
|
543
|
+
)
|
|
544
|
+
return None
|
|
545
|
+
return parse_ts_millis(assertion.source.created.time)
|
|
546
|
+
elif isinstance(assertion.source, models.AssertionSourceTypeClass):
|
|
547
|
+
logger.warning(
|
|
548
|
+
f"Assertion {assertion.urn} has a source type with no created by"
|
|
549
|
+
)
|
|
550
|
+
return None
|
|
551
|
+
return None
|
|
552
|
+
|
|
553
|
+
@staticmethod
|
|
554
|
+
def _get_updated_by(assertion: Assertion) -> Optional[CorpUserUrn]:
|
|
555
|
+
if assertion.last_updated is None:
|
|
556
|
+
logger.warning(f"Assertion {assertion.urn} does not have a last updated")
|
|
557
|
+
return None
|
|
558
|
+
return CorpUserUrn.from_string(assertion.last_updated.actor)
|
|
559
|
+
|
|
560
|
+
@staticmethod
|
|
561
|
+
def _get_updated_at(assertion: Assertion) -> Union[datetime, None]:
|
|
562
|
+
if assertion.last_updated is None:
|
|
563
|
+
logger.warning(f"Assertion {assertion.urn} does not have a last updated")
|
|
564
|
+
return None
|
|
565
|
+
return parse_ts_millis(assertion.last_updated.time)
|
|
566
|
+
|
|
567
|
+
@staticmethod
|
|
568
|
+
def _get_tags(assertion: Assertion) -> list[TagUrn]:
|
|
569
|
+
return [TagUrn.from_string(t.tag) for t in assertion.tags or []]
|
|
570
|
+
|
|
571
|
+
@staticmethod
|
|
572
|
+
def _get_mode(monitor: Monitor) -> AssertionMode:
|
|
573
|
+
if monitor.info is None:
|
|
574
|
+
logger.warning(
|
|
575
|
+
f"Monitor {monitor.urn} does not have a info, defaulting status to INACTIVE"
|
|
576
|
+
)
|
|
577
|
+
return AssertionMode.INACTIVE
|
|
578
|
+
return AssertionMode(monitor.info.status.mode)
|
|
579
|
+
|
|
580
|
+
@classmethod
|
|
581
|
+
@abstractmethod
|
|
582
|
+
def _from_entities(
|
|
583
|
+
cls,
|
|
584
|
+
assertion: Assertion,
|
|
585
|
+
monitor: Monitor,
|
|
586
|
+
) -> Self:
|
|
587
|
+
"""
|
|
588
|
+
Create an assertion from the assertion and monitor entities.
|
|
589
|
+
|
|
590
|
+
Note: This is a private method since it is intended to be called internally by the client.
|
|
591
|
+
"""
|
|
592
|
+
pass
|
|
593
|
+
|
|
594
|
+
@staticmethod
|
|
595
|
+
def _get_additional_filter(assertion: Assertion) -> Optional[str]:
|
|
596
|
+
"""Get the additional filter SQL from the assertion."""
|
|
597
|
+
if assertion.info is None:
|
|
598
|
+
logger.warning(
|
|
599
|
+
f"Assertion {assertion.urn} does not have an info, defaulting additional filter to None"
|
|
600
|
+
)
|
|
601
|
+
return None
|
|
602
|
+
if (
|
|
603
|
+
not isinstance(
|
|
604
|
+
assertion.info,
|
|
605
|
+
_AssertionPublic._SUPPORTED_WITH_FILTER_ASSERTION_TYPES,
|
|
606
|
+
)
|
|
607
|
+
or assertion.info.filter is None
|
|
608
|
+
):
|
|
609
|
+
logger.warning(
|
|
610
|
+
f"Assertion {assertion.urn} does not have a filter, defaulting additional filter to None"
|
|
611
|
+
)
|
|
612
|
+
return None
|
|
613
|
+
if assertion.info.filter.type != models.DatasetFilterTypeClass.SQL:
|
|
614
|
+
raise SDKNotYetSupportedError(
|
|
615
|
+
f"DatasetFilterType {assertion.info.filter.type}"
|
|
616
|
+
)
|
|
617
|
+
return assertion.info.filter.sql
|
|
618
|
+
|
|
619
|
+
@staticmethod
|
|
620
|
+
def _get_field_value_detection_mechanism(
|
|
621
|
+
assertion: Assertion,
|
|
622
|
+
parameters: models.AssertionEvaluationParametersClass,
|
|
623
|
+
) -> _DetectionMechanismTypes:
|
|
624
|
+
"""Get the detection mechanism for field value based freshness."""
|
|
625
|
+
# We know datasetFreshnessParameters is not None from _get_freshness_detection_mechanism check
|
|
626
|
+
assert parameters.datasetFreshnessParameters is not None
|
|
627
|
+
field = parameters.datasetFreshnessParameters.field
|
|
628
|
+
|
|
629
|
+
if field is None or field.kind is None:
|
|
630
|
+
logger.warning(
|
|
631
|
+
f"Monitor does not have valid field info, defaulting detection mechanism to {DEFAULT_DETECTION_MECHANISM}"
|
|
632
|
+
)
|
|
633
|
+
return DEFAULT_DETECTION_MECHANISM
|
|
634
|
+
|
|
635
|
+
column_name = field.path
|
|
636
|
+
additional_filter = _AssertionPublic._get_additional_filter(assertion)
|
|
637
|
+
|
|
638
|
+
if field.kind == models.FreshnessFieldKindClass.LAST_MODIFIED:
|
|
639
|
+
return DetectionMechanism.LAST_MODIFIED_COLUMN(
|
|
640
|
+
column_name=column_name, additional_filter=additional_filter
|
|
641
|
+
)
|
|
642
|
+
elif field.kind == models.FreshnessFieldKindClass.HIGH_WATERMARK:
|
|
643
|
+
return DetectionMechanism.HIGH_WATERMARK_COLUMN(
|
|
644
|
+
column_name=column_name, additional_filter=additional_filter
|
|
645
|
+
)
|
|
646
|
+
else:
|
|
647
|
+
raise SDKNotYetSupportedError(f"FreshnessFieldKind {field.kind}")
|
|
648
|
+
|
|
649
|
+
@staticmethod
|
|
650
|
+
def _warn_and_return_default_detection_mechanism(
|
|
651
|
+
monitor: Monitor,
|
|
652
|
+
field_name: str,
|
|
653
|
+
default: Optional[_DetectionMechanismTypes] = DEFAULT_DETECTION_MECHANISM,
|
|
654
|
+
) -> Optional[_DetectionMechanismTypes]:
|
|
655
|
+
"""Helper method to log a warning and return default detection mechanism."""
|
|
656
|
+
logger.warning(
|
|
657
|
+
f"Monitor {monitor.urn} does not have an `{field_name}` field, defaulting detection mechanism to {default}"
|
|
658
|
+
)
|
|
659
|
+
return default
|
|
660
|
+
|
|
661
|
+
@staticmethod
|
|
662
|
+
def _check_valid_monitor_info(
|
|
663
|
+
monitor: Monitor,
|
|
664
|
+
default: Optional[_DetectionMechanismTypes] = DEFAULT_DETECTION_MECHANISM,
|
|
665
|
+
) -> Optional[models.AssertionEvaluationParametersClass]:
|
|
666
|
+
"""Check if monitor has valid info and get assertion parameters.
|
|
667
|
+
|
|
668
|
+
Returns:
|
|
669
|
+
The assertion parameters if monitor info is valid, None otherwise.
|
|
670
|
+
"""
|
|
671
|
+
if not _AssertionPublic._has_valid_monitor_info(monitor):
|
|
672
|
+
return None
|
|
673
|
+
|
|
674
|
+
parameters = _AssertionPublic._get_assertion_parameters(monitor)
|
|
675
|
+
if parameters is None:
|
|
676
|
+
return None
|
|
677
|
+
|
|
678
|
+
return parameters
|
|
679
|
+
|
|
680
|
+
@staticmethod
|
|
681
|
+
def _get_validated_detection_context(
|
|
682
|
+
monitor: Monitor,
|
|
683
|
+
assertion: Assertion,
|
|
684
|
+
expected_parameters_type: str,
|
|
685
|
+
expected_info_class: type,
|
|
686
|
+
default: Optional[_DetectionMechanismTypes] = DEFAULT_DETECTION_MECHANISM,
|
|
687
|
+
) -> Optional[models.AssertionEvaluationParametersClass]:
|
|
688
|
+
"""
|
|
689
|
+
Validate and extract the detection context (parameters) for detection mechanism logic.
|
|
690
|
+
Returns the parameters if all checks pass, otherwise None.
|
|
691
|
+
"""
|
|
692
|
+
parameters = _AssertionPublic._check_valid_monitor_info(monitor, default)
|
|
693
|
+
if parameters is None:
|
|
694
|
+
return None
|
|
695
|
+
if parameters.type != expected_parameters_type:
|
|
696
|
+
logger.warning(
|
|
697
|
+
f"Expected {expected_parameters_type} parameters type, got {parameters.type}, defaulting detection mechanism to {default}"
|
|
698
|
+
)
|
|
699
|
+
return None
|
|
700
|
+
if assertion.info is None:
|
|
701
|
+
_AssertionPublic._warn_and_return_default_detection_mechanism(
|
|
702
|
+
monitor, "info", default
|
|
703
|
+
)
|
|
704
|
+
return None
|
|
705
|
+
if not isinstance(assertion.info, expected_info_class):
|
|
706
|
+
logger.warning(
|
|
707
|
+
f"Expected {expected_info_class.__name__}, got {type(assertion.info).__name__}, defaulting detection mechanism to {default}"
|
|
708
|
+
)
|
|
709
|
+
return None
|
|
710
|
+
return parameters
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
if TYPE_CHECKING:
|
|
714
|
+
# Import the assertion classes from their separate files for type checking
|
|
715
|
+
from acryl_datahub_cloud.sdk.assertion.column_metric_assertion import (
|
|
716
|
+
ColumnMetricAssertion,
|
|
717
|
+
)
|
|
718
|
+
from acryl_datahub_cloud.sdk.assertion.column_value_assertion import (
|
|
719
|
+
ColumnValueAssertion,
|
|
720
|
+
)
|
|
721
|
+
from acryl_datahub_cloud.sdk.assertion.freshness_assertion import FreshnessAssertion
|
|
722
|
+
from acryl_datahub_cloud.sdk.assertion.schema_assertion import SchemaAssertion
|
|
723
|
+
from acryl_datahub_cloud.sdk.assertion.smart_column_metric_assertion import (
|
|
724
|
+
SmartColumnMetricAssertion,
|
|
725
|
+
)
|
|
726
|
+
from acryl_datahub_cloud.sdk.assertion.smart_freshness_assertion import (
|
|
727
|
+
SmartFreshnessAssertion,
|
|
728
|
+
)
|
|
729
|
+
from acryl_datahub_cloud.sdk.assertion.smart_sql_assertion import SmartSqlAssertion
|
|
730
|
+
from acryl_datahub_cloud.sdk.assertion.smart_volume_assertion import (
|
|
731
|
+
SmartVolumeAssertion,
|
|
732
|
+
)
|
|
733
|
+
from acryl_datahub_cloud.sdk.assertion.sql_assertion import SqlAssertion
|
|
734
|
+
from acryl_datahub_cloud.sdk.assertion.volume_assertion import VolumeAssertion
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
# For runtime access, we'll use dynamic imports to avoid circular dependencies
|
|
738
|
+
def __getattr__(name: str) -> type:
|
|
739
|
+
"""Dynamic import for assertion classes to avoid circular dependencies."""
|
|
740
|
+
# Mapping of class names to their import paths
|
|
741
|
+
assertion_imports = {
|
|
742
|
+
"SmartFreshnessAssertion": "acryl_datahub_cloud.sdk.assertion.smart_freshness_assertion",
|
|
743
|
+
"SmartVolumeAssertion": "acryl_datahub_cloud.sdk.assertion.smart_volume_assertion",
|
|
744
|
+
"VolumeAssertion": "acryl_datahub_cloud.sdk.assertion.volume_assertion",
|
|
745
|
+
"FreshnessAssertion": "acryl_datahub_cloud.sdk.assertion.freshness_assertion",
|
|
746
|
+
"SqlAssertion": "acryl_datahub_cloud.sdk.assertion.sql_assertion",
|
|
747
|
+
"ColumnValueAssertion": "acryl_datahub_cloud.sdk.assertion.column_value_assertion",
|
|
748
|
+
"SmartSqlAssertion": "acryl_datahub_cloud.sdk.assertion.smart_sql_assertion",
|
|
749
|
+
"ColumnMetricAssertion": "acryl_datahub_cloud.sdk.assertion.column_metric_assertion",
|
|
750
|
+
"SmartColumnMetricAssertion": "acryl_datahub_cloud.sdk.assertion.smart_column_metric_assertion",
|
|
751
|
+
"SchemaAssertion": "acryl_datahub_cloud.sdk.assertion.schema_assertion",
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
if name in assertion_imports:
|
|
755
|
+
module_path = assertion_imports[name]
|
|
756
|
+
module = __import__(module_path, fromlist=[name])
|
|
757
|
+
return getattr(module, name)
|
|
758
|
+
|
|
759
|
+
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
# Export all classes for backward compatibility
|
|
763
|
+
__all__ = [
|
|
764
|
+
"AssertionMode",
|
|
765
|
+
"_HasSchedule",
|
|
766
|
+
"_HasSmartFunctionality",
|
|
767
|
+
"_HasColumnMetricFunctionality",
|
|
768
|
+
"_AssertionPublic",
|
|
769
|
+
"ColumnValueAssertion",
|
|
770
|
+
"SmartFreshnessAssertion",
|
|
771
|
+
"SmartSqlAssertion",
|
|
772
|
+
"SmartVolumeAssertion",
|
|
773
|
+
"SmartColumnMetricAssertion",
|
|
774
|
+
"VolumeAssertion",
|
|
775
|
+
"FreshnessAssertion",
|
|
776
|
+
"SqlAssertion",
|
|
777
|
+
"ColumnMetricAssertion",
|
|
778
|
+
"SchemaAssertion",
|
|
779
|
+
]
|