Skip to content

Commit 408779d

Browse files
authored
Add serverless support to dbt-sql template (#3668)
## Changes This mirrors the approach in default-python. ## Why I found this missing when working on #3667. ## Tests Manually initialized and successfully ran both variants.
1 parent 972db90 commit 408779d

File tree

7 files changed

+49
-23
lines changed

7 files changed

+49
-23
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Dependency updates
1010

1111
### Bundles
12+
* Prompt for serverless compute in `dbt-sql` template (defaults to `yes`) ([#3668](https://github.com/databricks/cli/pull/3668))
1213

1314
### API Changes
1415
* Added `databricks account account-groups-v2` command group.

acceptance/bundle/templates/dbt-sql/output/my_dbt_sql/resources/my_dbt_sql.job.yml

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ resources:
1515

1616
tasks:
1717
- task_key: dbt
18+
environment_key: default
1819
dbt_task:
1920
project_directory: ../
2021
# The default schema, catalog, etc. are defined in ../dbt_profiles/profiles.yml
@@ -25,17 +26,9 @@ resources:
2526
- 'dbt seed --target=${bundle.target} --vars "{ dev_schema: ${workspace.current_user.short_name} }"'
2627
- 'dbt run --target=${bundle.target} --vars "{ dev_schema: ${workspace.current_user.short_name} }"'
2728

28-
libraries:
29-
- pypi:
30-
package: dbt-databricks>=1.8.0,<2.0.0
31-
32-
new_cluster:
33-
spark_version: 15.4.x-scala2.12
34-
node_type_id: [NODE_TYPE_ID]
35-
data_security_mode: SINGLE_USER
36-
num_workers: 0
37-
spark_conf:
38-
spark.master: "local[*, 4]"
39-
spark.databricks.cluster.profile: singleNode
40-
custom_tags:
41-
ResourceClass: SingleNode
29+
environments:
30+
- environment_key: default
31+
spec:
32+
environment_version: "2"
33+
dependencies:
34+
- dbt-databricks>=1.8.0,<2.0.0

acceptance/bundle/templates/telemetry/dbt-sql/out.requests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"uploadTime": [UNIX_TIME_MILLIS],
2929
"items": [],
3030
"protoLogs": [
31-
"{\"frontend_log_event_id\":\"[UUID]\",\"entry\":{\"databricks_cli_log\":{\"execution_context\":{\"cmd_exec_id\":\"[CMD-EXEC-ID]\",\"version\":\"[DEV_VERSION]\",\"command\":\"bundle_init\",\"operating_system\":\"[OS]\",\"execution_time_ms\":\"SMALL_INT\",\"exit_code\":0},\"bundle_init_event\":{\"bundle_uuid\":\"[BUNDLE-UUID]\",\"template_name\":\"dbt-sql\",\"template_enum_args\":[{\"key\":\"personal_schemas\",\"value\":\"yes, use a schema based on the current user name during development\"}]}}}}"
31+
"{\"frontend_log_event_id\":\"[UUID]\",\"entry\":{\"databricks_cli_log\":{\"execution_context\":{\"cmd_exec_id\":\"[CMD-EXEC-ID]\",\"version\":\"[DEV_VERSION]\",\"command\":\"bundle_init\",\"operating_system\":\"[OS]\",\"execution_time_ms\":\"SMALL_INT\",\"exit_code\":0},\"bundle_init_event\":{\"bundle_uuid\":\"[BUNDLE-UUID]\",\"template_name\":\"dbt-sql\",\"template_enum_args\":[{\"key\":\"personal_schemas\",\"value\":\"yes, use a schema based on the current user name during development\"},{\"key\":\"serverless\",\"value\":\"yes\"}]}}}}"
3232
]
3333
}
3434
}

acceptance/bundle/templates/telemetry/dbt-sql/output.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Refer to the README.md file for full "getting started" guide and production setu
2929
{
3030
"key": "personal_schemas",
3131
"value": "yes, use a schema based on the current user name during development"
32+
},
33+
{
34+
"key": "serverless",
35+
"value": "yes"
3236
}
3337
]
3438
}

libs/template/renderer_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,18 @@ func TestBuiltinDbtTemplateValid(t *testing.T) {
135135
for _, personal_schemas := range []string{"yes", "no"} {
136136
for _, target := range []string{"dev", "prod"} {
137137
for _, isServicePrincipal := range []bool{true, false} {
138-
config := map[string]any{
139-
"project_name": "my_project",
140-
"http_path": "/sql/1.0/warehouses/123",
141-
"default_catalog": "hive_metastore",
142-
"personal_schemas": personal_schemas,
143-
"shared_schema": "lennart",
138+
for _, serverless := range []string{"yes", "no"} {
139+
config := map[string]any{
140+
"project_name": "my_project",
141+
"http_path": "/sql/1.0/warehouses/123",
142+
"default_catalog": "hive_metastore",
143+
"personal_schemas": personal_schemas,
144+
"shared_schema": "lennart",
145+
"serverless": serverless,
146+
}
147+
build := false
148+
assertBuiltinTemplateValid(t, "dbt-sql", config, target, isServicePrincipal, build, t.TempDir())
144149
}
145-
build := false
146-
assertBuiltinTemplateValid(t, "dbt-sql", config, target, isServicePrincipal, build, t.TempDir())
147150
}
148151
}
149152
}

libs/template/templates/dbt-sql/databricks_template_schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
"pattern_match_failure_message": "Invalid schema name.",
4848
"description": "\nPlease provide an initial schema during development.\ndefault_schema",
4949
"order": 5
50+
},
51+
"serverless": {
52+
"type": "string",
53+
"default": "yes",
54+
"enum": ["yes", "no"],
55+
"description": "Use serverless compute",
56+
"order": 6
5057
}
5158
},
5259
"success_message": "\n📊 Your new project has been created in the '{{.project_name}}' directory!\nIf you already have dbt installed, just type 'cd {{.project_name}}; dbt init' to get started.\nRefer to the README.md file for full \"getting started\" guide and production setup instructions.\n"

libs/template/templates/dbt-sql/template/{{.project_name}}/resources/{{.project_name}}.job.yml.tmpl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{{$with_serverless := (eq .serverless "yes") -}}
2+
13
resources:
24
jobs:
35
{{.project_name}}_job:
@@ -15,6 +17,9 @@ resources:
1517

1618
tasks:
1719
- task_key: dbt
20+
{{- if $with_serverless }}
21+
environment_key: default
22+
{{- end }}
1823
dbt_task:
1924
project_directory: ../
2025
# The default schema, catalog, etc. are defined in ../dbt_profiles/profiles.yml
@@ -32,6 +37,8 @@ resources:
3237
- 'dbt run --target=${bundle.target}'
3338
{{- end}}
3439

40+
{{- if not $with_serverless }}
41+
3542
libraries:
3643
- pypi:
3744
package: dbt-databricks>=1.8.0,<2.0.0
@@ -46,3 +53,14 @@ resources:
4653
spark.databricks.cluster.profile: singleNode
4754
custom_tags:
4855
ResourceClass: SingleNode
56+
{{- end }}
57+
58+
{{- if $with_serverless }}
59+
60+
environments:
61+
- environment_key: default
62+
spec:
63+
environment_version: "2"
64+
dependencies:
65+
- dbt-databricks>=1.8.0,<2.0.0
66+
{{- end }}

0 commit comments

Comments
 (0)