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.

Files changed (238) hide show
  1. acryl_datahub_cloud/_codegen_config.json +1 -1
  2. acryl_datahub_cloud/acryl_cs_issues/models.py +5 -3
  3. acryl_datahub_cloud/action_request/action_request_owner_source.py +36 -6
  4. acryl_datahub_cloud/datahub_forms_notifications/__init__.py +0 -0
  5. acryl_datahub_cloud/datahub_forms_notifications/forms_notifications_source.py +569 -0
  6. acryl_datahub_cloud/datahub_forms_notifications/get_feature_flag.gql +7 -0
  7. acryl_datahub_cloud/datahub_forms_notifications/get_search_results_total.gql +14 -0
  8. acryl_datahub_cloud/datahub_forms_notifications/query.py +17 -0
  9. acryl_datahub_cloud/datahub_forms_notifications/scroll_forms_for_notification.gql +29 -0
  10. acryl_datahub_cloud/datahub_forms_notifications/send_form_notification_request.gql +5 -0
  11. acryl_datahub_cloud/datahub_reporting/datahub_dataset.py +37 -13
  12. acryl_datahub_cloud/datahub_reporting/datahub_form_reporting.py +55 -24
  13. acryl_datahub_cloud/datahub_reporting/extract_graph.py +4 -3
  14. acryl_datahub_cloud/datahub_reporting/extract_sql.py +242 -51
  15. acryl_datahub_cloud/datahub_reporting/forms.py +1 -1
  16. acryl_datahub_cloud/datahub_reporting/forms_config.py +3 -2
  17. acryl_datahub_cloud/datahub_restore/source.py +3 -2
  18. acryl_datahub_cloud/datahub_usage_reporting/excluded.py +94 -0
  19. acryl_datahub_cloud/datahub_usage_reporting/query_builder.py +48 -8
  20. acryl_datahub_cloud/datahub_usage_reporting/usage_feature_reporter.py +518 -77
  21. acryl_datahub_cloud/elasticsearch/graph_service.py +76 -14
  22. acryl_datahub_cloud/graphql_utils.py +64 -0
  23. acryl_datahub_cloud/lineage_features/source.py +555 -49
  24. acryl_datahub_cloud/metadata/_urns/urn_defs.py +2296 -1900
  25. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/actionworkflow/__init__.py +53 -0
  26. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/anomaly/__init__.py +2 -0
  27. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/application/__init__.py +19 -0
  28. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/assertion/__init__.py +4 -2
  29. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/common/__init__.py +6 -0
  30. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/conversation/__init__.py +29 -0
  31. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/event/notification/settings/__init__.py +2 -0
  32. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/execution/__init__.py +2 -0
  33. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/file/__init__.py +19 -0
  34. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/form/__init__.py +8 -0
  35. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/identity/__init__.py +8 -0
  36. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/knowledge/__init__.py +33 -0
  37. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/logical/__init__.py +15 -0
  38. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/metadata/key/__init__.py +12 -0
  39. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/metadata/search/features/__init__.py +2 -0
  40. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/module/__init__.py +31 -0
  41. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/notification/__init__.py +19 -0
  42. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/platform/event/v1/__init__.py +4 -0
  43. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/role/__init__.py +2 -0
  44. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/settings/asset/__init__.py +19 -0
  45. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/settings/global/__init__.py +28 -0
  46. acryl_datahub_cloud/metadata/com/linkedin/pegasus2avro/template/__init__.py +31 -0
  47. acryl_datahub_cloud/metadata/schema.avsc +25091 -20557
  48. acryl_datahub_cloud/metadata/schema_classes.py +29269 -23863
  49. acryl_datahub_cloud/metadata/schemas/ActionRequestInfo.avsc +235 -2
  50. acryl_datahub_cloud/metadata/schemas/ActionWorkflowInfo.avsc +683 -0
  51. acryl_datahub_cloud/metadata/schemas/ActionWorkflowKey.avsc +21 -0
  52. acryl_datahub_cloud/metadata/schemas/Actors.avsc +38 -1
  53. acryl_datahub_cloud/metadata/schemas/ApplicationKey.avsc +31 -0
  54. acryl_datahub_cloud/metadata/schemas/ApplicationProperties.avsc +75 -0
  55. acryl_datahub_cloud/metadata/schemas/Applications.avsc +38 -0
  56. acryl_datahub_cloud/metadata/schemas/AssertionAnalyticsRunEvent.avsc +353 -215
  57. acryl_datahub_cloud/metadata/schemas/AssertionInfo.avsc +147 -20
  58. acryl_datahub_cloud/metadata/schemas/AssertionKey.avsc +1 -1
  59. acryl_datahub_cloud/metadata/schemas/AssertionRunEvent.avsc +166 -21
  60. acryl_datahub_cloud/metadata/schemas/{AssertionSummary.avsc → AssertionRunSummary.avsc} +15 -2
  61. acryl_datahub_cloud/metadata/schemas/AssertionsSummary.avsc +54 -0
  62. acryl_datahub_cloud/metadata/schemas/AssetSettings.avsc +63 -0
  63. acryl_datahub_cloud/metadata/schemas/BusinessAttributeInfo.avsc +7 -3
  64. acryl_datahub_cloud/metadata/schemas/ChartInfo.avsc +20 -6
  65. acryl_datahub_cloud/metadata/schemas/ChartKey.avsc +1 -0
  66. acryl_datahub_cloud/metadata/schemas/ConstraintInfo.avsc +12 -1
  67. acryl_datahub_cloud/metadata/schemas/ContainerKey.avsc +1 -0
  68. acryl_datahub_cloud/metadata/schemas/ContainerProperties.avsc +16 -5
  69. acryl_datahub_cloud/metadata/schemas/CorpGroupEditableInfo.avsc +2 -1
  70. acryl_datahub_cloud/metadata/schemas/CorpGroupInfo.avsc +7 -3
  71. acryl_datahub_cloud/metadata/schemas/CorpGroupKey.avsc +2 -1
  72. acryl_datahub_cloud/metadata/schemas/CorpGroupSettings.avsc +127 -2
  73. acryl_datahub_cloud/metadata/schemas/CorpUserEditableInfo.avsc +1 -1
  74. acryl_datahub_cloud/metadata/schemas/CorpUserInfo.avsc +18 -2
  75. acryl_datahub_cloud/metadata/schemas/CorpUserInvitationStatus.avsc +106 -0
  76. acryl_datahub_cloud/metadata/schemas/CorpUserKey.avsc +4 -1
  77. acryl_datahub_cloud/metadata/schemas/CorpUserSettings.avsc +304 -2
  78. acryl_datahub_cloud/metadata/schemas/CorpUserUsageFeatures.avsc +86 -0
  79. acryl_datahub_cloud/metadata/schemas/DashboardInfo.avsc +11 -5
  80. acryl_datahub_cloud/metadata/schemas/DashboardKey.avsc +1 -0
  81. acryl_datahub_cloud/metadata/schemas/DataFlowInfo.avsc +15 -5
  82. acryl_datahub_cloud/metadata/schemas/DataFlowKey.avsc +1 -0
  83. acryl_datahub_cloud/metadata/schemas/DataHubAiConversationInfo.avsc +256 -0
  84. acryl_datahub_cloud/metadata/schemas/DataHubAiConversationKey.avsc +22 -0
  85. acryl_datahub_cloud/metadata/schemas/DataHubFileInfo.avsc +234 -0
  86. acryl_datahub_cloud/metadata/schemas/DataHubFileKey.avsc +22 -0
  87. acryl_datahub_cloud/metadata/schemas/DataHubIngestionSourceKey.avsc +2 -1
  88. acryl_datahub_cloud/metadata/schemas/DataHubPageModuleKey.avsc +21 -0
  89. acryl_datahub_cloud/metadata/schemas/DataHubPageModuleProperties.avsc +308 -0
  90. acryl_datahub_cloud/metadata/schemas/DataHubPageTemplateKey.avsc +21 -0
  91. acryl_datahub_cloud/metadata/schemas/DataHubPageTemplateProperties.avsc +251 -0
  92. acryl_datahub_cloud/metadata/schemas/DataHubPolicyInfo.avsc +12 -1
  93. acryl_datahub_cloud/metadata/schemas/DataJobInfo.avsc +13 -4
  94. acryl_datahub_cloud/metadata/schemas/DataJobInputOutput.avsc +8 -0
  95. acryl_datahub_cloud/metadata/schemas/DataJobKey.avsc +1 -0
  96. acryl_datahub_cloud/metadata/schemas/DataPlatformInfo.avsc +3 -1
  97. acryl_datahub_cloud/metadata/schemas/DataPlatformInstanceProperties.avsc +5 -2
  98. acryl_datahub_cloud/metadata/schemas/DataProcessKey.avsc +4 -0
  99. acryl_datahub_cloud/metadata/schemas/DataProductKey.avsc +2 -0
  100. acryl_datahub_cloud/metadata/schemas/DataProductProperties.avsc +6 -3
  101. acryl_datahub_cloud/metadata/schemas/DataTypeInfo.avsc +5 -0
  102. acryl_datahub_cloud/metadata/schemas/DatasetKey.avsc +10 -2
  103. acryl_datahub_cloud/metadata/schemas/DatasetProperties.avsc +12 -5
  104. acryl_datahub_cloud/metadata/schemas/DatasetUsageStatistics.avsc +8 -0
  105. acryl_datahub_cloud/metadata/schemas/DocumentInfo.avsc +407 -0
  106. acryl_datahub_cloud/metadata/schemas/DocumentKey.avsc +35 -0
  107. acryl_datahub_cloud/metadata/schemas/DocumentSettings.avsc +79 -0
  108. acryl_datahub_cloud/metadata/schemas/DomainKey.avsc +2 -0
  109. acryl_datahub_cloud/metadata/schemas/DomainProperties.avsc +7 -3
  110. acryl_datahub_cloud/metadata/schemas/EditableContainerProperties.avsc +2 -1
  111. acryl_datahub_cloud/metadata/schemas/EditableDashboardProperties.avsc +2 -1
  112. acryl_datahub_cloud/metadata/schemas/EditableDataFlowProperties.avsc +2 -1
  113. acryl_datahub_cloud/metadata/schemas/EditableDataJobProperties.avsc +2 -1
  114. acryl_datahub_cloud/metadata/schemas/EditableDatasetProperties.avsc +2 -1
  115. acryl_datahub_cloud/metadata/schemas/EditableERModelRelationshipProperties.avsc +2 -1
  116. acryl_datahub_cloud/metadata/schemas/EditableMLFeatureProperties.avsc +2 -1
  117. acryl_datahub_cloud/metadata/schemas/EditableMLFeatureTableProperties.avsc +2 -1
  118. acryl_datahub_cloud/metadata/schemas/EditableMLModelGroupProperties.avsc +2 -1
  119. acryl_datahub_cloud/metadata/schemas/EditableMLModelProperties.avsc +2 -1
  120. acryl_datahub_cloud/metadata/schemas/EditableNotebookProperties.avsc +2 -1
  121. acryl_datahub_cloud/metadata/schemas/EditableSchemaMetadata.avsc +4 -2
  122. acryl_datahub_cloud/metadata/schemas/EntityTypeInfo.avsc +5 -0
  123. acryl_datahub_cloud/metadata/schemas/ExecutionRequestArtifactsLocation.avsc +16 -0
  124. acryl_datahub_cloud/metadata/schemas/ExecutionRequestKey.avsc +2 -1
  125. acryl_datahub_cloud/metadata/schemas/FormAssignmentStatus.avsc +36 -0
  126. acryl_datahub_cloud/metadata/schemas/FormInfo.avsc +6 -0
  127. acryl_datahub_cloud/metadata/schemas/FormKey.avsc +3 -1
  128. acryl_datahub_cloud/metadata/schemas/FormNotifications.avsc +69 -0
  129. acryl_datahub_cloud/metadata/schemas/FormSettings.avsc +30 -0
  130. acryl_datahub_cloud/metadata/schemas/GlobalSettingsInfo.avsc +416 -0
  131. acryl_datahub_cloud/metadata/schemas/GlobalTags.avsc +2 -1
  132. acryl_datahub_cloud/metadata/schemas/GlossaryNodeInfo.avsc +3 -1
  133. acryl_datahub_cloud/metadata/schemas/GlossaryNodeKey.avsc +1 -0
  134. acryl_datahub_cloud/metadata/schemas/GlossaryTermInfo.avsc +3 -1
  135. acryl_datahub_cloud/metadata/schemas/GlossaryTermKey.avsc +2 -0
  136. acryl_datahub_cloud/metadata/schemas/IcebergWarehouseInfo.avsc +4 -0
  137. acryl_datahub_cloud/metadata/schemas/IncidentActivityEvent.avsc +3 -3
  138. acryl_datahub_cloud/metadata/schemas/IncidentInfo.avsc +3 -3
  139. acryl_datahub_cloud/metadata/schemas/InferredMetadata.avsc +71 -1
  140. acryl_datahub_cloud/metadata/schemas/InputFields.avsc +2 -1
  141. acryl_datahub_cloud/metadata/schemas/InviteToken.avsc +26 -0
  142. acryl_datahub_cloud/metadata/schemas/LineageFeatures.avsc +67 -42
  143. acryl_datahub_cloud/metadata/schemas/LogicalParent.avsc +145 -0
  144. acryl_datahub_cloud/metadata/schemas/MLFeatureKey.avsc +4 -1
  145. acryl_datahub_cloud/metadata/schemas/MLFeatureTableKey.avsc +4 -1
  146. acryl_datahub_cloud/metadata/schemas/MLModelDeploymentKey.avsc +7 -1
  147. acryl_datahub_cloud/metadata/schemas/MLModelGroupKey.avsc +9 -1
  148. acryl_datahub_cloud/metadata/schemas/MLModelKey.avsc +9 -1
  149. acryl_datahub_cloud/metadata/schemas/MLModelProperties.avsc +4 -2
  150. acryl_datahub_cloud/metadata/schemas/MLPrimaryKeyKey.avsc +4 -1
  151. acryl_datahub_cloud/metadata/schemas/MetadataChangeEvent.avsc +418 -97
  152. acryl_datahub_cloud/metadata/schemas/MetadataChangeLog.avsc +62 -44
  153. acryl_datahub_cloud/metadata/schemas/MetadataChangeProposal.avsc +61 -0
  154. acryl_datahub_cloud/metadata/schemas/MonitorAnomalyEvent.avsc +54 -9
  155. acryl_datahub_cloud/metadata/schemas/MonitorInfo.avsc +163 -23
  156. acryl_datahub_cloud/metadata/schemas/MonitorKey.avsc +9 -1
  157. acryl_datahub_cloud/metadata/schemas/MonitorSuiteInfo.avsc +128 -3
  158. acryl_datahub_cloud/metadata/schemas/NotebookInfo.avsc +5 -2
  159. acryl_datahub_cloud/metadata/schemas/NotebookKey.avsc +1 -0
  160. acryl_datahub_cloud/metadata/schemas/NotificationRequest.avsc +91 -4
  161. acryl_datahub_cloud/metadata/schemas/Operation.avsc +17 -0
  162. acryl_datahub_cloud/metadata/schemas/Ownership.avsc +71 -1
  163. acryl_datahub_cloud/metadata/schemas/QuerySubjects.avsc +2 -13
  164. acryl_datahub_cloud/metadata/schemas/RelationshipChangeEvent.avsc +215 -0
  165. acryl_datahub_cloud/metadata/schemas/RoleProperties.avsc +3 -1
  166. acryl_datahub_cloud/metadata/schemas/SchemaFieldInfo.avsc +3 -1
  167. acryl_datahub_cloud/metadata/schemas/SchemaFieldKey.avsc +3 -0
  168. acryl_datahub_cloud/metadata/schemas/SchemaMetadata.avsc +2 -1
  169. acryl_datahub_cloud/metadata/schemas/SemanticContent.avsc +123 -0
  170. acryl_datahub_cloud/metadata/schemas/StructuredProperties.avsc +69 -0
  171. acryl_datahub_cloud/metadata/schemas/StructuredPropertyDefinition.avsc +15 -4
  172. acryl_datahub_cloud/metadata/schemas/StructuredPropertySettings.avsc +9 -0
  173. acryl_datahub_cloud/metadata/schemas/SubscriptionInfo.avsc +136 -5
  174. acryl_datahub_cloud/metadata/schemas/SubscriptionKey.avsc +2 -1
  175. acryl_datahub_cloud/metadata/schemas/SystemMetadata.avsc +61 -0
  176. acryl_datahub_cloud/metadata/schemas/TagProperties.avsc +3 -1
  177. acryl_datahub_cloud/metadata/schemas/TestInfo.avsc +2 -1
  178. acryl_datahub_cloud/metadata/schemas/UpstreamLineage.avsc +9 -0
  179. acryl_datahub_cloud/metadata/schemas/UsageFeatures.avsc +10 -0
  180. acryl_datahub_cloud/notifications/__init__.py +0 -0
  181. acryl_datahub_cloud/notifications/notification_recipient_builder.py +399 -0
  182. acryl_datahub_cloud/sdk/__init__.py +69 -0
  183. acryl_datahub_cloud/sdk/assertion/__init__.py +58 -0
  184. acryl_datahub_cloud/sdk/assertion/assertion_base.py +779 -0
  185. acryl_datahub_cloud/sdk/assertion/column_metric_assertion.py +191 -0
  186. acryl_datahub_cloud/sdk/assertion/column_value_assertion.py +431 -0
  187. acryl_datahub_cloud/sdk/assertion/freshness_assertion.py +201 -0
  188. acryl_datahub_cloud/sdk/assertion/schema_assertion.py +268 -0
  189. acryl_datahub_cloud/sdk/assertion/smart_column_metric_assertion.py +212 -0
  190. acryl_datahub_cloud/sdk/assertion/smart_freshness_assertion.py +165 -0
  191. acryl_datahub_cloud/sdk/assertion/smart_sql_assertion.py +156 -0
  192. acryl_datahub_cloud/sdk/assertion/smart_volume_assertion.py +162 -0
  193. acryl_datahub_cloud/sdk/assertion/sql_assertion.py +273 -0
  194. acryl_datahub_cloud/sdk/assertion/types.py +20 -0
  195. acryl_datahub_cloud/sdk/assertion/volume_assertion.py +156 -0
  196. acryl_datahub_cloud/sdk/assertion_client/__init__.py +0 -0
  197. acryl_datahub_cloud/sdk/assertion_client/column_metric.py +545 -0
  198. acryl_datahub_cloud/sdk/assertion_client/column_value.py +617 -0
  199. acryl_datahub_cloud/sdk/assertion_client/freshness.py +371 -0
  200. acryl_datahub_cloud/sdk/assertion_client/helpers.py +166 -0
  201. acryl_datahub_cloud/sdk/assertion_client/schema.py +358 -0
  202. acryl_datahub_cloud/sdk/assertion_client/smart_column_metric.py +540 -0
  203. acryl_datahub_cloud/sdk/assertion_client/smart_freshness.py +373 -0
  204. acryl_datahub_cloud/sdk/assertion_client/smart_sql.py +411 -0
  205. acryl_datahub_cloud/sdk/assertion_client/smart_volume.py +380 -0
  206. acryl_datahub_cloud/sdk/assertion_client/sql.py +410 -0
  207. acryl_datahub_cloud/sdk/assertion_client/volume.py +446 -0
  208. acryl_datahub_cloud/sdk/assertion_input/__init__.py +0 -0
  209. acryl_datahub_cloud/sdk/assertion_input/assertion_input.py +1470 -0
  210. acryl_datahub_cloud/sdk/assertion_input/column_assertion_constants.py +114 -0
  211. acryl_datahub_cloud/sdk/assertion_input/column_assertion_utils.py +284 -0
  212. acryl_datahub_cloud/sdk/assertion_input/column_metric_assertion_input.py +759 -0
  213. acryl_datahub_cloud/sdk/assertion_input/column_metric_constants.py +109 -0
  214. acryl_datahub_cloud/sdk/assertion_input/column_value_assertion_input.py +810 -0
  215. acryl_datahub_cloud/sdk/assertion_input/freshness_assertion_input.py +305 -0
  216. acryl_datahub_cloud/sdk/assertion_input/schema_assertion_input.py +413 -0
  217. acryl_datahub_cloud/sdk/assertion_input/smart_column_metric_assertion_input.py +793 -0
  218. acryl_datahub_cloud/sdk/assertion_input/smart_freshness_assertion_input.py +218 -0
  219. acryl_datahub_cloud/sdk/assertion_input/smart_sql_assertion_input.py +181 -0
  220. acryl_datahub_cloud/sdk/assertion_input/smart_volume_assertion_input.py +189 -0
  221. acryl_datahub_cloud/sdk/assertion_input/sql_assertion_input.py +320 -0
  222. acryl_datahub_cloud/sdk/assertion_input/volume_assertion_input.py +635 -0
  223. acryl_datahub_cloud/sdk/assertions_client.py +1074 -0
  224. acryl_datahub_cloud/sdk/entities/__init__.py +0 -0
  225. acryl_datahub_cloud/sdk/entities/assertion.py +439 -0
  226. acryl_datahub_cloud/sdk/entities/monitor.py +291 -0
  227. acryl_datahub_cloud/sdk/entities/subscription.py +100 -0
  228. acryl_datahub_cloud/sdk/errors.py +34 -0
  229. acryl_datahub_cloud/sdk/resolver_client.py +42 -0
  230. acryl_datahub_cloud/sdk/subscription_client.py +737 -0
  231. {acryl_datahub_cloud-0.3.11rc0.dist-info → acryl_datahub_cloud-0.3.16.1rc0.dist-info}/METADATA +55 -49
  232. {acryl_datahub_cloud-0.3.11rc0.dist-info → acryl_datahub_cloud-0.3.16.1rc0.dist-info}/RECORD +235 -142
  233. {acryl_datahub_cloud-0.3.11rc0.dist-info → acryl_datahub_cloud-0.3.16.1rc0.dist-info}/WHEEL +1 -1
  234. {acryl_datahub_cloud-0.3.11rc0.dist-info → acryl_datahub_cloud-0.3.16.1rc0.dist-info}/entry_points.txt +1 -0
  235. acryl_datahub_cloud/_sdk_extras/__init__.py +0 -4
  236. acryl_datahub_cloud/_sdk_extras/assertion.py +0 -15
  237. acryl_datahub_cloud/_sdk_extras/assertions_client.py +0 -23
  238. {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,759 @@
1
+ from datetime import datetime
2
+ from typing import TYPE_CHECKING, Optional, Union
3
+
4
+ if TYPE_CHECKING:
5
+ pass
6
+
7
+ from acryl_datahub_cloud.sdk.assertion_input.assertion_input import (
8
+ DEFAULT_DAILY_SCHEDULE,
9
+ HIGH_WATERMARK_ALLOWED_FIELD_TYPES,
10
+ NO_PARAMETER_OPERATORS,
11
+ RANGE_OPERATORS,
12
+ SINGLE_VALUE_OPERATORS,
13
+ AssertionIncidentBehaviorInputTypes,
14
+ AssertionInfoInputType,
15
+ DetectionMechanismInputTypes,
16
+ FieldSpecType,
17
+ _AllRowsQuery,
18
+ _AllRowsQueryDataHubDatasetProfile,
19
+ _AssertionInput,
20
+ _ChangedRowsQuery,
21
+ _DatasetProfile,
22
+ _try_parse_and_validate_schema_classes_enum,
23
+ get_gms_type_if_criteria_unchanged,
24
+ get_gms_types_if_criteria_unchanged,
25
+ )
26
+ from acryl_datahub_cloud.sdk.assertion_input.column_assertion_utils import (
27
+ _is_no_parameter_operator,
28
+ _is_range_required_for_operator,
29
+ _is_value_required_for_operator,
30
+ _try_parse_and_validate_range,
31
+ _try_parse_and_validate_range_type,
32
+ _try_parse_and_validate_value,
33
+ _try_parse_and_validate_value_type,
34
+ )
35
+ from acryl_datahub_cloud.sdk.assertion_input.column_metric_constants import (
36
+ ALLOWED_COLUMN_TYPES_FOR_COLUMN_METRIC_ASSERTION,
37
+ FIELD_METRIC_TYPE_CONFIG,
38
+ FIELD_VALUES_OPERATOR_CONFIG,
39
+ MetricInputType,
40
+ OperatorInputType,
41
+ RangeInputType,
42
+ RangeTypeInputType,
43
+ ValueInputType,
44
+ ValueType,
45
+ ValueTypeInputType,
46
+ )
47
+ from acryl_datahub_cloud.sdk.entities.assertion import TagsInputType
48
+ from acryl_datahub_cloud.sdk.errors import (
49
+ SDKNotYetSupportedError,
50
+ SDKUsageError,
51
+ )
52
+ from datahub.metadata import schema_classes as models
53
+ from datahub.metadata.urns import AssertionUrn, CorpUserUrn, DatasetUrn
54
+ from datahub.sdk.entity_client import EntityClient
55
+
56
+ # New unified criteria parameters type
57
+ ColumnMetricAssertionParameters = Union[
58
+ None, # For operators that don't require parameters (NULL, NOT_NULL)
59
+ ValueInputType, # Single value
60
+ RangeInputType, # Range as tuple
61
+ ]
62
+
63
+ DEFAULT_DETECTION_MECHANISM_COLUMN_METRIC_ASSERTION: _AllRowsQuery = _AllRowsQuery()
64
+
65
+
66
+ class _ColumnMetricAssertionInput(_AssertionInput):
67
+ """
68
+ Input used to create a column metric assertion.
69
+
70
+ This assertion is used to validate the value of a common field / column metric (e.g. aggregation) such as null count + percentage,
71
+ min, max, median, and more.
72
+
73
+ Example using the entity models, not comprehensive for all options:
74
+
75
+ ```python
76
+ models.AssertionInfoClass(
77
+ type=models.AssertionTypeClass.FIELD,
78
+ fieldAssertion=FieldAssertionInfoClass(
79
+ type=models.FieldAssertionTypeClass.FIELD_METRIC,
80
+ entity=str(self.dataset_urn),
81
+ filter=DatasetFilterClass(
82
+ type=models.DatasetFilterTypeClass.SQL,
83
+ sql="SELECT * FROM dataset WHERE column_name = 'value'", # Example filter
84
+ ),
85
+ fieldMetricAssertion=FieldMetricAssertionClass(
86
+ field=SchemaFieldSpecClass(
87
+ path="column_name", # The column name to validate
88
+ type="string", # The type of the column
89
+ nativeType="string", # The native type of the column
90
+ ),
91
+ metric=models.FieldMetricTypeClass.NULL_COUNT_PERCENTAGE, # The metric to validate
92
+ operator=models.AssertionStdOperatorClass.GREATER_THAN, # The operator to use
93
+ parameters=models.AssertionStdParametersClass(
94
+ value=models.AssertionStdParameterClass(
95
+ value=10, # The value to validate
96
+ type=models.AssertionStdParameterTypeClass.NUMBER, # The type of the value
97
+ ),
98
+ ),
99
+ ),
100
+ ),
101
+ source=models.AssertionSourceClass(
102
+ type=models.AssertionSourceTypeClass.NATIVE, # Column metric assertions are of type native
103
+ created=AuditStampClass(
104
+ time=1717929600,
105
+ actor="urn:li:corpuser:jdoe", # The actor who created the assertion
106
+ ),
107
+ ),
108
+ lastUpdated=AuditStampClass(
109
+ time=1717929600,
110
+ actor="urn:li:corpuser:jdoe", # The actor who last updated the assertion
111
+ ),
112
+ description="This assertion validates the null count percentage of the column 'column_name' is greater than 10.", # Optional description of the assertion
113
+ )
114
+ ```
115
+
116
+ ```python
117
+ models.MonitorInfoClass(
118
+ type=models.MonitorTypeClass.ASSERTION,
119
+ status=models.MonitorStatusClass(
120
+ mode=models.MonitorModeClass.ACTIVE, # Active or Inactive
121
+ ),
122
+ assertionMonitor=AssertionMonitorClass(
123
+ assertions=AssertionEvaluationSpecClass(
124
+ assertion="urn:li:assertion:123", # The assertion to monitor
125
+ schedule=models.CronScheduleClass(
126
+ cron="0 0 * * *", # The cron schedule
127
+ timezone="America/New_York", # The timezone
128
+ ),
129
+ parameters=models.AssertionEvaluationParametersClass(
130
+ type=models.AssertionEvaluationParametersTypeClass.DATASET_FIELD,
131
+ datasetFieldParameters=models.DatasetFieldAssertionParametersClass(
132
+ sourceType=models.DatasetFieldAssertionSourceTypeClass.CHANGED_ROWS_QUERY, # This can be ALL_ROWS_QUERY, CHANGED_ROWS_QUERY or DATAHUB_DATASET_PROFILE
133
+ changedRowsField=models.FreshnessFieldSpecClass(
134
+ path="column_name",
135
+ type="string",
136
+ nativeType="string",
137
+ kind=models.FreshnessFieldKindClass.HIGH_WATERMARK, # This can be LAST_MODIFIED or HIGH_WATERMARK
138
+ ),
139
+ ),
140
+ ),
141
+ ),
142
+ ),
143
+ )
144
+ ```
145
+ """
146
+
147
+ def __init__(
148
+ self,
149
+ *,
150
+ # Required parameters
151
+ dataset_urn: Union[str, DatasetUrn],
152
+ entity_client: EntityClient,
153
+ column_name: str,
154
+ metric_type: MetricInputType,
155
+ operator: OperatorInputType,
156
+ # Criteria parameters
157
+ criteria_parameters: Optional[ColumnMetricAssertionParameters] = None,
158
+ urn: Optional[Union[str, AssertionUrn]] = None,
159
+ display_name: Optional[str] = None,
160
+ enabled: bool = True,
161
+ schedule: Optional[Union[str, models.CronScheduleClass]] = None,
162
+ detection_mechanism: DetectionMechanismInputTypes = None,
163
+ incident_behavior: Optional[AssertionIncidentBehaviorInputTypes] = None,
164
+ tags: Optional[TagsInputType] = None,
165
+ created_by: Union[str, CorpUserUrn],
166
+ created_at: datetime,
167
+ updated_by: Union[str, CorpUserUrn],
168
+ updated_at: datetime,
169
+ gms_criteria_type_info: Optional[tuple] = None,
170
+ ):
171
+ """
172
+ Initialize a column metric assertion input.
173
+
174
+ Args:
175
+ dataset_urn: The dataset urn.
176
+ entity_client: The entity client.
177
+ column_name: The name of the column to validate.
178
+ metric_type: The metric type to validate.
179
+ operator: The operator to use.
180
+ criteria_parameters: The criteria parameters (single value, range tuple, or None). Type will be automatically inferred.
181
+ urn: The urn of the assertion.
182
+ display_name: The display name of the assertion.
183
+ enabled: Whether the assertion is enabled.
184
+ schedule: The schedule of the assertion.
185
+ detection_mechanism: The detection mechanism of the assertion.
186
+ incident_behavior: The incident behavior of the assertion. Accepts strings, enum values, lists, or None.
187
+ tags: The tags of the assertion.
188
+ created_by: The creator of the assertion.
189
+ created_at: The creation time of the assertion.
190
+ updated_by: The updater of the assertion.
191
+ updated_at: The update time of the assertion.
192
+ """
193
+ # Parent will handle validation of common parameters:
194
+ _AssertionInput.__init__(
195
+ self,
196
+ dataset_urn=dataset_urn,
197
+ entity_client=entity_client,
198
+ urn=urn,
199
+ display_name=display_name,
200
+ enabled=enabled,
201
+ schedule=schedule,
202
+ detection_mechanism=detection_mechanism,
203
+ incident_behavior=incident_behavior,
204
+ tags=tags,
205
+ source_type=models.AssertionSourceTypeClass.NATIVE, # Column metric assertions are of type native
206
+ created_by=created_by,
207
+ created_at=created_at,
208
+ updated_by=updated_by,
209
+ updated_at=updated_at,
210
+ default_detection_mechanism=DEFAULT_DETECTION_MECHANISM_COLUMN_METRIC_ASSERTION,
211
+ )
212
+
213
+ # Column metric assertions (non-smart) don't use exclusion_windows, sensitivity or training_data_lookback_days
214
+
215
+ # Validate Column Metric Assertion specific parameters
216
+ self.metric_type = _try_parse_and_validate_schema_classes_enum(
217
+ metric_type, models.FieldMetricTypeClass
218
+ )
219
+ self.column_name = self._try_parse_and_validate_column_name_is_valid_type(
220
+ column_name
221
+ )
222
+ self.operator = _try_parse_and_validate_schema_classes_enum(
223
+ operator, models.AssertionStdOperatorClass
224
+ )
225
+
226
+ # Initialize instance variables with proper type annotations
227
+ self.criteria_parameters: Optional[ColumnMetricAssertionParameters] = None
228
+ self.criteria_type: Optional[Union[ValueTypeInputType, RangeTypeInputType]] = (
229
+ None
230
+ )
231
+
232
+ # Process criteria parameters with GMS type information if available
233
+ if gms_criteria_type_info is not None:
234
+ self._process_criteria_parameters_with_gms_type(
235
+ criteria_parameters, gms_criteria_type_info
236
+ )
237
+ else:
238
+ self._process_criteria_parameters(criteria_parameters)
239
+
240
+ # Validate compatibility:
241
+ self._validate_field_type_and_operator_compatibility(
242
+ self.column_name, self.operator
243
+ )
244
+ self._validate_field_type_and_metric_type_compatibility(
245
+ self.column_name, self.metric_type
246
+ )
247
+
248
+ def _infer_criteria_type_from_parameters(
249
+ self,
250
+ criteria_parameters: Optional[ColumnMetricAssertionParameters],
251
+ ) -> Optional[Union[ValueTypeInputType, RangeTypeInputType]]:
252
+ """
253
+ Infer the criteria type from the parameters based on Python types.
254
+
255
+ Args:
256
+ criteria_parameters: The criteria parameters to infer type from.
257
+
258
+ Returns:
259
+ The inferred type(s) for the criteria parameters.
260
+ """
261
+ if criteria_parameters is None:
262
+ return None
263
+
264
+ if isinstance(criteria_parameters, tuple):
265
+ # Range parameters - infer type for each value
266
+ if len(criteria_parameters) != 2:
267
+ raise SDKUsageError(
268
+ "Range parameters must be a tuple of exactly 2 values"
269
+ )
270
+
271
+ type1 = self._infer_single_value_type(criteria_parameters[0])
272
+ type2 = self._infer_single_value_type(criteria_parameters[1])
273
+ return (type1, type2)
274
+ else:
275
+ # Single value parameter
276
+ return self._infer_single_value_type(criteria_parameters)
277
+
278
+ def _infer_single_value_type(self, value: ValueInputType) -> ValueTypeInputType:
279
+ """
280
+ Infer the type of a single value based on its Python type.
281
+
282
+ Args:
283
+ value: The value to infer type from.
284
+
285
+ Returns:
286
+ The inferred ValueType.
287
+ """
288
+ if isinstance(value, (int, float)):
289
+ return ValueType.NUMBER
290
+ elif isinstance(value, str):
291
+ return ValueType.STRING
292
+ else:
293
+ # Default fallback
294
+ return ValueType.UNKNOWN
295
+
296
+ def _process_criteria_parameters_with_gms_type(
297
+ self,
298
+ criteria_parameters: Optional[ColumnMetricAssertionParameters],
299
+ gms_type_info: Optional[tuple],
300
+ ) -> None:
301
+ """Process criteria_parameters, using GMS type only if criteria is unchanged."""
302
+ if criteria_parameters is None:
303
+ self._process_none_parameters()
304
+ elif isinstance(criteria_parameters, tuple):
305
+ # Only use GMS types if the user hasn't changed the criteria values
306
+ explicit_types = get_gms_types_if_criteria_unchanged(
307
+ criteria_parameters, gms_type_info
308
+ )
309
+ if explicit_types:
310
+ self._process_range_parameters_with_types(
311
+ criteria_parameters, explicit_types
312
+ )
313
+ else:
314
+ self._process_range_parameters(criteria_parameters)
315
+ else:
316
+ # Only use GMS type if the user hasn't changed the criteria value
317
+ explicit_type = get_gms_type_if_criteria_unchanged(
318
+ criteria_parameters, gms_type_info
319
+ )
320
+ if explicit_type:
321
+ self._process_single_value_parameters_with_type(
322
+ criteria_parameters, explicit_type
323
+ )
324
+ else:
325
+ self._process_single_value_parameters(criteria_parameters)
326
+
327
+ def _process_criteria_parameters(
328
+ self,
329
+ criteria_parameters: Optional[ColumnMetricAssertionParameters],
330
+ ) -> None:
331
+ """Process the new consolidated criteria_parameters with automatic type inference."""
332
+ if criteria_parameters is None:
333
+ self._process_none_parameters()
334
+ elif isinstance(criteria_parameters, tuple):
335
+ self._process_range_parameters(criteria_parameters)
336
+ else:
337
+ self._process_single_value_parameters(criteria_parameters)
338
+
339
+ def _process_none_parameters(self) -> None:
340
+ """Process None criteria_parameters."""
341
+ # No parameters - validation is now handled at the client level
342
+ # This allows both creation and update scenarios to be handled appropriately
343
+ self.criteria_parameters = None
344
+ self.criteria_type = None
345
+
346
+ def _process_range_parameters(self, criteria_parameters: tuple) -> None:
347
+ """Process tuple criteria_parameters for range operators."""
348
+ # Range parameters
349
+ if not _is_range_required_for_operator(self.operator):
350
+ raise SDKUsageError(
351
+ f"Operator {self.operator} does not support range parameters. "
352
+ "Provide a single value instead of a tuple."
353
+ )
354
+
355
+ # Infer range type automatically
356
+ inferred_range_type = self._infer_criteria_type_from_parameters(
357
+ criteria_parameters
358
+ )
359
+
360
+ # Validate and parse the range type
361
+ validated_range_type = _try_parse_and_validate_range_type(inferred_range_type)
362
+
363
+ # Validate and parse the range values
364
+ validated_range = _try_parse_and_validate_range(
365
+ criteria_parameters, validated_range_type, self.operator
366
+ )
367
+
368
+ # Store validated parameters
369
+ self.criteria_parameters = validated_range
370
+ self.criteria_type = validated_range_type
371
+
372
+ def _process_single_value_parameters(
373
+ self, criteria_parameters: Union[str, int, float]
374
+ ) -> None:
375
+ """Process single value criteria_parameters."""
376
+ # Single value parameters
377
+ if _is_no_parameter_operator(self.operator):
378
+ raise SDKUsageError(
379
+ f"Value parameters should not be provided for operator {self.operator}"
380
+ )
381
+ if not _is_value_required_for_operator(self.operator):
382
+ raise SDKUsageError(
383
+ f"Operator {self.operator} does not support value parameters. "
384
+ "Use criteria_parameters=None or omit criteria_parameters."
385
+ )
386
+
387
+ # Infer value type automatically
388
+ inferred_value_type = self._infer_criteria_type_from_parameters(
389
+ criteria_parameters
390
+ )
391
+
392
+ # Validate value if required
393
+ if _is_value_required_for_operator(self.operator):
394
+ # Validate and parse the value type - make sure it's a single type, not a tuple
395
+ if isinstance(inferred_value_type, tuple):
396
+ raise SDKUsageError("Single value type expected, not a tuple type")
397
+
398
+ validated_value_type = _try_parse_and_validate_value_type(
399
+ inferred_value_type
400
+ )
401
+ validated_value = _try_parse_and_validate_value(
402
+ criteria_parameters, validated_value_type
403
+ )
404
+
405
+ # Store validated parameters
406
+ self.criteria_parameters = validated_value
407
+ self.criteria_type = validated_value_type
408
+ else:
409
+ # Store raw parameters for operators that don't require validation
410
+ self.criteria_parameters = criteria_parameters
411
+ self.criteria_type = inferred_value_type
412
+
413
+ def _process_single_value_parameters_with_type(
414
+ self,
415
+ criteria_parameters: Union[str, int, float],
416
+ gms_type: models.AssertionStdParameterTypeClass,
417
+ ) -> None:
418
+ """Process single value criteria_parameters using explicit GMS type information."""
419
+ # Single value parameters
420
+ if _is_no_parameter_operator(self.operator):
421
+ raise SDKUsageError(
422
+ f"Value parameters should not be provided for operator {self.operator}"
423
+ )
424
+ if not _is_value_required_for_operator(self.operator):
425
+ raise SDKUsageError(
426
+ f"Operator {self.operator} does not support value parameters. "
427
+ "Use criteria_parameters=None or omit criteria_parameters."
428
+ )
429
+
430
+ # Use GMS type instead of inferring
431
+ validated_value_type = _try_parse_and_validate_value_type(gms_type)
432
+ validated_value = _try_parse_and_validate_value(
433
+ criteria_parameters, validated_value_type
434
+ )
435
+
436
+ # Store validated parameters
437
+ self.criteria_parameters = validated_value
438
+ self.criteria_type = validated_value_type
439
+
440
+ def _process_range_parameters_with_types(
441
+ self,
442
+ criteria_parameters: tuple,
443
+ gms_types: tuple,
444
+ ) -> None:
445
+ """Process range criteria_parameters using explicit GMS type information."""
446
+ # Range parameters with GMS types
447
+ if _is_no_parameter_operator(self.operator):
448
+ raise SDKUsageError(
449
+ f"Range parameters should not be provided for operator {self.operator}"
450
+ )
451
+ if not _is_range_required_for_operator(self.operator):
452
+ raise SDKUsageError(
453
+ f"Operator {self.operator} does not support range parameters. "
454
+ "Use a single value or criteria_parameters=None."
455
+ )
456
+
457
+ if len(criteria_parameters) != 2:
458
+ raise SDKUsageError("Range parameters must be a tuple of exactly 2 values")
459
+
460
+ min_value, max_value = criteria_parameters
461
+ min_type, max_type = gms_types
462
+
463
+ # Use GMS types instead of inferring
464
+ validated_min_type = _try_parse_and_validate_value_type(min_type)
465
+ validated_max_type = _try_parse_and_validate_value_type(max_type)
466
+
467
+ validated_min_value = _try_parse_and_validate_value(
468
+ min_value, validated_min_type
469
+ )
470
+ validated_max_value = _try_parse_and_validate_value(
471
+ max_value, validated_max_type
472
+ )
473
+
474
+ # Store validated parameters
475
+ self.criteria_parameters = (validated_min_value, validated_max_value)
476
+ self.criteria_type = (validated_min_type, validated_max_type)
477
+
478
+ def _create_monitor_info(
479
+ self,
480
+ assertion_urn: AssertionUrn,
481
+ status: models.MonitorStatusClass,
482
+ schedule: models.CronScheduleClass,
483
+ ) -> models.MonitorInfoClass:
484
+ """
485
+ Create a MonitorInfoClass with all the necessary components.
486
+ """
487
+ source_type, field = self._convert_assertion_source_type_and_field()
488
+ return models.MonitorInfoClass(
489
+ type=models.MonitorTypeClass.ASSERTION,
490
+ status=status,
491
+ assertionMonitor=models.AssertionMonitorClass(
492
+ assertions=[
493
+ models.AssertionEvaluationSpecClass(
494
+ assertion=str(assertion_urn),
495
+ schedule=schedule,
496
+ parameters=self._get_assertion_evaluation_parameters(
497
+ str(source_type), field
498
+ ),
499
+ ),
500
+ ],
501
+ settings=None,
502
+ ),
503
+ )
504
+
505
+ def _create_assertion_info(
506
+ self, filter: Optional[models.DatasetFilterClass]
507
+ ) -> AssertionInfoInputType:
508
+ """
509
+ Create a FieldAssertionInfoClass for a column metric assertion.
510
+
511
+ Args:
512
+ filter: Optional filter to apply to the assertion.
513
+
514
+ Returns:
515
+ A FieldAssertionInfoClass configured for column metric.
516
+ """
517
+ # Get the field spec for the column
518
+ field_spec = self._get_schema_field_spec(self.column_name)
519
+
520
+ # Create the field metric assertion
521
+ field_metric_assertion = models.FieldMetricAssertionClass(
522
+ field=field_spec,
523
+ metric=self.metric_type,
524
+ operator=self.operator,
525
+ parameters=self._create_assertion_parameters(),
526
+ )
527
+
528
+ # Create the field assertion info
529
+ return models.FieldAssertionInfoClass(
530
+ type=models.FieldAssertionTypeClass.FIELD_METRIC,
531
+ entity=str(self.dataset_urn),
532
+ filter=filter,
533
+ fieldMetricAssertion=field_metric_assertion,
534
+ fieldValuesAssertion=None, # Explicitly set to None since this is a field metric assertion
535
+ )
536
+
537
+ def _convert_schedule(self) -> models.CronScheduleClass:
538
+ """
539
+ Create a schedule for a column metric assertion.
540
+
541
+ Returns:
542
+ A CronScheduleClass with appropriate schedule settings.
543
+ """
544
+ if self.schedule is None:
545
+ return DEFAULT_DAILY_SCHEDULE
546
+
547
+ return models.CronScheduleClass(
548
+ cron=self.schedule.cron,
549
+ timezone=self.schedule.timezone,
550
+ )
551
+
552
+ def _convert_schema_field_spec_to_freshness_field_spec(
553
+ self, field_spec: models.SchemaFieldSpecClass
554
+ ) -> models.FreshnessFieldSpecClass:
555
+ """
556
+ Convert a SchemaFieldSpecClass to a FreshnessFieldSpecClass.
557
+ """
558
+ return models.FreshnessFieldSpecClass(
559
+ path=field_spec.path,
560
+ type=field_spec.type,
561
+ nativeType=field_spec.nativeType,
562
+ kind=models.FreshnessFieldKindClass.HIGH_WATERMARK,
563
+ )
564
+
565
+ def _get_assertion_evaluation_parameters(
566
+ self, source_type: str, field: Optional[FieldSpecType]
567
+ ) -> models.AssertionEvaluationParametersClass:
568
+ """
569
+ Get evaluation parameters for a column metric assertion.
570
+ Converts SchemaFieldSpecClass to FreshnessFieldSpecClass if needed.
571
+ """
572
+ if field is not None:
573
+ if isinstance(field, models.SchemaFieldSpecClass):
574
+ field = self._convert_schema_field_spec_to_freshness_field_spec(field)
575
+ assert isinstance(field, models.FreshnessFieldSpecClass), (
576
+ "Field must be FreshnessFieldSpecClass for monitor info"
577
+ )
578
+ return models.AssertionEvaluationParametersClass(
579
+ type=models.AssertionEvaluationParametersTypeClass.DATASET_FIELD,
580
+ datasetFieldParameters=models.DatasetFieldAssertionParametersClass(
581
+ sourceType=source_type,
582
+ changedRowsField=field,
583
+ ),
584
+ )
585
+
586
+ def _convert_assertion_source_type_and_field(
587
+ self,
588
+ ) -> tuple[str, Optional[FieldSpecType]]:
589
+ """
590
+ Convert detection mechanism into source type and field specification for column metric assertions.
591
+
592
+ Returns:
593
+ A tuple of (source_type, field) where field may be None.
594
+ Note that the source_type is a string, not a models.DatasetFieldAssertionSourceTypeClass (or other assertion source type) since
595
+ the source type is not a enum in the code generated from the DatasetFieldSourceType enum in the PDL.
596
+
597
+ Raises:
598
+ SDKNotYetSupportedError: If the detection mechanism is not supported.
599
+ SDKUsageError: If the field (column) is not found in the dataset,
600
+ and the detection mechanism requires a field. Also if the field
601
+ is not an allowed type for the detection mechanism.
602
+ """
603
+ source_type = models.DatasetFieldAssertionSourceTypeClass.ALL_ROWS_QUERY
604
+ field = None
605
+ SUPPORTED_DETECTION_MECHANISMS = [
606
+ _AllRowsQuery().type,
607
+ _AllRowsQueryDataHubDatasetProfile().type,
608
+ _ChangedRowsQuery(column_name="").type,
609
+ ]
610
+
611
+ if isinstance(self.detection_mechanism, _ChangedRowsQuery):
612
+ source_type = models.DatasetFieldAssertionSourceTypeClass.CHANGED_ROWS_QUERY
613
+ column_name = self._try_parse_and_validate_column_name_is_valid_type(
614
+ self.detection_mechanism.column_name, # The high watermark column name
615
+ allowed_column_types=HIGH_WATERMARK_ALLOWED_FIELD_TYPES,
616
+ )
617
+ field = self._get_schema_field_spec(column_name)
618
+ elif isinstance(self.detection_mechanism, _AllRowsQuery):
619
+ source_type = models.DatasetFieldAssertionSourceTypeClass.ALL_ROWS_QUERY
620
+ # For query-based detection, we don't need a field specification
621
+ # as the query itself defines what data to analyze
622
+ elif isinstance(
623
+ self.detection_mechanism,
624
+ (_AllRowsQueryDataHubDatasetProfile, _DatasetProfile),
625
+ ):
626
+ source_type = (
627
+ models.DatasetFieldAssertionSourceTypeClass.DATAHUB_DATASET_PROFILE
628
+ )
629
+ # Note: This is only valid on the all rows query
630
+ else:
631
+ raise SDKNotYetSupportedError(
632
+ f"Detection mechanism {self.detection_mechanism} is not supported for column metric assertions, please use a supported detection mechanism: {', '.join(SUPPORTED_DETECTION_MECHANISMS)}"
633
+ )
634
+
635
+ return source_type, field
636
+
637
+ def _create_assertion_parameters(self) -> models.AssertionStdParametersClass:
638
+ """
639
+ Create assertion parameters based on the operator type and provided values.
640
+
641
+ Returns:
642
+ An AssertionStdParametersClass with the appropriate parameters.
643
+
644
+ Raises:
645
+ SDKUsageError: If the parameters are invalid for the operator type.
646
+ """
647
+ if self.operator in SINGLE_VALUE_OPERATORS:
648
+ if self.criteria_parameters is None or isinstance(
649
+ self.criteria_parameters, tuple
650
+ ):
651
+ raise SDKUsageError(
652
+ f"Single value is required for operator {self.operator}"
653
+ )
654
+ if self.criteria_type is None or isinstance(self.criteria_type, tuple):
655
+ raise SDKUsageError(
656
+ f"Single value type is required for operator {self.operator}"
657
+ )
658
+ return models.AssertionStdParametersClass(
659
+ value=models.AssertionStdParameterClass(
660
+ value=str(self.criteria_parameters),
661
+ type=self.criteria_type,
662
+ ),
663
+ )
664
+ elif self.operator in RANGE_OPERATORS:
665
+ if not isinstance(self.criteria_parameters, tuple):
666
+ raise SDKUsageError(
667
+ f"Range parameters are required for operator {self.operator}"
668
+ )
669
+ if not isinstance(self.criteria_type, tuple):
670
+ raise SDKUsageError(
671
+ f"Range type is required for operator {self.operator}"
672
+ )
673
+ return models.AssertionStdParametersClass(
674
+ minValue=models.AssertionStdParameterClass(
675
+ value=str(self.criteria_parameters[0]),
676
+ type=self.criteria_type[0],
677
+ ),
678
+ maxValue=models.AssertionStdParameterClass(
679
+ value=str(self.criteria_parameters[1]),
680
+ type=self.criteria_type[1],
681
+ ),
682
+ )
683
+ elif self.operator in NO_PARAMETER_OPERATORS:
684
+ return models.AssertionStdParametersClass()
685
+ else:
686
+ raise SDKUsageError(f"Unsupported operator type: {self.operator}")
687
+
688
+ def _try_parse_and_validate_column_name_is_valid_type(
689
+ self,
690
+ column_name: str,
691
+ allowed_column_types: list[
692
+ models.DictWrapper
693
+ ] = ALLOWED_COLUMN_TYPES_FOR_COLUMN_METRIC_ASSERTION,
694
+ ) -> str:
695
+ """
696
+ Parse and validate a column name. Determine from the field spec if the column exists and is of the appropriate type for the metric type.
697
+ Validate that this is a column that is valid for the metric type, see also getEligibleFieldColumns and related functions in the frontend
698
+ """
699
+ field_spec = self._get_schema_field_spec(column_name)
700
+ self._validate_field_type(
701
+ field_spec,
702
+ column_name,
703
+ allowed_column_types,
704
+ "column metric assertion",
705
+ )
706
+ return column_name
707
+
708
+ def _assertion_type(self) -> str:
709
+ """Get the assertion type."""
710
+ return models.AssertionTypeClass.FIELD
711
+
712
+ def _validate_field_type_and_operator_compatibility(
713
+ self, column_name: str, operator: models.AssertionStdOperatorClass
714
+ ) -> None:
715
+ """Validate that the field type is compatible with the operator.
716
+
717
+ See FIELD_VALUES_OPERATOR_CONFIG in the frontend for the allowed operators for each field type.
718
+
719
+ Args:
720
+ column_name: The name of the column to validate.
721
+ operator: The operator to validate against.
722
+
723
+ Raises:
724
+ SDKUsageError: If the field type is not compatible with the operator.
725
+ """
726
+ field_spec = self._get_schema_field_spec(column_name)
727
+ allowed_operators = FIELD_VALUES_OPERATOR_CONFIG.get(field_spec.type, [])
728
+ if operator not in allowed_operators:
729
+ raise SDKUsageError(
730
+ f"Operator {operator} is not allowed for field type {field_spec.type} for column '{column_name}'. Allowed operators: {', '.join(str(op) for op in allowed_operators)}"
731
+ )
732
+
733
+ def _validate_field_type_and_metric_type_compatibility(
734
+ self, column_name: str, metric_type: models.FieldMetricTypeClass
735
+ ) -> None:
736
+ """Validate that the metric type is compatible with the field type.
737
+
738
+ See FIELD_METRIC_TYPE_CONFIG in the frontend for the allowed metric types for each field type.
739
+
740
+ Args:
741
+ column_name: The name of the column to validate.
742
+ metric_type: The metric type to validate.
743
+
744
+ Raises:
745
+ SDKUsageError: If the metric type is not compatible with the field type.
746
+ """
747
+ field_spec = self._get_schema_field_spec(column_name)
748
+ field_type = field_spec.type
749
+
750
+ if field_type not in FIELD_METRIC_TYPE_CONFIG:
751
+ raise SDKUsageError(
752
+ f"Column {column_name} is of type {field_type}, which is not supported for column metric assertions"
753
+ )
754
+
755
+ allowed_metric_types = FIELD_METRIC_TYPE_CONFIG[field_type]
756
+ if metric_type not in allowed_metric_types:
757
+ raise SDKUsageError(
758
+ f"Metric type {metric_type} is not allowed for field type {field_type}. Allowed metric types: {', '.join(str(mt) for mt in allowed_metric_types)}"
759
+ )