Skip to content

Commit 04ed892

Browse files
Add table update trigger in terraform API (#3401)
* add table update API * add test * more tests * fmt * integration test * remove filearrival test * one of * fix test * Update docs/resources/job.md --------- Co-authored-by: vuong-nguyen <[email protected]>
1 parent cf035e2 commit 04ed892

File tree

3 files changed

+78
-2
lines changed

3 files changed

+78
-2
lines changed

docs/resources/job.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,15 @@ This block describes the queue settings of the job:
209209
### trigger Configuration Block
210210

211211
* `pause_status` - (Optional) Indicate whether this trigger is paused or not. Either `PAUSED` or `UNPAUSED`. When the `pause_status` field is omitted in the block, the server will default to using `UNPAUSED` as a value for `pause_status`.
212-
* `file_arrival` - (Required) configuration block to define a trigger for [File Arrival events](https://learn.microsoft.com/en-us/azure/databricks/workflows/jobs/file-arrival-triggers) consisting of following attributes:
212+
* `file_arrival` - (Optional) configuration block to define a trigger for [File Arrival events](https://learn.microsoft.com/en-us/azure/databricks/workflows/jobs/file-arrival-triggers) consisting of following attributes:
213213
* `url` - (Required) string with URL under the Unity Catalog external location that will be monitored for new files. Please note that have a trailing slash character (`/`).
214214
* `min_time_between_triggers_seconds` - (Optional) If set, the trigger starts a run only after the specified amount of time passed since the last time the trigger fired. The minimum allowed value is 60 seconds.
215215
* `wait_after_last_change_seconds` - (Optional) If set, the trigger starts a run only after no file activity has occurred for the specified amount of time. This makes it possible to wait for a batch of incoming files to arrive before triggering a run. The minimum allowed value is 60 seconds.
216+
* `table_update` - (Optional) configuration block to define a trigger for Table Update events consisting of following attributes:
217+
* `table_names` - (Required) A list of Delta tables to monitor for changes. The table name must be in the format `catalog_name.schema_name.table_name`.
218+
* `condition` - (Optional) The table(s) condition based on which to trigger a job run. Valid values are `ANY_UPDATED` or `ALL_UPDATED`.
219+
* `min_time_between_triggers_seconds` - (Optional) If set, the trigger starts a run only after the specified amount of time passed since the last time the trigger fired. The minimum allowed value is 60 seconds.
220+
* `wait_after_last_change_seconds` - (Optional) If set, the trigger starts a run only after no file activity has occurred for the specified amount of time. This makes it possible to wait for a batch of incoming files to arrive before triggering a run. The minimum allowed value is 60 seconds.
216221

217222
### git_source Configuration Block
218223

jobs/resource_job.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,16 @@ type FileArrival struct {
267267
WaitAfterLastChangeSeconds int32 `json:"wait_after_last_change_seconds,omitempty"`
268268
}
269269

270+
type TableUpdate struct {
271+
TableNames []string `json:"table_names"`
272+
Condition string `json:"condition,omitempty"`
273+
MinTimeBetweenTriggersSeconds int32 `json:"min_time_between_triggers_seconds,omitempty"`
274+
WaitAfterLastChangeSeconds int32 `json:"wait_after_last_change_seconds,omitempty"`
275+
}
276+
270277
type Trigger struct {
271-
FileArrival *FileArrival `json:"file_arrival"`
278+
FileArrival *FileArrival `json:"file_arrival,omitempty"`
279+
TableUpdate *TableUpdate `json:"table_update,omitempty"`
272280
PauseStatus string `json:"pause_status,omitempty" tf:"default:UNPAUSED"`
273281
}
274282

@@ -728,6 +736,10 @@ var jobSchema = common.StructToSchema(JobSettings{},
728736
s["continuous"].ConflictsWith = []string{"schedule", "trigger"}
729737
s["trigger"].ConflictsWith = []string{"schedule", "continuous"}
730738

739+
trigger_eoo := []string{"trigger.0.file_arrival", "trigger.0.table_update"}
740+
common.MustSchemaPath(s, "trigger", "file_arrival").ExactlyOneOf = trigger_eoo
741+
common.MustSchemaPath(s, "trigger", "table_update").ExactlyOneOf = trigger_eoo
742+
731743
// Deprecated Job API 2.0 attributes
732744
var topLevelDeprecatedAttr = []string{
733745
"max_retries",

jobs/resource_job_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,65 @@ func TestResourceJobCreate_ControlRunState_ContinuousCreate(t *testing.T) {
13031303
}.Apply(t)
13041304
}
13051305

1306+
func TestResourceJobCreate_Trigger_TableUpdateCreate(t *testing.T) {
1307+
qa.ResourceFixture{
1308+
Create: true,
1309+
Resource: ResourceJob(),
1310+
Fixtures: []qa.HTTPFixture{
1311+
{
1312+
Method: "POST",
1313+
Resource: "/api/2.1/jobs/create",
1314+
ExpectedRequest: JobSettings{
1315+
MaxConcurrentRuns: 1,
1316+
Name: "Test",
1317+
Trigger: &Trigger{
1318+
PauseStatus: "UNPAUSED",
1319+
TableUpdate: &TableUpdate{
1320+
TableNames: []string{"catalog.schema.table1", "catalog.schema.table2"},
1321+
Condition: "ALL_UPDATED",
1322+
},
1323+
},
1324+
},
1325+
Response: Job{
1326+
JobID: 789,
1327+
},
1328+
},
1329+
{
1330+
Method: "GET",
1331+
Resource: "/api/2.1/jobs/get?job_id=789",
1332+
Response: Job{
1333+
JobID: 789,
1334+
Settings: &JobSettings{
1335+
MaxConcurrentRuns: 1,
1336+
Name: "Test",
1337+
Trigger: &Trigger{
1338+
PauseStatus: "UNPAUSED",
1339+
TableUpdate: &TableUpdate{
1340+
TableNames: []string{"catalog.schema.table1", "catalog.schema.table2"},
1341+
Condition: "ALL_UPDATED",
1342+
},
1343+
},
1344+
},
1345+
},
1346+
},
1347+
},
1348+
HCL: `
1349+
trigger {
1350+
pause_status = "UNPAUSED"
1351+
table_update {
1352+
table_names = {
1353+
"catalog.schema.table1",
1354+
"catalog.schema.table2"
1355+
}
1356+
condition = "ALL_UPDATED"
1357+
}
1358+
}
1359+
max_concurrent_runs = 1
1360+
name = "Test"
1361+
`,
1362+
}.Apply(t)
1363+
}
1364+
13061365
func TestResourceJobCreate_ControlRunState_ContinuousUpdateRunNow(t *testing.T) {
13071366
qa.ResourceFixture{
13081367
Update: true,

0 commit comments

Comments
 (0)