acryl-datahub-cloud 0.3.12rc5__py3-none-any.whl → 0.3.12rc6__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/datahub_forms_notifications/get_feature_flag.gql +7 -0
- acryl_datahub_cloud/sdk/__init__.py +6 -0
- acryl_datahub_cloud/sdk/assertion/assertion_base.py +170 -3
- acryl_datahub_cloud/sdk/assertion/types.py +2 -0
- acryl_datahub_cloud/sdk/assertion_input/assertion_input.py +36 -11
- acryl_datahub_cloud/sdk/assertion_input/freshness_assertion_input.py +1 -2
- acryl_datahub_cloud/sdk/assertion_input/smart_column_metric_assertion_input.py +4 -31
- acryl_datahub_cloud/sdk/assertion_input/sql_assertion_input.py +274 -0
- acryl_datahub_cloud/sdk/assertions_client.py +450 -0
- {acryl_datahub_cloud-0.3.12rc5.dist-info → acryl_datahub_cloud-0.3.12rc6.dist-info}/METADATA +36 -36
- {acryl_datahub_cloud-0.3.12rc5.dist-info → acryl_datahub_cloud-0.3.12rc6.dist-info}/RECORD +15 -13
- {acryl_datahub_cloud-0.3.12rc5.dist-info → acryl_datahub_cloud-0.3.12rc6.dist-info}/WHEEL +0 -0
- {acryl_datahub_cloud-0.3.12rc5.dist-info → acryl_datahub_cloud-0.3.12rc6.dist-info}/entry_points.txt +0 -0
- {acryl_datahub_cloud-0.3.12rc5.dist-info → acryl_datahub_cloud-0.3.12rc6.dist-info}/top_level.txt +0 -0
|
@@ -9,6 +9,7 @@ from acryl_datahub_cloud.sdk.assertion.assertion_base import (
|
|
|
9
9
|
FreshnessAssertion,
|
|
10
10
|
SmartFreshnessAssertion,
|
|
11
11
|
SmartVolumeAssertion,
|
|
12
|
+
SqlAssertion,
|
|
12
13
|
_AssertionPublic,
|
|
13
14
|
)
|
|
14
15
|
from acryl_datahub_cloud.sdk.assertion.smart_column_metric_assertion import (
|
|
@@ -36,6 +37,10 @@ from acryl_datahub_cloud.sdk.assertion_input.smart_column_metric_assertion_input
|
|
|
36
37
|
ValueTypeInputType,
|
|
37
38
|
_SmartColumnMetricAssertionInput,
|
|
38
39
|
)
|
|
40
|
+
from acryl_datahub_cloud.sdk.assertion_input.sql_assertion_input import (
|
|
41
|
+
SqlAssertionCriteria,
|
|
42
|
+
_SqlAssertionInput,
|
|
43
|
+
)
|
|
39
44
|
from acryl_datahub_cloud.sdk.entities.assertion import Assertion, TagsInputType
|
|
40
45
|
from acryl_datahub_cloud.sdk.entities.monitor import Monitor
|
|
41
46
|
from acryl_datahub_cloud.sdk.errors import SDKUsageError
|
|
@@ -489,6 +494,87 @@ class AssertionsClient:
|
|
|
489
494
|
|
|
490
495
|
return merged_assertion_input
|
|
491
496
|
|
|
497
|
+
def _retrieve_and_merge_sql_assertion_and_monitor(
|
|
498
|
+
self,
|
|
499
|
+
assertion_input: _SqlAssertionInput,
|
|
500
|
+
dataset_urn: Union[str, DatasetUrn],
|
|
501
|
+
urn: Union[str, AssertionUrn],
|
|
502
|
+
display_name: Optional[str],
|
|
503
|
+
enabled: Optional[bool],
|
|
504
|
+
criteria: SqlAssertionCriteria,
|
|
505
|
+
statement: str,
|
|
506
|
+
incident_behavior: Optional[
|
|
507
|
+
Union[AssertionIncidentBehavior, list[AssertionIncidentBehavior]]
|
|
508
|
+
],
|
|
509
|
+
tags: Optional[TagsInputType],
|
|
510
|
+
updated_by: Optional[Union[str, CorpUserUrn]],
|
|
511
|
+
now_utc: datetime,
|
|
512
|
+
schedule: Optional[Union[str, models.CronScheduleClass]],
|
|
513
|
+
) -> Union[SqlAssertion, _SqlAssertionInput]:
|
|
514
|
+
# 1. Retrieve any existing assertion and monitor entities:
|
|
515
|
+
maybe_assertion_entity, monitor_urn, maybe_monitor_entity = (
|
|
516
|
+
self._retrieve_assertion_and_monitor(assertion_input)
|
|
517
|
+
)
|
|
518
|
+
|
|
519
|
+
# 2.1 If the assertion and monitor entities exist, create an assertion object from them:
|
|
520
|
+
if maybe_assertion_entity and maybe_monitor_entity:
|
|
521
|
+
existing_assertion = SqlAssertion._from_entities(
|
|
522
|
+
maybe_assertion_entity, maybe_monitor_entity
|
|
523
|
+
)
|
|
524
|
+
# 2.2 If the assertion exists but the monitor does not, create a placeholder monitor entity to be able to create the assertion:
|
|
525
|
+
elif maybe_assertion_entity and not maybe_monitor_entity:
|
|
526
|
+
monitor_mode = (
|
|
527
|
+
"ACTIVE" if enabled else "INACTIVE" if enabled is not None else "ACTIVE"
|
|
528
|
+
)
|
|
529
|
+
existing_assertion = SqlAssertion._from_entities(
|
|
530
|
+
maybe_assertion_entity,
|
|
531
|
+
Monitor(id=monitor_urn, info=("ASSERTION", monitor_mode)),
|
|
532
|
+
)
|
|
533
|
+
# 2.3 If the assertion does not exist, create a new assertion with a generated urn and return the assertion input:
|
|
534
|
+
elif not maybe_assertion_entity:
|
|
535
|
+
logger.info(
|
|
536
|
+
f"No existing assertion entity found for assertion urn {urn}, creating a new assertion with a generated urn"
|
|
537
|
+
)
|
|
538
|
+
return self._create_sql_assertion(
|
|
539
|
+
dataset_urn=dataset_urn,
|
|
540
|
+
display_name=display_name,
|
|
541
|
+
criteria=criteria,
|
|
542
|
+
statement=statement,
|
|
543
|
+
incident_behavior=incident_behavior,
|
|
544
|
+
tags=tags,
|
|
545
|
+
created_by=updated_by,
|
|
546
|
+
schedule=schedule,
|
|
547
|
+
)
|
|
548
|
+
|
|
549
|
+
# 3. Check for any issues e.g. different dataset urns
|
|
550
|
+
if (
|
|
551
|
+
existing_assertion
|
|
552
|
+
and hasattr(existing_assertion, "dataset_urn")
|
|
553
|
+
and existing_assertion.dataset_urn != assertion_input.dataset_urn
|
|
554
|
+
):
|
|
555
|
+
raise SDKUsageError(
|
|
556
|
+
f"Dataset URN mismatch, existing assertion: {existing_assertion.dataset_urn} != new assertion: {dataset_urn}"
|
|
557
|
+
)
|
|
558
|
+
|
|
559
|
+
# 4. Merge the existing assertion with the validated input:
|
|
560
|
+
merged_assertion_input = self._merge_sql_input(
|
|
561
|
+
dataset_urn=dataset_urn,
|
|
562
|
+
urn=urn,
|
|
563
|
+
display_name=display_name,
|
|
564
|
+
enabled=enabled,
|
|
565
|
+
criteria=criteria,
|
|
566
|
+
statement=statement,
|
|
567
|
+
incident_behavior=incident_behavior,
|
|
568
|
+
tags=tags,
|
|
569
|
+
now_utc=now_utc,
|
|
570
|
+
assertion_input=assertion_input,
|
|
571
|
+
maybe_assertion_entity=maybe_assertion_entity,
|
|
572
|
+
existing_assertion=existing_assertion,
|
|
573
|
+
schedule=schedule,
|
|
574
|
+
)
|
|
575
|
+
|
|
576
|
+
return merged_assertion_input
|
|
577
|
+
|
|
492
578
|
def _retrieve_assertion_and_monitor(
|
|
493
579
|
self,
|
|
494
580
|
assertion_input: _AssertionInput,
|
|
@@ -781,6 +867,112 @@ class AssertionsClient:
|
|
|
781
867
|
)
|
|
782
868
|
return merged_assertion_input
|
|
783
869
|
|
|
870
|
+
def _merge_sql_input(
|
|
871
|
+
self,
|
|
872
|
+
dataset_urn: Union[str, DatasetUrn],
|
|
873
|
+
urn: Union[str, AssertionUrn],
|
|
874
|
+
display_name: Optional[str],
|
|
875
|
+
enabled: Optional[bool],
|
|
876
|
+
criteria: SqlAssertionCriteria,
|
|
877
|
+
statement: str,
|
|
878
|
+
incident_behavior: Optional[
|
|
879
|
+
Union[AssertionIncidentBehavior, list[AssertionIncidentBehavior]]
|
|
880
|
+
],
|
|
881
|
+
tags: Optional[TagsInputType],
|
|
882
|
+
now_utc: datetime,
|
|
883
|
+
assertion_input: _SqlAssertionInput,
|
|
884
|
+
maybe_assertion_entity: Optional[Assertion],
|
|
885
|
+
# not used: maybe_monitor_entity: Optional[Monitor], as schedule is already set in existing_assertion
|
|
886
|
+
existing_assertion: SqlAssertion,
|
|
887
|
+
schedule: Optional[Union[str, models.CronScheduleClass]],
|
|
888
|
+
) -> _SqlAssertionInput:
|
|
889
|
+
"""Merge the input with the existing assertion and monitor entities.
|
|
890
|
+
|
|
891
|
+
Args:
|
|
892
|
+
dataset_urn: The urn of the dataset to be monitored.
|
|
893
|
+
urn: The urn of the assertion.
|
|
894
|
+
display_name: The display name of the assertion.
|
|
895
|
+
enabled: Whether the assertion is enabled.
|
|
896
|
+
criteria: The criteria of the assertion.
|
|
897
|
+
statement: The statement of the assertion.
|
|
898
|
+
incident_behavior: The incident behavior to be applied to the assertion.
|
|
899
|
+
tags: The tags to be applied to the assertion.
|
|
900
|
+
now_utc: The current UTC time from when the function is called.
|
|
901
|
+
assertion_input: The validated input to the function.
|
|
902
|
+
maybe_assertion_entity: The existing assertion entity from the DataHub instance.
|
|
903
|
+
existing_assertion: The existing assertion from the DataHub instance.
|
|
904
|
+
schedule: The schedule to be applied to the assertion.
|
|
905
|
+
|
|
906
|
+
Returns:
|
|
907
|
+
The merged assertion input.
|
|
908
|
+
"""
|
|
909
|
+
merged_assertion_input = _SqlAssertionInput(
|
|
910
|
+
urn=urn,
|
|
911
|
+
entity_client=self.client.entities,
|
|
912
|
+
dataset_urn=dataset_urn,
|
|
913
|
+
display_name=_merge_field(
|
|
914
|
+
display_name,
|
|
915
|
+
"display_name",
|
|
916
|
+
assertion_input,
|
|
917
|
+
existing_assertion,
|
|
918
|
+
maybe_assertion_entity.description if maybe_assertion_entity else None,
|
|
919
|
+
),
|
|
920
|
+
enabled=_merge_field(
|
|
921
|
+
enabled,
|
|
922
|
+
"enabled",
|
|
923
|
+
assertion_input,
|
|
924
|
+
existing_assertion,
|
|
925
|
+
existing_assertion.mode == AssertionMode.ACTIVE
|
|
926
|
+
if existing_assertion
|
|
927
|
+
else None,
|
|
928
|
+
),
|
|
929
|
+
schedule=_merge_field(
|
|
930
|
+
schedule,
|
|
931
|
+
"schedule",
|
|
932
|
+
assertion_input,
|
|
933
|
+
existing_assertion,
|
|
934
|
+
# TODO should this use maybe_monitor_entity.schedule?
|
|
935
|
+
existing_assertion.schedule if existing_assertion else None,
|
|
936
|
+
),
|
|
937
|
+
criteria=_merge_field(
|
|
938
|
+
criteria,
|
|
939
|
+
"criteria",
|
|
940
|
+
assertion_input,
|
|
941
|
+
existing_assertion,
|
|
942
|
+
existing_assertion.criteria if existing_assertion else None,
|
|
943
|
+
),
|
|
944
|
+
statement=_merge_field(
|
|
945
|
+
statement,
|
|
946
|
+
"statement",
|
|
947
|
+
assertion_input,
|
|
948
|
+
existing_assertion,
|
|
949
|
+
existing_assertion.statement if existing_assertion else None,
|
|
950
|
+
),
|
|
951
|
+
incident_behavior=_merge_field(
|
|
952
|
+
incident_behavior,
|
|
953
|
+
"incident_behavior",
|
|
954
|
+
assertion_input,
|
|
955
|
+
existing_assertion,
|
|
956
|
+
SqlAssertion._get_incident_behavior(maybe_assertion_entity)
|
|
957
|
+
if maybe_assertion_entity
|
|
958
|
+
else None,
|
|
959
|
+
),
|
|
960
|
+
tags=_merge_field(
|
|
961
|
+
tags,
|
|
962
|
+
"tags",
|
|
963
|
+
assertion_input,
|
|
964
|
+
existing_assertion,
|
|
965
|
+
maybe_assertion_entity.tags if maybe_assertion_entity else None,
|
|
966
|
+
),
|
|
967
|
+
created_by=existing_assertion.created_by
|
|
968
|
+
or DEFAULT_CREATED_BY, # Override with the existing assertion's created_by or the default created_by if not set
|
|
969
|
+
created_at=existing_assertion.created_at
|
|
970
|
+
or now_utc, # Override with the existing assertion's created_at or now if not set
|
|
971
|
+
updated_by=assertion_input.updated_by, # Override with the input's updated_by
|
|
972
|
+
updated_at=assertion_input.updated_at, # Override with the input's updated_at (now)
|
|
973
|
+
)
|
|
974
|
+
return merged_assertion_input
|
|
975
|
+
|
|
784
976
|
def _merge_smart_volume_input(
|
|
785
977
|
self,
|
|
786
978
|
dataset_urn: Union[str, DatasetUrn],
|
|
@@ -1252,6 +1444,103 @@ class AssertionsClient:
|
|
|
1252
1444
|
# raise e
|
|
1253
1445
|
return FreshnessAssertion._from_entities(assertion_entity, monitor_entity)
|
|
1254
1446
|
|
|
1447
|
+
def _create_sql_assertion(
|
|
1448
|
+
self,
|
|
1449
|
+
*,
|
|
1450
|
+
dataset_urn: Union[str, DatasetUrn],
|
|
1451
|
+
display_name: Optional[str] = None,
|
|
1452
|
+
enabled: bool = True,
|
|
1453
|
+
criteria: SqlAssertionCriteria,
|
|
1454
|
+
statement: str,
|
|
1455
|
+
incident_behavior: Optional[
|
|
1456
|
+
Union[AssertionIncidentBehavior, list[AssertionIncidentBehavior]]
|
|
1457
|
+
],
|
|
1458
|
+
tags: Optional[TagsInputType],
|
|
1459
|
+
created_by: Optional[Union[str, CorpUserUrn]] = None,
|
|
1460
|
+
schedule: Optional[Union[str, models.CronScheduleClass]] = None,
|
|
1461
|
+
) -> SqlAssertion:
|
|
1462
|
+
"""Create a sql assertion.
|
|
1463
|
+
|
|
1464
|
+
Args:
|
|
1465
|
+
dataset_urn: The urn of the dataset to be monitored.
|
|
1466
|
+
display_name: The display name of the assertion. If not provided, a random display
|
|
1467
|
+
name will be generated.
|
|
1468
|
+
enabled: Whether the assertion is enabled. Defaults to True.
|
|
1469
|
+
criteria: The criteria to be used for the assertion. This is of type SqlAssertionCriteria. It has the following fields:
|
|
1470
|
+
- type: The type of sql assertion. Valid values are:
|
|
1471
|
+
- "METRIC" -> Looks at the current value of the metric.
|
|
1472
|
+
- "METRIC_CHANGE" -> Looks at the change in the metric between the current and previous run.
|
|
1473
|
+
- change_type: The change type of the assertion, if the type is "METRIC_CHANGE". Valid values are:
|
|
1474
|
+
- "ABSOLUTE" -> Looks at the absolute change in the metric.
|
|
1475
|
+
- "PERCENTAGE" -> Looks at the percentage change in the metric.
|
|
1476
|
+
- operator: The operator to be used for the assertion. Valid values are:
|
|
1477
|
+
- "GREATER_THAN" -> The metric value is greater than the threshold.
|
|
1478
|
+
- "LESS_THAN" -> The metric value is less than the threshold.
|
|
1479
|
+
- "GREATER_THAN_OR_EQUAL_TO" -> The metric value is greater than or equal to the threshold.
|
|
1480
|
+
- "LESS_THAN_OR_EQUAL_TO" -> The metric value is less than or equal to the threshold.
|
|
1481
|
+
- "EQUAL_TO" -> The metric value is equal to the threshold.
|
|
1482
|
+
- "NOT_EQUAL_TO" -> The metric value is not equal to the threshold.
|
|
1483
|
+
- "BETWEEN" -> The metric value is between the two thresholds.
|
|
1484
|
+
- parameters: The parameters to be used for the assertion. This is of type SqlAssertionParameters. It has the following fields:
|
|
1485
|
+
- value: The value of the metric. This can be a single value or a tuple range.
|
|
1486
|
+
- If the operator is "BETWEEN", the value is a tuple of two values, with format min, max.
|
|
1487
|
+
- If the operator is not "BETWEEN", the value is a single value.
|
|
1488
|
+
statement: The statement to be used for the assertion.
|
|
1489
|
+
incident_behavior: The incident behavior to be applied to the assertion. Valid values are:
|
|
1490
|
+
- "raise_on_fail" or AssertionIncidentBehavior.RAISE_ON_FAIL
|
|
1491
|
+
- "resolve_on_pass" or AssertionIncidentBehavior.RESOLVE_ON_PASS
|
|
1492
|
+
tags: The tags to be applied to the assertion. Valid values are:
|
|
1493
|
+
- a list of strings (strings will be converted to TagUrn objects)
|
|
1494
|
+
- a list of TagUrn objects
|
|
1495
|
+
- a list of TagAssociationClass objects
|
|
1496
|
+
created_by: Optional urn of the user who created the assertion. The format is
|
|
1497
|
+
"urn:li:corpuser:<username>", which you can find on the Users & Groups page.
|
|
1498
|
+
schedule: Optional cron formatted schedule for the assertion. If not provided, a default
|
|
1499
|
+
schedule will be used. The schedule determines when the assertion will be evaluated.
|
|
1500
|
+
The format is a cron expression, e.g. "0 * * * *" for every hour using UTC timezone.
|
|
1501
|
+
Alternatively, a models.CronScheduleClass object can be provided with string parameters
|
|
1502
|
+
cron and timezone. Use `from datahub.metadata import schema_classes as models` to import the class.
|
|
1503
|
+
|
|
1504
|
+
Returns:
|
|
1505
|
+
SqlAssertion: The created assertion.
|
|
1506
|
+
"""
|
|
1507
|
+
_print_experimental_warning()
|
|
1508
|
+
now_utc = datetime.now(timezone.utc)
|
|
1509
|
+
if created_by is None:
|
|
1510
|
+
logger.warning(
|
|
1511
|
+
f"Created by is not set, using {DEFAULT_CREATED_BY} as a placeholder"
|
|
1512
|
+
)
|
|
1513
|
+
created_by = DEFAULT_CREATED_BY
|
|
1514
|
+
assertion_input = _SqlAssertionInput(
|
|
1515
|
+
urn=None,
|
|
1516
|
+
entity_client=self.client.entities,
|
|
1517
|
+
dataset_urn=dataset_urn,
|
|
1518
|
+
display_name=display_name,
|
|
1519
|
+
enabled=enabled,
|
|
1520
|
+
criteria=criteria,
|
|
1521
|
+
statement=statement,
|
|
1522
|
+
incident_behavior=incident_behavior,
|
|
1523
|
+
tags=tags,
|
|
1524
|
+
created_by=created_by,
|
|
1525
|
+
created_at=now_utc,
|
|
1526
|
+
updated_by=created_by,
|
|
1527
|
+
updated_at=now_utc,
|
|
1528
|
+
schedule=schedule,
|
|
1529
|
+
)
|
|
1530
|
+
assertion_entity, monitor_entity = (
|
|
1531
|
+
assertion_input.to_assertion_and_monitor_entities()
|
|
1532
|
+
)
|
|
1533
|
+
# If assertion creation fails, we won't try to create the monitor
|
|
1534
|
+
self.client.entities.create(assertion_entity)
|
|
1535
|
+
# TODO: Wrap monitor creation in a try-except and delete the assertion if monitor creation fails (once delete is implemented https://linear.app/acryl-data/issue/OBS-1350/add-delete-method-to-entity-clientpy)
|
|
1536
|
+
# try:
|
|
1537
|
+
self.client.entities.create(monitor_entity)
|
|
1538
|
+
# except Exception as e:
|
|
1539
|
+
# logger.error(f"Error creating monitor: {e}")
|
|
1540
|
+
# self.client.entities.delete(assertion_entity)
|
|
1541
|
+
# raise e
|
|
1542
|
+
return SqlAssertion._from_entities(assertion_entity, monitor_entity)
|
|
1543
|
+
|
|
1255
1544
|
def sync_smart_volume_assertion(
|
|
1256
1545
|
self,
|
|
1257
1546
|
*,
|
|
@@ -2317,6 +2606,167 @@ class AssertionsClient:
|
|
|
2317
2606
|
|
|
2318
2607
|
return FreshnessAssertion._from_entities(assertion_entity, monitor_entity)
|
|
2319
2608
|
|
|
2609
|
+
def sync_sql_assertion(
|
|
2610
|
+
self,
|
|
2611
|
+
*,
|
|
2612
|
+
dataset_urn: Union[str, DatasetUrn],
|
|
2613
|
+
urn: Optional[Union[str, AssertionUrn]] = None,
|
|
2614
|
+
display_name: Optional[str] = None,
|
|
2615
|
+
enabled: Optional[bool] = None,
|
|
2616
|
+
statement: str,
|
|
2617
|
+
criteria: SqlAssertionCriteria,
|
|
2618
|
+
incident_behavior: Optional[
|
|
2619
|
+
Union[AssertionIncidentBehavior, list[AssertionIncidentBehavior]]
|
|
2620
|
+
] = None,
|
|
2621
|
+
tags: Optional[TagsInputType] = None,
|
|
2622
|
+
updated_by: Optional[Union[str, CorpUserUrn]] = None,
|
|
2623
|
+
schedule: Optional[Union[str, models.CronScheduleClass]] = None,
|
|
2624
|
+
) -> SqlAssertion:
|
|
2625
|
+
"""Upsert and merge a sql assertion.
|
|
2626
|
+
|
|
2627
|
+
Note: keyword arguments are required.
|
|
2628
|
+
|
|
2629
|
+
Upsert and merge is a combination of create and update. If the assertion does not exist,
|
|
2630
|
+
it will be created. If it does exist, it will be updated. Existing assertion fields will
|
|
2631
|
+
be updated if the input value is not None. If the input value is None, the existing value
|
|
2632
|
+
will be preserved. If the input value can be un-set e.g. by passing an empty list or
|
|
2633
|
+
empty string.
|
|
2634
|
+
|
|
2635
|
+
Schedule behavior:
|
|
2636
|
+
- Create case: Uses default daily schedule (\"0 0 * * *\") or provided schedule
|
|
2637
|
+
- Update case: Uses existing schedule or provided schedule.
|
|
2638
|
+
|
|
2639
|
+
Args:
|
|
2640
|
+
dataset_urn: The urn of the dataset to be monitored.
|
|
2641
|
+
urn: The urn of the assertion. If not provided, a urn will be generated and the assertion
|
|
2642
|
+
will be _created_ in the DataHub instance.
|
|
2643
|
+
display_name: The display name of the assertion. If not provided, a random display name
|
|
2644
|
+
will be generated.
|
|
2645
|
+
enabled: Whether the assertion is enabled. If not provided, the existing value
|
|
2646
|
+
will be preserved.
|
|
2647
|
+
criteria: The criteria to be used for the assertion. This is of type SqlAssertionCriteria. It has the following fields:
|
|
2648
|
+
- type: The type of sql assertion. Valid values are:
|
|
2649
|
+
- "METRIC" -> Looks at the current value of the metric.
|
|
2650
|
+
- "METRIC_CHANGE" -> Looks at the change in the metric between the current and previous run.
|
|
2651
|
+
- change_type: The change type of the assertion, if the type is "METRIC_CHANGE". Valid values are:
|
|
2652
|
+
- "ABSOLUTE" -> Looks at the absolute change in the metric.
|
|
2653
|
+
- "PERCENTAGE" -> Looks at the percentage change in the metric.
|
|
2654
|
+
- operator: The operator to be used for the assertion. Valid values are:
|
|
2655
|
+
- "GREATER_THAN" -> The metric value is greater than the threshold.
|
|
2656
|
+
- "LESS_THAN" -> The metric value is less than the threshold.
|
|
2657
|
+
- "GREATER_THAN_OR_EQUAL_TO" -> The metric value is greater than or equal to the threshold.
|
|
2658
|
+
- "LESS_THAN_OR_EQUAL_TO" -> The metric value is less than or equal to the threshold.
|
|
2659
|
+
- "EQUAL_TO" -> The metric value is equal to the threshold.
|
|
2660
|
+
- "NOT_EQUAL_TO" -> The metric value is not equal to the threshold.
|
|
2661
|
+
- "BETWEEN" -> The metric value is between the two thresholds.
|
|
2662
|
+
- parameters: The parameters to be used for the assertion. This is of type SqlAssertionParameters. It has the following fields:
|
|
2663
|
+
- value: The value of the metric. This can be a single value or a tuple range.
|
|
2664
|
+
- If the operator is "BETWEEN", the value is a tuple of two values, with format min, max.
|
|
2665
|
+
- If the operator is not "BETWEEN", the value is a single value.
|
|
2666
|
+
statement: The SQL statement to be used for the assertion.
|
|
2667
|
+
- "SELECT COUNT(*) FROM table WHERE column > 100"
|
|
2668
|
+
incident_behavior: The incident behavior to be applied to the assertion. Valid values are:
|
|
2669
|
+
- "raise_on_fail" or AssertionIncidentBehavior.RAISE_ON_FAIL
|
|
2670
|
+
- "resolve_on_pass" or AssertionIncidentBehavior.RESOLVE_ON_PASS
|
|
2671
|
+
tags: The tags to be applied to the assertion. Valid values are:
|
|
2672
|
+
- a list of strings (strings will be converted to TagUrn objects)
|
|
2673
|
+
- a list of TagUrn objects
|
|
2674
|
+
- a list of TagAssociationClass objects
|
|
2675
|
+
updated_by: Optional urn of the user who updated the assertion. The format is
|
|
2676
|
+
"urn:li:corpuser:<username>", which you can find on the Users & Groups page.
|
|
2677
|
+
The default is the datahub system user.
|
|
2678
|
+
TODO: Retrieve the SDK user as the default instead of the datahub system user.
|
|
2679
|
+
schedule: Optional cron formatted schedule for the assertion. If not provided, a default
|
|
2680
|
+
schedule will be used. The schedule determines when the assertion will be evaluated.
|
|
2681
|
+
The format is a cron expression, e.g. "0 * * * *" for every hour using UTC timezone.
|
|
2682
|
+
Alternatively, a models.CronScheduleClass object can be provided with string parameters
|
|
2683
|
+
cron and timezone. Use `from datahub.metadata import schema_classes as models` to import the class.
|
|
2684
|
+
|
|
2685
|
+
Returns:
|
|
2686
|
+
SqlAssertion: The created or updated assertion.
|
|
2687
|
+
"""
|
|
2688
|
+
_print_experimental_warning()
|
|
2689
|
+
now_utc = datetime.now(timezone.utc)
|
|
2690
|
+
|
|
2691
|
+
if updated_by is None:
|
|
2692
|
+
logger.warning(
|
|
2693
|
+
f"updated_by is not set, using {DEFAULT_CREATED_BY} as a placeholder"
|
|
2694
|
+
)
|
|
2695
|
+
updated_by = DEFAULT_CREATED_BY
|
|
2696
|
+
|
|
2697
|
+
# 1. If urn is not set, create a new assertion
|
|
2698
|
+
if urn is None:
|
|
2699
|
+
logger.info("URN is not set, creating a new assertion")
|
|
2700
|
+
return self._create_sql_assertion(
|
|
2701
|
+
dataset_urn=dataset_urn,
|
|
2702
|
+
display_name=display_name,
|
|
2703
|
+
enabled=enabled if enabled is not None else True,
|
|
2704
|
+
criteria=criteria,
|
|
2705
|
+
statement=statement,
|
|
2706
|
+
incident_behavior=incident_behavior,
|
|
2707
|
+
tags=tags,
|
|
2708
|
+
created_by=updated_by,
|
|
2709
|
+
schedule=schedule,
|
|
2710
|
+
)
|
|
2711
|
+
|
|
2712
|
+
# 2. If urn is set, first validate the input:
|
|
2713
|
+
assertion_input = _SqlAssertionInput(
|
|
2714
|
+
urn=urn,
|
|
2715
|
+
entity_client=self.client.entities,
|
|
2716
|
+
dataset_urn=dataset_urn,
|
|
2717
|
+
display_name=display_name,
|
|
2718
|
+
criteria=criteria,
|
|
2719
|
+
statement=statement,
|
|
2720
|
+
incident_behavior=incident_behavior,
|
|
2721
|
+
tags=tags,
|
|
2722
|
+
created_by=updated_by, # This will be overridden by the actual created_by
|
|
2723
|
+
created_at=now_utc, # This will be overridden by the actual created_at
|
|
2724
|
+
updated_by=updated_by,
|
|
2725
|
+
updated_at=now_utc,
|
|
2726
|
+
schedule=schedule,
|
|
2727
|
+
)
|
|
2728
|
+
|
|
2729
|
+
# 3. Merge the assertion input with the existing assertion and monitor entities or create a new assertion
|
|
2730
|
+
# if the assertion does not exist:
|
|
2731
|
+
merged_assertion_input_or_created_assertion = (
|
|
2732
|
+
self._retrieve_and_merge_sql_assertion_and_monitor(
|
|
2733
|
+
assertion_input=assertion_input,
|
|
2734
|
+
dataset_urn=dataset_urn,
|
|
2735
|
+
urn=urn,
|
|
2736
|
+
display_name=display_name,
|
|
2737
|
+
enabled=enabled,
|
|
2738
|
+
criteria=criteria,
|
|
2739
|
+
statement=statement,
|
|
2740
|
+
incident_behavior=incident_behavior,
|
|
2741
|
+
tags=tags,
|
|
2742
|
+
updated_by=updated_by,
|
|
2743
|
+
now_utc=now_utc,
|
|
2744
|
+
schedule=schedule,
|
|
2745
|
+
)
|
|
2746
|
+
)
|
|
2747
|
+
|
|
2748
|
+
# Return early if we created a new assertion in the merge:
|
|
2749
|
+
if isinstance(merged_assertion_input_or_created_assertion, _AssertionPublic):
|
|
2750
|
+
# We know this is the correct type because we passed the assertion_class parameter
|
|
2751
|
+
assert isinstance(merged_assertion_input_or_created_assertion, SqlAssertion)
|
|
2752
|
+
return merged_assertion_input_or_created_assertion
|
|
2753
|
+
|
|
2754
|
+
# 4. Upsert the assertion and monitor entities:
|
|
2755
|
+
assertion_entity, monitor_entity = (
|
|
2756
|
+
merged_assertion_input_or_created_assertion.to_assertion_and_monitor_entities()
|
|
2757
|
+
)
|
|
2758
|
+
# If assertion upsert fails, we won't try to upsert the monitor
|
|
2759
|
+
self.client.entities.upsert(assertion_entity)
|
|
2760
|
+
# 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)
|
|
2761
|
+
# try:
|
|
2762
|
+
self.client.entities.upsert(monitor_entity)
|
|
2763
|
+
# except Exception as e:
|
|
2764
|
+
# logger.error(f"Error upserting monitor: {e}")
|
|
2765
|
+
# self.client.entities.delete(assertion_entity)
|
|
2766
|
+
# raise e
|
|
2767
|
+
|
|
2768
|
+
return SqlAssertion._from_entities(assertion_entity, monitor_entity)
|
|
2769
|
+
|
|
2320
2770
|
|
|
2321
2771
|
def _merge_field(
|
|
2322
2772
|
input_field_value: Any,
|
{acryl_datahub_cloud-0.3.12rc5.dist-info → acryl_datahub_cloud-0.3.12rc6.dist-info}/METADATA
RENAMED
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: acryl-datahub-cloud
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.12rc6
|
|
4
4
|
Requires-Dist: avro-gen3==0.7.16
|
|
5
5
|
Requires-Dist: acryl-datahub
|
|
6
6
|
Requires-Dist: croniter
|
|
7
7
|
Requires-Dist: pytz
|
|
8
8
|
Requires-Dist: types-croniter
|
|
9
9
|
Provides-Extra: datahub-lineage-features
|
|
10
|
-
Requires-Dist: pydantic<2; extra == "datahub-lineage-features"
|
|
11
10
|
Requires-Dist: duckdb; extra == "datahub-lineage-features"
|
|
12
11
|
Requires-Dist: opensearch-py==2.4.2; extra == "datahub-lineage-features"
|
|
13
12
|
Requires-Dist: pandas; extra == "datahub-lineage-features"
|
|
14
13
|
Requires-Dist: pyarrow; extra == "datahub-lineage-features"
|
|
14
|
+
Requires-Dist: pydantic<2; extra == "datahub-lineage-features"
|
|
15
15
|
Provides-Extra: datahub-reporting-forms
|
|
16
|
-
Requires-Dist: pydantic<2; extra == "datahub-reporting-forms"
|
|
17
16
|
Requires-Dist: duckdb; extra == "datahub-reporting-forms"
|
|
18
|
-
Requires-Dist: termcolor==2.5.0; extra == "datahub-reporting-forms"
|
|
19
|
-
Requires-Dist: boto3; extra == "datahub-reporting-forms"
|
|
20
17
|
Requires-Dist: pandas; extra == "datahub-reporting-forms"
|
|
18
|
+
Requires-Dist: boto3; extra == "datahub-reporting-forms"
|
|
19
|
+
Requires-Dist: termcolor==2.5.0; extra == "datahub-reporting-forms"
|
|
21
20
|
Requires-Dist: pyarrow; extra == "datahub-reporting-forms"
|
|
21
|
+
Requires-Dist: pydantic<2; extra == "datahub-reporting-forms"
|
|
22
22
|
Provides-Extra: datahub-reporting-extract-graph
|
|
23
|
-
Requires-Dist: pydantic<2; extra == "datahub-reporting-extract-graph"
|
|
24
23
|
Requires-Dist: duckdb; extra == "datahub-reporting-extract-graph"
|
|
25
24
|
Requires-Dist: opensearch-py==2.4.2; extra == "datahub-reporting-extract-graph"
|
|
26
|
-
Requires-Dist: boto3; extra == "datahub-reporting-extract-graph"
|
|
27
25
|
Requires-Dist: pandas; extra == "datahub-reporting-extract-graph"
|
|
26
|
+
Requires-Dist: boto3; extra == "datahub-reporting-extract-graph"
|
|
28
27
|
Requires-Dist: pyarrow; extra == "datahub-reporting-extract-graph"
|
|
28
|
+
Requires-Dist: pydantic<2; extra == "datahub-reporting-extract-graph"
|
|
29
29
|
Provides-Extra: datahub-reporting-extract-sql
|
|
30
|
-
Requires-Dist: pydantic<2; extra == "datahub-reporting-extract-sql"
|
|
31
30
|
Requires-Dist: duckdb; extra == "datahub-reporting-extract-sql"
|
|
32
|
-
Requires-Dist: boto3; extra == "datahub-reporting-extract-sql"
|
|
33
31
|
Requires-Dist: pandas; extra == "datahub-reporting-extract-sql"
|
|
32
|
+
Requires-Dist: boto3; extra == "datahub-reporting-extract-sql"
|
|
34
33
|
Requires-Dist: pyarrow; extra == "datahub-reporting-extract-sql"
|
|
34
|
+
Requires-Dist: pydantic<2; extra == "datahub-reporting-extract-sql"
|
|
35
35
|
Provides-Extra: datahub-usage-reporting
|
|
36
|
-
Requires-Dist: scipy<=1.14.1; extra == "datahub-usage-reporting"
|
|
37
|
-
Requires-Dist: duckdb; extra == "datahub-usage-reporting"
|
|
38
|
-
Requires-Dist: pyarrow<=18.0.0; extra == "datahub-usage-reporting"
|
|
39
|
-
Requires-Dist: termcolor==2.5.0; extra == "datahub-usage-reporting"
|
|
40
36
|
Requires-Dist: polars==1.30.0; extra == "datahub-usage-reporting"
|
|
37
|
+
Requires-Dist: opensearch-py==2.4.2; extra == "datahub-usage-reporting"
|
|
41
38
|
Requires-Dist: pandas; extra == "datahub-usage-reporting"
|
|
42
|
-
Requires-Dist: pyarrow; extra == "datahub-usage-reporting"
|
|
39
|
+
Requires-Dist: pyarrow<=18.0.0; extra == "datahub-usage-reporting"
|
|
43
40
|
Requires-Dist: numpy<2; extra == "datahub-usage-reporting"
|
|
41
|
+
Requires-Dist: termcolor==2.5.0; extra == "datahub-usage-reporting"
|
|
42
|
+
Requires-Dist: pyarrow; extra == "datahub-usage-reporting"
|
|
44
43
|
Requires-Dist: pydantic<2; extra == "datahub-usage-reporting"
|
|
45
|
-
Requires-Dist:
|
|
44
|
+
Requires-Dist: duckdb; extra == "datahub-usage-reporting"
|
|
45
|
+
Requires-Dist: scipy<=1.14.1; extra == "datahub-usage-reporting"
|
|
46
46
|
Requires-Dist: boto3; extra == "datahub-usage-reporting"
|
|
47
47
|
Requires-Dist: elasticsearch==7.13.4; extra == "datahub-usage-reporting"
|
|
48
48
|
Provides-Extra: datahub-metadata-sharing
|
|
@@ -51,47 +51,47 @@ Provides-Extra: datahub-action-request-owner
|
|
|
51
51
|
Requires-Dist: tenacity; extra == "datahub-action-request-owner"
|
|
52
52
|
Provides-Extra: acryl-cs-issues
|
|
53
53
|
Requires-Dist: jinja2; extra == "acryl-cs-issues"
|
|
54
|
-
Requires-Dist: zenpy; extra == "acryl-cs-issues"
|
|
55
54
|
Requires-Dist: openai; extra == "acryl-cs-issues"
|
|
55
|
+
Requires-Dist: zenpy; extra == "acryl-cs-issues"
|
|
56
56
|
Requires-Dist: slack-sdk; extra == "acryl-cs-issues"
|
|
57
57
|
Provides-Extra: datahub-forms-notifications
|
|
58
58
|
Requires-Dist: tenacity; extra == "datahub-forms-notifications"
|
|
59
59
|
Provides-Extra: all
|
|
60
|
-
Requires-Dist:
|
|
61
|
-
Requires-Dist:
|
|
62
|
-
Requires-Dist: pydantic<2; extra == "all"
|
|
60
|
+
Requires-Dist: pandas; extra == "all"
|
|
61
|
+
Requires-Dist: numpy<2; extra == "all"
|
|
63
62
|
Requires-Dist: openai; extra == "all"
|
|
64
|
-
Requires-Dist:
|
|
65
|
-
Requires-Dist: tenacity; extra == "all"
|
|
63
|
+
Requires-Dist: boto3; extra == "all"
|
|
66
64
|
Requires-Dist: elasticsearch==7.13.4; extra == "all"
|
|
67
|
-
Requires-Dist:
|
|
68
|
-
Requires-Dist:
|
|
65
|
+
Requires-Dist: tenacity; extra == "all"
|
|
66
|
+
Requires-Dist: polars==1.30.0; extra == "all"
|
|
67
|
+
Requires-Dist: opensearch-py==2.4.2; extra == "all"
|
|
69
68
|
Requires-Dist: termcolor==2.5.0; extra == "all"
|
|
70
69
|
Requires-Dist: pyarrow<=18.0.0; extra == "all"
|
|
71
|
-
Requires-Dist: pandas; extra == "all"
|
|
72
70
|
Requires-Dist: pyarrow; extra == "all"
|
|
73
|
-
Requires-Dist:
|
|
71
|
+
Requires-Dist: pydantic<2; extra == "all"
|
|
72
|
+
Requires-Dist: slack-sdk; extra == "all"
|
|
73
|
+
Requires-Dist: duckdb; extra == "all"
|
|
74
74
|
Requires-Dist: jinja2; extra == "all"
|
|
75
|
-
Requires-Dist:
|
|
75
|
+
Requires-Dist: scipy<=1.14.1; extra == "all"
|
|
76
76
|
Requires-Dist: zenpy; extra == "all"
|
|
77
77
|
Provides-Extra: dev
|
|
78
|
-
Requires-Dist: tenacity; extra == "dev"
|
|
79
|
-
Requires-Dist: scipy<=1.14.1; extra == "dev"
|
|
80
|
-
Requires-Dist: duckdb; extra == "dev"
|
|
81
|
-
Requires-Dist: termcolor==2.5.0; extra == "dev"
|
|
82
|
-
Requires-Dist: pyarrow<=18.0.0; extra == "dev"
|
|
83
78
|
Requires-Dist: polars==1.30.0; extra == "dev"
|
|
79
|
+
Requires-Dist: opensearch-py==2.4.2; extra == "dev"
|
|
80
|
+
Requires-Dist: acryl-datahub[dev]; extra == "dev"
|
|
84
81
|
Requires-Dist: pandas; extra == "dev"
|
|
85
|
-
Requires-Dist:
|
|
82
|
+
Requires-Dist: termcolor==2.5.0; extra == "dev"
|
|
83
|
+
Requires-Dist: pyarrow<=18.0.0; extra == "dev"
|
|
86
84
|
Requires-Dist: numpy<2; extra == "dev"
|
|
87
|
-
Requires-Dist:
|
|
85
|
+
Requires-Dist: pyarrow; extra == "dev"
|
|
88
86
|
Requires-Dist: pydantic<2; extra == "dev"
|
|
87
|
+
Requires-Dist: slack-sdk; extra == "dev"
|
|
88
|
+
Requires-Dist: duckdb; extra == "dev"
|
|
89
|
+
Requires-Dist: jinja2; extra == "dev"
|
|
89
90
|
Requires-Dist: openai; extra == "dev"
|
|
90
|
-
Requires-Dist:
|
|
91
|
+
Requires-Dist: scipy<=1.14.1; extra == "dev"
|
|
91
92
|
Requires-Dist: boto3; extra == "dev"
|
|
92
93
|
Requires-Dist: elasticsearch==7.13.4; extra == "dev"
|
|
93
|
-
Requires-Dist: acryl-datahub[dev]; extra == "dev"
|
|
94
94
|
Requires-Dist: zenpy; extra == "dev"
|
|
95
|
-
Requires-Dist:
|
|
95
|
+
Requires-Dist: tenacity; extra == "dev"
|
|
96
96
|
Dynamic: provides-extra
|
|
97
97
|
Dynamic: requires-dist
|