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,371 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from datetime import datetime, timezone
|
|
5
|
+
from typing import TYPE_CHECKING, Optional, Union
|
|
6
|
+
|
|
7
|
+
from acryl_datahub_cloud.sdk.assertion.assertion_base import (
|
|
8
|
+
AssertionMode,
|
|
9
|
+
FreshnessAssertion,
|
|
10
|
+
)
|
|
11
|
+
from acryl_datahub_cloud.sdk.assertion_client.helpers import (
|
|
12
|
+
DEFAULT_CREATED_BY,
|
|
13
|
+
_merge_field,
|
|
14
|
+
_print_experimental_warning,
|
|
15
|
+
retrieve_assertion_and_monitor_by_urn,
|
|
16
|
+
)
|
|
17
|
+
from acryl_datahub_cloud.sdk.assertion_input.assertion_input import (
|
|
18
|
+
AssertionIncidentBehaviorInputTypes,
|
|
19
|
+
DetectionMechanismInputTypes,
|
|
20
|
+
TimeWindowSizeInputTypes,
|
|
21
|
+
)
|
|
22
|
+
from acryl_datahub_cloud.sdk.assertion_input.freshness_assertion_input import (
|
|
23
|
+
FreshnessAssertionScheduleCheckType,
|
|
24
|
+
_FreshnessAssertionInput,
|
|
25
|
+
)
|
|
26
|
+
from acryl_datahub_cloud.sdk.entities.assertion import Assertion, TagsInputType
|
|
27
|
+
from acryl_datahub_cloud.sdk.entities.monitor import Monitor
|
|
28
|
+
from acryl_datahub_cloud.sdk.errors import SDKUsageError
|
|
29
|
+
from datahub.metadata import schema_classes as models
|
|
30
|
+
from datahub.metadata.urns import AssertionUrn, CorpUserUrn, DatasetUrn, MonitorUrn
|
|
31
|
+
|
|
32
|
+
if TYPE_CHECKING:
|
|
33
|
+
from datahub.sdk.main_client import DataHubClient
|
|
34
|
+
|
|
35
|
+
logger = logging.getLogger(__name__)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class FreshnessAssertionClient:
|
|
39
|
+
"""Client for managing freshness assertions."""
|
|
40
|
+
|
|
41
|
+
def __init__(self, client: "DataHubClient"):
|
|
42
|
+
self.client = client
|
|
43
|
+
|
|
44
|
+
def sync_freshness_assertion(
|
|
45
|
+
self,
|
|
46
|
+
*,
|
|
47
|
+
dataset_urn: Union[str, DatasetUrn],
|
|
48
|
+
urn: Optional[Union[str, AssertionUrn]] = None,
|
|
49
|
+
display_name: Optional[str] = None,
|
|
50
|
+
enabled: Optional[bool] = None,
|
|
51
|
+
detection_mechanism: DetectionMechanismInputTypes = None,
|
|
52
|
+
incident_behavior: Optional[AssertionIncidentBehaviorInputTypes] = None,
|
|
53
|
+
tags: Optional[TagsInputType] = None,
|
|
54
|
+
updated_by: Optional[Union[str, CorpUserUrn]] = None,
|
|
55
|
+
freshness_schedule_check_type: Optional[
|
|
56
|
+
Union[
|
|
57
|
+
str,
|
|
58
|
+
FreshnessAssertionScheduleCheckType,
|
|
59
|
+
models.FreshnessAssertionScheduleTypeClass,
|
|
60
|
+
]
|
|
61
|
+
] = None,
|
|
62
|
+
schedule: Optional[Union[str, models.CronScheduleClass]] = None,
|
|
63
|
+
lookback_window: Optional[TimeWindowSizeInputTypes] = None,
|
|
64
|
+
) -> FreshnessAssertion:
|
|
65
|
+
_print_experimental_warning()
|
|
66
|
+
now_utc = datetime.now(timezone.utc)
|
|
67
|
+
|
|
68
|
+
if updated_by is None:
|
|
69
|
+
logger.warning(
|
|
70
|
+
f"updated_by is not set, using {DEFAULT_CREATED_BY} as a placeholder"
|
|
71
|
+
)
|
|
72
|
+
updated_by = DEFAULT_CREATED_BY
|
|
73
|
+
|
|
74
|
+
# 1. Retrieve and merge the assertion input with any existing assertion and monitor entities,
|
|
75
|
+
# or build a new assertion input if the assertion does not exist:
|
|
76
|
+
assertion_input = self._retrieve_and_merge_freshness_assertion_and_monitor(
|
|
77
|
+
dataset_urn=dataset_urn,
|
|
78
|
+
urn=urn,
|
|
79
|
+
display_name=display_name,
|
|
80
|
+
enabled=enabled,
|
|
81
|
+
detection_mechanism=detection_mechanism,
|
|
82
|
+
incident_behavior=incident_behavior,
|
|
83
|
+
tags=tags,
|
|
84
|
+
updated_by=updated_by,
|
|
85
|
+
now_utc=now_utc,
|
|
86
|
+
schedule=schedule,
|
|
87
|
+
freshness_schedule_check_type=freshness_schedule_check_type,
|
|
88
|
+
lookback_window=lookback_window,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# 2. Upsert the assertion and monitor entities:
|
|
92
|
+
assertion_entity, monitor_entity = (
|
|
93
|
+
assertion_input.to_assertion_and_monitor_entities()
|
|
94
|
+
)
|
|
95
|
+
# If assertion upsert fails, we won't try to upsert the monitor
|
|
96
|
+
self.client.entities.upsert(assertion_entity)
|
|
97
|
+
# TODO: Wrap monitor upsert in a try-except and delete the assertion if monitor upsert fails (once delete is implemented https://linear.app/acryl-data/issue/OBS-1350/add-delete-method-to-entity-clientpy)
|
|
98
|
+
# try:
|
|
99
|
+
self.client.entities.upsert(monitor_entity)
|
|
100
|
+
# except Exception as e:
|
|
101
|
+
# logger.error(f"Error upserting monitor: {e}")
|
|
102
|
+
# self.client.entities.delete(assertion_entity)
|
|
103
|
+
# raise e
|
|
104
|
+
|
|
105
|
+
return FreshnessAssertion._from_entities(assertion_entity, monitor_entity)
|
|
106
|
+
|
|
107
|
+
def _retrieve_and_merge_freshness_assertion_and_monitor(
|
|
108
|
+
self,
|
|
109
|
+
dataset_urn: Union[str, DatasetUrn],
|
|
110
|
+
urn: Optional[Union[str, AssertionUrn]],
|
|
111
|
+
display_name: Optional[str],
|
|
112
|
+
enabled: Optional[bool],
|
|
113
|
+
detection_mechanism: DetectionMechanismInputTypes,
|
|
114
|
+
incident_behavior: Optional[AssertionIncidentBehaviorInputTypes],
|
|
115
|
+
tags: Optional[TagsInputType],
|
|
116
|
+
updated_by: Union[str, CorpUserUrn],
|
|
117
|
+
now_utc: datetime,
|
|
118
|
+
schedule: Optional[Union[str, models.CronScheduleClass]],
|
|
119
|
+
freshness_schedule_check_type: Optional[
|
|
120
|
+
Union[str, models.FreshnessAssertionScheduleTypeClass]
|
|
121
|
+
] = None,
|
|
122
|
+
lookback_window: Optional[TimeWindowSizeInputTypes] = None,
|
|
123
|
+
) -> _FreshnessAssertionInput:
|
|
124
|
+
# 1. If urn is not provided, build and return a new assertion input directly
|
|
125
|
+
if urn is None:
|
|
126
|
+
logger.info("URN is not set, building a new assertion input")
|
|
127
|
+
return _FreshnessAssertionInput(
|
|
128
|
+
urn=None,
|
|
129
|
+
entity_client=self.client.entities,
|
|
130
|
+
dataset_urn=dataset_urn,
|
|
131
|
+
display_name=display_name,
|
|
132
|
+
enabled=enabled if enabled is not None else True,
|
|
133
|
+
detection_mechanism=detection_mechanism,
|
|
134
|
+
freshness_schedule_check_type=freshness_schedule_check_type,
|
|
135
|
+
lookback_window=lookback_window,
|
|
136
|
+
incident_behavior=incident_behavior,
|
|
137
|
+
tags=tags,
|
|
138
|
+
created_by=updated_by,
|
|
139
|
+
created_at=now_utc,
|
|
140
|
+
updated_by=updated_by,
|
|
141
|
+
updated_at=now_utc,
|
|
142
|
+
schedule=schedule,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
# 2. Build initial assertion input for validation
|
|
146
|
+
assertion_input = _FreshnessAssertionInput(
|
|
147
|
+
urn=urn,
|
|
148
|
+
entity_client=self.client.entities,
|
|
149
|
+
dataset_urn=dataset_urn,
|
|
150
|
+
display_name=display_name,
|
|
151
|
+
detection_mechanism=detection_mechanism,
|
|
152
|
+
freshness_schedule_check_type=freshness_schedule_check_type,
|
|
153
|
+
lookback_window=lookback_window,
|
|
154
|
+
incident_behavior=incident_behavior,
|
|
155
|
+
tags=tags,
|
|
156
|
+
created_by=updated_by, # This will be overridden by the actual created_by
|
|
157
|
+
created_at=now_utc, # This will be overridden by the actual created_at
|
|
158
|
+
updated_by=updated_by,
|
|
159
|
+
updated_at=now_utc,
|
|
160
|
+
schedule=schedule,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
# 3. Retrieve any existing assertion and monitor entities:
|
|
164
|
+
maybe_assertion_entity, monitor_urn, maybe_monitor_entity = (
|
|
165
|
+
self._retrieve_assertion_and_monitor(assertion_input)
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
# 4.1 If the assertion and monitor entities exist, create an assertion object from them:
|
|
169
|
+
if maybe_assertion_entity and maybe_monitor_entity:
|
|
170
|
+
existing_assertion = FreshnessAssertion._from_entities(
|
|
171
|
+
maybe_assertion_entity, maybe_monitor_entity
|
|
172
|
+
)
|
|
173
|
+
# 4.2 If the assertion exists but the monitor does not, create a placeholder monitor entity to be able to create the assertion:
|
|
174
|
+
elif maybe_assertion_entity and not maybe_monitor_entity:
|
|
175
|
+
monitor_mode = (
|
|
176
|
+
"ACTIVE" if enabled else "INACTIVE" if enabled is not None else "ACTIVE"
|
|
177
|
+
)
|
|
178
|
+
existing_assertion = FreshnessAssertion._from_entities(
|
|
179
|
+
maybe_assertion_entity,
|
|
180
|
+
Monitor(id=monitor_urn, info=("ASSERTION", monitor_mode)),
|
|
181
|
+
)
|
|
182
|
+
# 4.3 If the assertion does not exist, build and return a new assertion input:
|
|
183
|
+
elif not maybe_assertion_entity:
|
|
184
|
+
logger.info(
|
|
185
|
+
f"No existing assertion entity found for assertion urn {urn}, building a new assertion input"
|
|
186
|
+
)
|
|
187
|
+
return _FreshnessAssertionInput(
|
|
188
|
+
urn=urn,
|
|
189
|
+
entity_client=self.client.entities,
|
|
190
|
+
dataset_urn=dataset_urn,
|
|
191
|
+
display_name=display_name,
|
|
192
|
+
enabled=enabled if enabled is not None else True,
|
|
193
|
+
detection_mechanism=detection_mechanism,
|
|
194
|
+
freshness_schedule_check_type=freshness_schedule_check_type,
|
|
195
|
+
lookback_window=lookback_window,
|
|
196
|
+
incident_behavior=incident_behavior,
|
|
197
|
+
tags=tags,
|
|
198
|
+
created_by=updated_by,
|
|
199
|
+
created_at=now_utc,
|
|
200
|
+
updated_by=updated_by,
|
|
201
|
+
updated_at=now_utc,
|
|
202
|
+
schedule=schedule,
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
# 5. Check for any issues e.g. different dataset urns
|
|
206
|
+
if (
|
|
207
|
+
existing_assertion
|
|
208
|
+
and hasattr(existing_assertion, "dataset_urn")
|
|
209
|
+
and existing_assertion.dataset_urn != assertion_input.dataset_urn
|
|
210
|
+
):
|
|
211
|
+
raise SDKUsageError(
|
|
212
|
+
f"Dataset URN mismatch, existing assertion: {existing_assertion.dataset_urn} != new assertion: {dataset_urn}"
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
# 6. Merge the existing assertion with the validated input:
|
|
216
|
+
merged_assertion_input = self._merge_freshness_input(
|
|
217
|
+
dataset_urn=dataset_urn,
|
|
218
|
+
urn=urn,
|
|
219
|
+
display_name=display_name,
|
|
220
|
+
enabled=enabled,
|
|
221
|
+
detection_mechanism=detection_mechanism,
|
|
222
|
+
incident_behavior=incident_behavior,
|
|
223
|
+
tags=tags,
|
|
224
|
+
now_utc=now_utc,
|
|
225
|
+
assertion_input=assertion_input,
|
|
226
|
+
maybe_assertion_entity=maybe_assertion_entity,
|
|
227
|
+
maybe_monitor_entity=maybe_monitor_entity,
|
|
228
|
+
existing_assertion=existing_assertion,
|
|
229
|
+
schedule=schedule,
|
|
230
|
+
freshness_schedule_check_type=freshness_schedule_check_type,
|
|
231
|
+
lookback_window=lookback_window,
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
return merged_assertion_input
|
|
235
|
+
|
|
236
|
+
def _retrieve_assertion_and_monitor(
|
|
237
|
+
self,
|
|
238
|
+
assertion_input: _FreshnessAssertionInput,
|
|
239
|
+
) -> tuple[Optional[Assertion], MonitorUrn, Optional[Monitor]]:
|
|
240
|
+
"""Retrieve the assertion and monitor entities from the DataHub instance.
|
|
241
|
+
|
|
242
|
+
Args:
|
|
243
|
+
assertion_input: The validated input to the function.
|
|
244
|
+
|
|
245
|
+
Returns:
|
|
246
|
+
The assertion and monitor entities.
|
|
247
|
+
"""
|
|
248
|
+
assert assertion_input.urn is not None, "URN is required"
|
|
249
|
+
return retrieve_assertion_and_monitor_by_urn(
|
|
250
|
+
self.client, assertion_input.urn, assertion_input.dataset_urn
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
def _merge_freshness_input(
|
|
254
|
+
self,
|
|
255
|
+
dataset_urn: Union[str, DatasetUrn],
|
|
256
|
+
urn: Union[str, AssertionUrn],
|
|
257
|
+
display_name: Optional[str],
|
|
258
|
+
enabled: Optional[bool],
|
|
259
|
+
detection_mechanism: DetectionMechanismInputTypes,
|
|
260
|
+
incident_behavior: Optional[AssertionIncidentBehaviorInputTypes],
|
|
261
|
+
tags: Optional[TagsInputType],
|
|
262
|
+
now_utc: datetime,
|
|
263
|
+
assertion_input: _FreshnessAssertionInput,
|
|
264
|
+
maybe_assertion_entity: Optional[Assertion],
|
|
265
|
+
maybe_monitor_entity: Optional[Monitor],
|
|
266
|
+
existing_assertion: FreshnessAssertion,
|
|
267
|
+
schedule: Optional[Union[str, models.CronScheduleClass]],
|
|
268
|
+
freshness_schedule_check_type: Optional[
|
|
269
|
+
Union[str, models.FreshnessAssertionScheduleTypeClass]
|
|
270
|
+
] = None,
|
|
271
|
+
lookback_window: Optional[TimeWindowSizeInputTypes] = None,
|
|
272
|
+
) -> _FreshnessAssertionInput:
|
|
273
|
+
"""Merge the input with the existing assertion and monitor entities.
|
|
274
|
+
|
|
275
|
+
Args:
|
|
276
|
+
dataset_urn: The urn of the dataset to be monitored.
|
|
277
|
+
urn: The urn of the assertion.
|
|
278
|
+
display_name: The display name of the assertion.
|
|
279
|
+
enabled: Whether the assertion is enabled.
|
|
280
|
+
incident_behavior: The incident behavior to be applied to the assertion.
|
|
281
|
+
tags: The tags to be applied to the assertion.
|
|
282
|
+
now_utc: The current UTC time from when the function is called.
|
|
283
|
+
assertion_input: The validated input to the function.
|
|
284
|
+
maybe_assertion_entity: The existing assertion entity from the DataHub instance.
|
|
285
|
+
maybe_monitor_entity: The existing monitor entity from the DataHub instance.
|
|
286
|
+
existing_assertion: The existing assertion from the DataHub instance.
|
|
287
|
+
schedule: The schedule to be applied to the assertion.
|
|
288
|
+
freshness_schedule_check_type: The freshness schedule check type to be applied to the assertion.
|
|
289
|
+
lookback_window: The lookback window to be applied to the assertion.
|
|
290
|
+
|
|
291
|
+
Returns:
|
|
292
|
+
The merged assertion input.
|
|
293
|
+
"""
|
|
294
|
+
merged_assertion_input = _FreshnessAssertionInput(
|
|
295
|
+
urn=urn,
|
|
296
|
+
entity_client=self.client.entities,
|
|
297
|
+
dataset_urn=dataset_urn,
|
|
298
|
+
display_name=_merge_field(
|
|
299
|
+
display_name,
|
|
300
|
+
"display_name",
|
|
301
|
+
assertion_input,
|
|
302
|
+
existing_assertion,
|
|
303
|
+
maybe_assertion_entity.description if maybe_assertion_entity else None,
|
|
304
|
+
),
|
|
305
|
+
enabled=_merge_field(
|
|
306
|
+
enabled,
|
|
307
|
+
"enabled",
|
|
308
|
+
assertion_input,
|
|
309
|
+
existing_assertion,
|
|
310
|
+
existing_assertion.mode == AssertionMode.ACTIVE
|
|
311
|
+
if existing_assertion
|
|
312
|
+
else None,
|
|
313
|
+
),
|
|
314
|
+
schedule=_merge_field(
|
|
315
|
+
schedule,
|
|
316
|
+
"schedule",
|
|
317
|
+
assertion_input,
|
|
318
|
+
existing_assertion,
|
|
319
|
+
existing_assertion.schedule if existing_assertion else None,
|
|
320
|
+
),
|
|
321
|
+
freshness_schedule_check_type=_merge_field(
|
|
322
|
+
freshness_schedule_check_type,
|
|
323
|
+
"freshness_schedule_check_type",
|
|
324
|
+
assertion_input,
|
|
325
|
+
existing_assertion,
|
|
326
|
+
existing_assertion._freshness_schedule_check_type
|
|
327
|
+
if existing_assertion
|
|
328
|
+
else None,
|
|
329
|
+
),
|
|
330
|
+
lookback_window=_merge_field(
|
|
331
|
+
lookback_window,
|
|
332
|
+
"lookback_window",
|
|
333
|
+
assertion_input,
|
|
334
|
+
existing_assertion,
|
|
335
|
+
existing_assertion.lookback_window if existing_assertion else None,
|
|
336
|
+
),
|
|
337
|
+
detection_mechanism=_merge_field(
|
|
338
|
+
detection_mechanism,
|
|
339
|
+
"detection_mechanism",
|
|
340
|
+
assertion_input,
|
|
341
|
+
existing_assertion,
|
|
342
|
+
FreshnessAssertion._get_detection_mechanism(
|
|
343
|
+
maybe_assertion_entity, maybe_monitor_entity, default=None
|
|
344
|
+
)
|
|
345
|
+
if maybe_assertion_entity and maybe_monitor_entity
|
|
346
|
+
else None,
|
|
347
|
+
),
|
|
348
|
+
incident_behavior=_merge_field(
|
|
349
|
+
incident_behavior,
|
|
350
|
+
"incident_behavior",
|
|
351
|
+
assertion_input,
|
|
352
|
+
existing_assertion,
|
|
353
|
+
FreshnessAssertion._get_incident_behavior(maybe_assertion_entity)
|
|
354
|
+
if maybe_assertion_entity
|
|
355
|
+
else None,
|
|
356
|
+
),
|
|
357
|
+
tags=_merge_field(
|
|
358
|
+
tags,
|
|
359
|
+
"tags",
|
|
360
|
+
assertion_input,
|
|
361
|
+
existing_assertion,
|
|
362
|
+
maybe_assertion_entity.tags if maybe_assertion_entity else None,
|
|
363
|
+
),
|
|
364
|
+
created_by=existing_assertion.created_by
|
|
365
|
+
or DEFAULT_CREATED_BY, # Override with the existing assertion's created_by or the default created_by if not set
|
|
366
|
+
created_at=existing_assertion.created_at
|
|
367
|
+
or now_utc, # Override with the existing assertion's created_at or now if not set
|
|
368
|
+
updated_by=assertion_input.updated_by, # Override with the input's updated_by
|
|
369
|
+
updated_at=assertion_input.updated_at, # Override with the input's updated_at (now)
|
|
370
|
+
)
|
|
371
|
+
return merged_assertion_input
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"""Helper utilities for assertion clients."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Optional, Union
|
|
7
|
+
|
|
8
|
+
from acryl_datahub_cloud.sdk.assertion.assertion_base import _AssertionPublic
|
|
9
|
+
from acryl_datahub_cloud.sdk.assertion_input.assertion_input import _AssertionInput
|
|
10
|
+
from acryl_datahub_cloud.sdk.entities.assertion import Assertion
|
|
11
|
+
from acryl_datahub_cloud.sdk.entities.monitor import Monitor
|
|
12
|
+
from acryl_datahub_cloud.sdk.errors import SDKUsageError
|
|
13
|
+
from datahub.errors import ItemNotFoundError
|
|
14
|
+
from datahub.metadata.urns import AssertionUrn, CorpUserUrn, DatasetUrn, MonitorUrn
|
|
15
|
+
from datahub.sdk.search_filters import FilterDsl
|
|
16
|
+
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from datahub.sdk.main_client import DataHubClient
|
|
19
|
+
|
|
20
|
+
logger = logging.getLogger(__name__)
|
|
21
|
+
|
|
22
|
+
# TODO: Replace __datahub_system with the actual datahub system user https://linear.app/acryl-data/issue/OBS-1351/auditstamp-actor-hydration-pattern-for-sdk-calls
|
|
23
|
+
DEFAULT_CREATED_BY = CorpUserUrn.from_string("urn:li:corpuser:__datahub_system")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _merge_field(
|
|
27
|
+
input_field_value: Any,
|
|
28
|
+
input_field_name: str,
|
|
29
|
+
validated_assertion_input: _AssertionInput,
|
|
30
|
+
validated_existing_assertion: _AssertionPublic,
|
|
31
|
+
existing_entity_value: Optional[Any] = None, # TODO: Can we do better than Any?
|
|
32
|
+
) -> Any:
|
|
33
|
+
"""Merge the input field value with any existing entity value or default value.
|
|
34
|
+
|
|
35
|
+
The merge logic is as follows:
|
|
36
|
+
- If the input is None, use the existing value
|
|
37
|
+
- If the input is not None, use the input value
|
|
38
|
+
- If the input is an empty list or empty string, still use the input value (falsy values can be used to unset fields)
|
|
39
|
+
- If the input is a non-empty list or non-empty string, use the input value
|
|
40
|
+
- If the input is None and the existing value is None, use the default value from _AssertionInput
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
input_field_value: The value of the field in the input e.g. passed to the function.
|
|
44
|
+
input_field_name: The name of the field in the input.
|
|
45
|
+
validated_assertion_input: The *validated* input to the function.
|
|
46
|
+
validated_existing_assertion: The *validated* existing assertion from the DataHub instance.
|
|
47
|
+
existing_entity_value: The value of the field in the existing entity from the DataHub instance, directly retrieved from the entity.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
The merged value of the field.
|
|
51
|
+
|
|
52
|
+
"""
|
|
53
|
+
if input_field_value is None: # Input value default
|
|
54
|
+
if existing_entity_value is not None: # Existing entity value set
|
|
55
|
+
return existing_entity_value
|
|
56
|
+
elif (
|
|
57
|
+
getattr(validated_existing_assertion, input_field_name) is None
|
|
58
|
+
): # Validated existing value not set
|
|
59
|
+
return getattr(validated_assertion_input, input_field_name)
|
|
60
|
+
else: # Validated existing value set
|
|
61
|
+
return getattr(validated_existing_assertion, input_field_name)
|
|
62
|
+
else: # Input value set
|
|
63
|
+
return input_field_value
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _print_experimental_warning() -> None:
|
|
67
|
+
print(
|
|
68
|
+
"Warning: The assertions client is experimental and under heavy development. Expect breaking changes."
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _validate_required_field(
|
|
73
|
+
field_value: Optional[Any], field_name: str, context: str
|
|
74
|
+
) -> None:
|
|
75
|
+
"""Validate that a required field is not None and raise SDKUsageError if it is."""
|
|
76
|
+
if field_value is None:
|
|
77
|
+
raise SDKUsageError(f"{field_name} is required {context}")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def resolve_updated_by(
|
|
81
|
+
updated_by: Optional[Union[str, CorpUserUrn]],
|
|
82
|
+
) -> Union[str, CorpUserUrn]:
|
|
83
|
+
"""Resolve the updated_by field, using DEFAULT_CREATED_BY if not provided.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
updated_by: The updated_by value from the user input, or None.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
The resolved updated_by value.
|
|
90
|
+
"""
|
|
91
|
+
if updated_by is None:
|
|
92
|
+
logger.warning(
|
|
93
|
+
f"updated_by is not set, using {DEFAULT_CREATED_BY} as a placeholder"
|
|
94
|
+
)
|
|
95
|
+
return DEFAULT_CREATED_BY
|
|
96
|
+
return updated_by
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def retrieve_assertion_and_monitor_by_urn(
|
|
100
|
+
client: "DataHubClient",
|
|
101
|
+
assertion_urn: Union[str, AssertionUrn],
|
|
102
|
+
dataset_urn: Union[str, DatasetUrn],
|
|
103
|
+
) -> tuple[Optional[Assertion], MonitorUrn, Optional[Monitor]]:
|
|
104
|
+
"""Retrieve the assertion and monitor entities from the DataHub instance by URN.
|
|
105
|
+
|
|
106
|
+
Args:
|
|
107
|
+
client: The DataHub client.
|
|
108
|
+
assertion_urn: The assertion URN.
|
|
109
|
+
dataset_urn: The dataset URN.
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
A tuple of (assertion entity or None, monitor URN, monitor entity or None).
|
|
113
|
+
"""
|
|
114
|
+
urn: AssertionUrn = (
|
|
115
|
+
assertion_urn
|
|
116
|
+
if isinstance(assertion_urn, AssertionUrn)
|
|
117
|
+
else AssertionUrn.from_string(assertion_urn)
|
|
118
|
+
)
|
|
119
|
+
_dataset_urn: DatasetUrn = (
|
|
120
|
+
dataset_urn
|
|
121
|
+
if isinstance(dataset_urn, DatasetUrn)
|
|
122
|
+
else DatasetUrn.from_string(dataset_urn)
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
# Get assertion entity
|
|
126
|
+
maybe_assertion_entity: Optional[Assertion] = None
|
|
127
|
+
try:
|
|
128
|
+
entity = client.entities.get(urn)
|
|
129
|
+
if entity is not None:
|
|
130
|
+
assert isinstance(entity, Assertion)
|
|
131
|
+
maybe_assertion_entity = entity
|
|
132
|
+
except ItemNotFoundError:
|
|
133
|
+
pass
|
|
134
|
+
|
|
135
|
+
# Get monitor entity by searching for monitors where assertionUrn equals the assertion urn
|
|
136
|
+
monitor_urn: Optional[MonitorUrn] = None
|
|
137
|
+
maybe_monitor_entity: Optional[Monitor] = None
|
|
138
|
+
try:
|
|
139
|
+
# Search for monitor entities with assertionUrn matching the assertion urn
|
|
140
|
+
monitor_filter = FilterDsl.and_(
|
|
141
|
+
FilterDsl.entity_type("monitor"),
|
|
142
|
+
FilterDsl.custom_filter("assertionUrn", "EQUAL", [str(urn)]),
|
|
143
|
+
)
|
|
144
|
+
monitor_urns = list(client.search.get_urns(filter=monitor_filter))
|
|
145
|
+
|
|
146
|
+
if monitor_urns:
|
|
147
|
+
# Log if there are multiple monitors found, because this is unexpected
|
|
148
|
+
if len(monitor_urns) > 1:
|
|
149
|
+
logger.warning(
|
|
150
|
+
f"Multiple monitors found for assertion {urn}, which should never happen: {monitor_urns}"
|
|
151
|
+
)
|
|
152
|
+
# Use the first matching monitor
|
|
153
|
+
monitor_urn = MonitorUrn.from_string(str(monitor_urns[0]))
|
|
154
|
+
entity = client.entities.get(monitor_urn)
|
|
155
|
+
if entity is not None:
|
|
156
|
+
assert isinstance(entity, Monitor)
|
|
157
|
+
maybe_monitor_entity = entity
|
|
158
|
+
except ItemNotFoundError as e:
|
|
159
|
+
logger.debug(f"Could not find monitor for assertion {urn}: {e}")
|
|
160
|
+
pass
|
|
161
|
+
|
|
162
|
+
# If no monitor found via search, fall back to creating a new monitor with the dataset urn and assertion urn
|
|
163
|
+
if monitor_urn is None:
|
|
164
|
+
monitor_urn = Monitor._ensure_id(id=(_dataset_urn, urn))
|
|
165
|
+
|
|
166
|
+
return maybe_assertion_entity, monitor_urn, maybe_monitor_entity
|