-
Notifications
You must be signed in to change notification settings - Fork 153
Added support for double underscore variable references #2203
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
acceptance/bundle/variables/double_underscore/databricks.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| bundle: | ||
| name: double_underscore | ||
|
|
||
| variables: | ||
| double__underscore: | ||
| description: "This is a variable with a double underscore" | ||
| default: "default" | ||
|
|
||
| resources: | ||
| jobs: | ||
| test_job: | ||
| name: "test" | ||
| tasks: | ||
| - task_key: "test ${var.double__underscore}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
|
|
||
| >>> $CLI bundle validate -o json | ||
| [ | ||
| { | ||
| "task_key": "test default" | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| trace $CLI bundle validate -o json | jq .resources.jobs.test_job.tasks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
integration/bundle/bundles/basic_with_variables/databricks_template_schema.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "properties": { | ||
| "unique_id": { | ||
| "type": "string", | ||
| "description": "Unique ID for job name" | ||
| }, | ||
| "spark_version": { | ||
| "type": "string", | ||
| "description": "Spark version used for job cluster" | ||
| }, | ||
| "node_type_id": { | ||
| "type": "string", | ||
| "description": "Node type id for job cluster" | ||
| }, | ||
| "root_path": { | ||
| "type": "string", | ||
| "description": "Root path to deploy bundle to", | ||
| "default": "" | ||
| } | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
integration/bundle/bundles/basic_with_variables/template/databricks.yml.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| bundle: | ||
| name: basic | ||
|
|
||
| workspace: | ||
| {{ if .root_path }} | ||
| root_path: "{{.root_path}}/.bundle/{{.unique_id}}" | ||
| {{ else }} | ||
| root_path: "~/.bundle/{{.unique_id}}" | ||
| {{ end }} | ||
|
|
||
| variables: | ||
| task__key: # Note: the variable has double underscore | ||
| default: my_notebook_task | ||
|
|
||
| resources: | ||
| jobs: | ||
| foo__bar: # Note: the resource has double underscore to check that TF provider can use such names | ||
| name: test-job-basic-{{.unique_id}} | ||
| tasks: | ||
| - task_key: ${var.task__key} | ||
| new_cluster: | ||
| num_workers: 1 | ||
| spark_version: "{{.spark_version}}" | ||
| node_type_id: "{{.node_type_id}}" | ||
| spark_python_task: | ||
| python_file: ./hello_world.py | ||
| foo: | ||
| name: test-job-basic-ref-{{.unique_id}} | ||
| tasks: | ||
| - task_key: job_task | ||
| run_job_task: | ||
| job_id: ${resources.jobs.foo__bar.id} |
1 change: 1 addition & 0 deletions
1
integration/bundle/bundles/basic_with_variables/template/hello_world.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| print("Hello World!") |
4 changes: 4 additions & 0 deletions
4
integration/bundle/testdata/basic_with_variables/bundle_deploy.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Uploading bundle files to /Workspace/Users/$USERNAME/.bundle/$UNIQUE_PRJ/files... | ||
| Deploying resources... | ||
| Updating deployment state... | ||
| Deployment complete! |
7 changes: 7 additions & 0 deletions
7
integration/bundle/testdata/basic_with_variables/bundle_validate.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Name: basic | ||
| Target: default | ||
| Workspace: | ||
| User: $USERNAME | ||
| Path: /Workspace/Users/$USERNAME/.bundle/$UNIQUE_PRJ | ||
|
|
||
| Validation OK! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,9 +15,13 @@ func TestNewRefNoString(t *testing.T) { | |
|
|
||
| func TestNewRefValidPattern(t *testing.T) { | ||
| for in, refs := range map[string][]string{ | ||
| "${hello_world.world_world}": {"hello_world.world_world"}, | ||
| "${helloworld.world-world}": {"helloworld.world-world"}, | ||
| "${hello-world.world-world}": {"hello-world.world-world"}, | ||
| "${hello_world.world_world}": {"hello_world.world_world"}, | ||
| "${helloworld.world-world}": {"helloworld.world-world"}, | ||
| "${hello-world.world-world}": {"hello-world.world-world"}, | ||
| "${hello_world.world__world}": {"hello_world.world__world"}, | ||
| "${hello_world.world--world}": {"hello_world.world--world"}, | ||
| "${hello_world.world-_world}": {"hello_world.world-_world"}, | ||
| "${hello_world.world_-world}": {"hello_world.world_-world"}, | ||
| } { | ||
| ref, ok := newRef(dyn.V(in)) | ||
| require.True(t, ok, "should match valid pattern: %s", in) | ||
|
|
@@ -36,8 +40,6 @@ func TestNewRefInvalidPattern(t *testing.T) { | |
| "${_-_._-_.id}", // cannot use _- in sequence | ||
| "${0helloworld.world-world}", // interpolated first section shouldn't start with number | ||
| "${helloworld.9world-world}", // interpolated second section shouldn't start with number | ||
| "${a-a.a-_a-a.id}", // fails because of -_ in the second segment | ||
|
Contributor
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. is this pattern "-_" supported? I don't see it in tests.
Contributor
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. |
||
| "${a-a.a--a-a.id}", // fails because of -- in the second segment | ||
| } | ||
| for _, v := range invalid { | ||
| _, ok := newRef(dyn.V(v)) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you check if the second
(\[[0-9]+\])*is actually needed?It looks like a repetition of the previous pattern.
Not blocking.
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.
Also, the pattern requires you to not have a
-or_at the end.We can make this more broad and use
[a-zA-Z]+[-_a-zA-Z0-9]*.