-
Notifications
You must be signed in to change notification settings - Fork 215
Add PyDABs support for SQL Alerts #6335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d43471f
46757e8
b28ad73
0d500ba
ed5b9dc
d3e7d64
0526619
43bc6f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| bundle: | ||
| name: my_project | ||
|
|
||
| sync: {paths: []} # don't need to copy files | ||
|
|
||
| python: | ||
| resources: | ||
| - "resources:load_resources" | ||
| mutators: | ||
| - "mutators:update_alert" | ||
|
|
||
| resources: | ||
| alerts: | ||
| my_alert_1: | ||
| display_name: "My Alert" | ||
| query_text: "SELECT 1" | ||
| warehouse_id: "my_warehouse" | ||
| evaluation: | ||
| comparison_operator: "GREATER_THAN" | ||
| source: | ||
| name: "column_1" | ||
| schedule: | ||
| quartz_cron_schedule: "0 0 0 * * ?" | ||
| timezone_id: "UTC" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from dataclasses import replace | ||
|
|
||
| from databricks.bundles.alerts import Alert | ||
| from databricks.bundles.core import alert_mutator | ||
|
|
||
|
|
||
| @alert_mutator | ||
| def update_alert(alert: Alert) -> Alert: | ||
| assert isinstance(alert.display_name, str) | ||
|
|
||
| return replace(alert, display_name=f"{alert.display_name} (updated)") |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
|
|
||
| >>> uv run [UV_ARGS] -q [CLI] bundle validate --output json | ||
| { | ||
| "experimental": { | ||
| "python": { | ||
| "mutators": [ | ||
| "mutators:update_alert" | ||
| ], | ||
| "resources": [ | ||
| "resources:load_resources" | ||
| ] | ||
| } | ||
| }, | ||
| "resources": { | ||
| "alerts": { | ||
| "my_alert_1": { | ||
| "display_name": "My Alert (updated)", | ||
| "evaluation": { | ||
| "comparison_operator": "GREATER_THAN", | ||
| "source": { | ||
| "name": "column_1" | ||
| } | ||
| }, | ||
| "parent_path": "/Workspace/Users/[USERNAME]/.bundle/my_project/default/resources", | ||
| "query_text": "SELECT 1", | ||
| "schedule": { | ||
| "quartz_cron_schedule": "0 0 0 * * ?", | ||
| "timezone_id": "UTC" | ||
| }, | ||
| "warehouse_id": "my_warehouse" | ||
| }, | ||
| "my_alert_2": { | ||
| "display_name": "My Alert (2) (updated)", | ||
| "evaluation": { | ||
| "comparison_operator": "LESS_THAN", | ||
| "source": { | ||
| "name": "column_2" | ||
| } | ||
| }, | ||
| "parent_path": "/Workspace/Users/[USERNAME]/.bundle/my_project/default/resources", | ||
| "query_text": "SELECT 2", | ||
| "schedule": { | ||
| "quartz_cron_schedule": "0 0 12 * * ?", | ||
| "timezone_id": "UTC" | ||
| }, | ||
| "warehouse_id": "my_warehouse_2" | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| from databricks.bundles.core import Resources | ||
|
|
||
|
|
||
| def load_resources() -> Resources: | ||
| resources = Resources() | ||
|
|
||
| resources.add_alert( | ||
| "my_alert_2", | ||
| { | ||
| "display_name": "My Alert (2)", | ||
| "query_text": "SELECT 2", | ||
| "warehouse_id": "my_warehouse_2", | ||
| "evaluation": { | ||
| "comparison_operator": "LESS_THAN", | ||
| "source": {"name": "column_2"}, | ||
| }, | ||
| "schedule": { | ||
| "quartz_cron_schedule": "0 0 12 * * ?", | ||
| "timezone_id": "UTC", | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
| return resources |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
|
|
||
| trace uv run $UV_ARGS -q $CLI bundle validate --output json | \ | ||
| jq "pick(.experimental.python, .resources)" | ||
|
|
||
| rm -fr .databricks __pycache__ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Cloud = false # tests don't interact with APIs | ||
|
|
||
| # alerts are only supported in the current version of the wheel | ||
| EnvMatrix.PYDAB_VERSION = ["current"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| __all__ = [ | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is also auto generated |
||
| "Aggregation", | ||
| "AggregationParam", | ||
| "Alert", | ||
| "AlertDict", | ||
| "AlertEvaluationState", | ||
| "AlertEvaluationStateParam", | ||
| "AlertParam", | ||
| "AlertStatementParameter", | ||
| "AlertStatementParameterDict", | ||
| "AlertStatementParameterParam", | ||
| "AlertV2Evaluation", | ||
| "AlertV2EvaluationDict", | ||
| "AlertV2EvaluationParam", | ||
| "AlertV2Notification", | ||
| "AlertV2NotificationDict", | ||
| "AlertV2NotificationParam", | ||
| "AlertV2Operand", | ||
| "AlertV2OperandColumn", | ||
| "AlertV2OperandColumnDict", | ||
| "AlertV2OperandColumnParam", | ||
| "AlertV2OperandDict", | ||
| "AlertV2OperandParam", | ||
| "AlertV2OperandValue", | ||
| "AlertV2OperandValueDict", | ||
| "AlertV2OperandValueParam", | ||
| "AlertV2RunAs", | ||
| "AlertV2RunAsDict", | ||
| "AlertV2RunAsParam", | ||
| "AlertV2Subscription", | ||
| "AlertV2SubscriptionDict", | ||
| "AlertV2SubscriptionParam", | ||
| "ComparisonOperator", | ||
| "ComparisonOperatorParam", | ||
| "CronSchedule", | ||
| "CronScheduleDict", | ||
| "CronScheduleParam", | ||
| "Lifecycle", | ||
| "LifecycleDict", | ||
| "LifecycleParam", | ||
| "Permission", | ||
| "PermissionDict", | ||
| "PermissionLevel", | ||
| "PermissionLevelParam", | ||
| "PermissionParam", | ||
| "SchedulePauseStatus", | ||
| "SchedulePauseStatusParam", | ||
| ] | ||
|
|
||
|
|
||
| from databricks.bundles.alerts._models.aggregation import Aggregation, AggregationParam | ||
| from databricks.bundles.alerts._models.alert import Alert, AlertDict, AlertParam | ||
| from databricks.bundles.alerts._models.alert_evaluation_state import ( | ||
| AlertEvaluationState, | ||
| AlertEvaluationStateParam, | ||
| ) | ||
| from databricks.bundles.alerts._models.alert_statement_parameter import ( | ||
| AlertStatementParameter, | ||
| AlertStatementParameterDict, | ||
| AlertStatementParameterParam, | ||
| ) | ||
| from databricks.bundles.alerts._models.alert_v2_evaluation import ( | ||
| AlertV2Evaluation, | ||
| AlertV2EvaluationDict, | ||
| AlertV2EvaluationParam, | ||
| ) | ||
| from databricks.bundles.alerts._models.alert_v2_notification import ( | ||
| AlertV2Notification, | ||
| AlertV2NotificationDict, | ||
| AlertV2NotificationParam, | ||
| ) | ||
| from databricks.bundles.alerts._models.alert_v2_operand import ( | ||
| AlertV2Operand, | ||
| AlertV2OperandDict, | ||
| AlertV2OperandParam, | ||
| ) | ||
| from databricks.bundles.alerts._models.alert_v2_operand_column import ( | ||
| AlertV2OperandColumn, | ||
| AlertV2OperandColumnDict, | ||
| AlertV2OperandColumnParam, | ||
| ) | ||
| from databricks.bundles.alerts._models.alert_v2_operand_value import ( | ||
| AlertV2OperandValue, | ||
| AlertV2OperandValueDict, | ||
| AlertV2OperandValueParam, | ||
| ) | ||
| from databricks.bundles.alerts._models.alert_v2_run_as import ( | ||
| AlertV2RunAs, | ||
| AlertV2RunAsDict, | ||
| AlertV2RunAsParam, | ||
| ) | ||
| from databricks.bundles.alerts._models.alert_v2_subscription import ( | ||
| AlertV2Subscription, | ||
| AlertV2SubscriptionDict, | ||
| AlertV2SubscriptionParam, | ||
| ) | ||
| from databricks.bundles.alerts._models.comparison_operator import ( | ||
| ComparisonOperator, | ||
| ComparisonOperatorParam, | ||
| ) | ||
| from databricks.bundles.alerts._models.cron_schedule import ( | ||
| CronSchedule, | ||
| CronScheduleDict, | ||
| CronScheduleParam, | ||
| ) | ||
| from databricks.bundles.alerts._models.lifecycle import ( | ||
| Lifecycle, | ||
| LifecycleDict, | ||
| LifecycleParam, | ||
| ) | ||
| from databricks.bundles.alerts._models.permission import ( | ||
| Permission, | ||
| PermissionDict, | ||
| PermissionParam, | ||
| ) | ||
| from databricks.bundles.alerts._models.permission_level import ( | ||
| PermissionLevel, | ||
| PermissionLevelParam, | ||
| ) | ||
| from databricks.bundles.alerts._models.schedule_pause_status import ( | ||
| SchedulePauseStatus, | ||
| SchedulePauseStatusParam, | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| from enum import Enum | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This entire directory |
||
| from typing import Literal | ||
|
|
||
|
|
||
| class Aggregation(Enum): | ||
| SUM = "SUM" | ||
| COUNT = "COUNT" | ||
| COUNT_DISTINCT = "COUNT_DISTINCT" | ||
| AVG = "AVG" | ||
| MEDIAN = "MEDIAN" | ||
| MIN = "MIN" | ||
| MAX = "MAX" | ||
| STDDEV = "STDDEV" | ||
|
|
||
|
|
||
| AggregationParam = ( | ||
| Literal["SUM", "COUNT", "COUNT_DISTINCT", "AVG", "MEDIAN", "MIN", "MAX", "STDDEV"] | ||
| | Aggregation | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 2 had to be added manually but I think they can be found out using BFS and potentially stored in a yaml file