Skip to content

Commit 0ea36ad

Browse files
authored
Used KeyedSllice for job fields in bundle plan (#4921)
## Changes <!-- Brief summary of your changes that is easy to understand --> Use key-slice for `job.parameters`, `job.job_clusters` and `job.environments` to make comparison order-independent and more predictable ## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> For non-keyed arrays when the new item is added we show the full array as replaced instead of only one last element Example: ``` // array recreation when new item is added // Example diff from in config-remote-sync: parameters: - - name: catalog - default: ${var.catalog} - - name: schema - default: ${var.schema} + - default: main + name: catalog + - default: ilya_kuznetsov + name: schema + - default: bar + name: foo ``` ## Tests <!-- How have you tested the changes? --> Updated existing tests and added separate test suite for variables (I will be add more fields there in future PRs) Also I tested that key-value pairs cannot be duplicated as this is the only thing that can affect the behavior, see this comment #4921 (comment) <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent a2ee990 commit 0ea36ad

9 files changed

Lines changed: 139 additions & 17 deletions

File tree

acceptance/bundle/artifacts/whl_dynamic/out.plan_update.direct.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
"reason": "empty",
160160
"remote": {}
161161
},
162-
"environments[0].spec.dependencies[0]": {
162+
"environments[environment_key='test_env'].spec.dependencies[0]": {
163163
"action": "update",
164164
"old": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/artifacts/.internal/my_test_code-0.0.1+[UNIX_TIME_NANOS][2]-py3-none-any.whl",
165165
"new": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/artifacts/.internal/my_test_code-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl",

acceptance/bundle/config-remote-sync/job_fields/output.txt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ Detected changes in 1 resource(s):
1212
Resource: resources.jobs.my_job
1313
email_notifications.no_alert_for_skipped_runs: add
1414
email_notifications.on_failure: add
15-
job_clusters[0].job_cluster_key: replace
16-
parameters: replace
15+
job_clusters[job_cluster_key='test_cluster']: remove
16+
job_clusters[job_cluster_key='test_cluster_renamed']: add
17+
parameters[name='region']: add
1718
tags['team']: add
1819
tasks[task_key='inline_cluster_task'].new_cluster.num_workers: replace
1920
tasks[task_key='main'].job_cluster_key: replace
@@ -28,21 +29,17 @@ Resource: resources.jobs.my_job
2829
>>> diff.py databricks.yml.backup databricks.yml
2930
--- databricks.yml.backup
3031
+++ databricks.yml
31-
@@ -8,13 +8,19 @@
32+
@@ -8,4 +8,7 @@
3233
on_success:
3334
- success@example.com
3435
+ no_alert_for_skipped_runs: true
3536
+ on_failure:
3637
+ - failure@example.com
3738
parameters:
38-
- - name: catalog
39-
- default: main
40-
- - name: env
41-
- default: dev
42-
+ - default: main
43-
+ name: catalog
44-
+ - default: dev
45-
+ name: env
39+
- name: catalog
40+
@@ -13,8 +16,11 @@
41+
- name: env
42+
default: dev
4643
+ - default: us-east-1
4744
+ name: region
4845
trigger:
@@ -55,14 +52,18 @@ Resource: resources.jobs.my_job
5552
+ - samples.nyctaxi.trips
5653
environments:
5754
- environment_key: default
58-
@@ -24,5 +30,5 @@
55+
@@ -24,14 +30,14 @@
5956
- ./*.whl
6057
job_clusters:
6158
- - job_cluster_key: test_cluster
6259
+ - job_cluster_key: test_cluster_renamed
6360
new_cluster:
64-
spark_version: [[DEFAULT_SPARK_VERSION]]
65-
@@ -33,5 +39,5 @@
61+
- spark_version: [[DEFAULT_SPARK_VERSION]]
62+
node_type_id: [NODE_TYPE_ID]
63+
num_workers: 1
64+
+ spark_version: [[DEFAULT_SPARK_VERSION]]
65+
tasks:
66+
- task_key: main
6667
notebook_task:
6768
notebook_path: /Users/{{workspace_user_name}}/notebook
6869
- job_cluster_key: test_cluster
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
bundle:
2+
name: test-bundle-$UNIQUE_NAME
3+
4+
variables:
5+
catalog:
6+
default: main
7+
schema:
8+
default: dev
9+
10+
resources:
11+
jobs:
12+
my_job:
13+
parameters:
14+
- name: catalog
15+
default: ${var.catalog}
16+
- name: schema
17+
default: ${var.schema}
18+
tasks:
19+
- task_key: main
20+
notebook_task:
21+
notebook_path: /Users/{{workspace_user_name}}/notebook
22+
23+
targets:
24+
default:
25+
mode: development

acceptance/bundle/config-remote-sync/job_params_variables/out.test.toml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
2+
Deploying resources...
3+
Updating deployment state...
4+
Deployment complete!
5+
6+
=== Add new parameter remotely
7+
=== Detect and save changes
8+
Detected changes in 1 resource(s):
9+
10+
Resource: resources.jobs.my_job
11+
parameters[name='region']: add
12+
13+
14+
15+
=== Configuration changes
16+
17+
>>> diff.py databricks.yml.backup databricks.yml
18+
--- databricks.yml.backup
19+
+++ databricks.yml
20+
@@ -16,4 +16,6 @@
21+
- name: schema
22+
default: ${var.schema}
23+
+ - default: us-east-1
24+
+ name: region
25+
tasks:
26+
- task_key: main
27+
28+
>>> [CLI] bundle destroy --auto-approve
29+
The following resources will be deleted:
30+
delete resources.jobs.my_job
31+
32+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default
33+
34+
Deleting files...
35+
Destroy complete!
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
envsubst < databricks.yml.tmpl > databricks.yml
4+
5+
cleanup() {
6+
trace $CLI bundle destroy --auto-approve
7+
}
8+
trap cleanup EXIT
9+
10+
$CLI bundle deploy
11+
job_id="$(read_id.py my_job)"
12+
13+
title "Add new parameter remotely"
14+
edit_resource.py jobs $job_id <<EOF
15+
r["parameters"].append({"name": "region", "default": "us-east-1"})
16+
EOF
17+
18+
title "Detect and save changes"
19+
echo
20+
cp databricks.yml databricks.yml.backup
21+
$CLI bundle config-remote-sync --save
22+
23+
title "Configuration changes"
24+
echo
25+
trace diff.py databricks.yml.backup databricks.yml
26+
rm databricks.yml.backup
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Cloud = true
2+
RequiresUnityCatalog = true
3+
4+
RecordRequests = false
5+
Ignore = [".databricks", "databricks.yml", "databricks.yml.backup"]
6+
7+
[Env]
8+
DATABRICKS_BUNDLE_ENABLE_EXPERIMENTAL_YAML_SYNC = "true"
9+
10+
[EnvMatrix]
11+
DATABRICKS_BUNDLE_ENGINE = ["direct", "terraform"]

acceptance/bundle/resource_deps/jobs_update_remote/out.plan_update.direct.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"reason": "empty",
126126
"remote": {}
127127
},
128-
"job_clusters[0].new_cluster.num_workers": {
128+
"job_clusters[job_cluster_key='key'].new_cluster.num_workers": {
129129
"action": "skip",
130130
"reason": "empty",
131131
"old": 0,

bundle/direct/dresources/job.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,24 @@ func getTaskKey(x jobs.Task) (string, string) {
5959
return "task_key", x.TaskKey
6060
}
6161

62+
func getParameterName(x jobs.JobParameterDefinition) (string, string) {
63+
return "name", x.Name
64+
}
65+
66+
func getJobClusterKey(x jobs.JobCluster) (string, string) {
67+
return "job_cluster_key", x.JobClusterKey
68+
}
69+
70+
func getEnvironmentKey(x jobs.JobEnvironment) (string, string) {
71+
return "environment_key", x.EnvironmentKey
72+
}
73+
6274
func (*ResourceJob) KeyedSlices() map[string]any {
6375
return map[string]any{
64-
"tasks": getTaskKey,
76+
"tasks": getTaskKey,
77+
"parameters": getParameterName,
78+
"job_clusters": getJobClusterKey,
79+
"environments": getEnvironmentKey,
6580
}
6681
}
6782

0 commit comments

Comments
 (0)