本頁說明如何在 Databricks 資產包中覆寫或聯結頂層設定與目標設定。 如需套件組合設定的相關資訊,請參閱 Databricks 資產套件組合設定。
工件設定覆寫
您可以使用對映中的artifacts構件設定置換最上層targets對映中的構件設定,例如:
# ...
artifacts:
<some-unique-programmatic-identifier-for-this-artifact>:
# Artifact settings.
targets:
<some-unique-programmatic-identifier-for-this-target>:
artifacts:
<the-matching-programmatic-identifier-for-this-artifact>:
# Any more artifact settings to join with the settings from the
# matching top-level artifacts mapping.
如果在最上層 artifacts 對映和 targets 相同構件的對映中定義了任何構件設定,則對映中的 targets 設定優先於最上層 artifacts 對映中的設定。
範例 1: 僅在最上層構件對映中定義的構件設定
為了說明這在實際操作中的運作方式,在以下範例中,path 是於最高層級的 artifacts 對應中定義的,其中包含了應用程式的所有設定:
# ...
artifacts:
my-artifact:
type: whl
path: ./my_package
# ...
當您執行 databricks bundle validate 此範例時,產生的圖形為:
{
"...": "...",
"artifacts": {
"my-artifact": {
"type": "whl",
"path": "./my_package",
"...": "..."
}
},
"...": "..."
}
範例 2: 在多個構件對映中定義的衝突構件設定
在此範例中, path 在最上層 artifacts 對映和 artifacts 中的 targets對映中定義。 **
在此範例中,path在artifacts對應中的優先權高於最上層targets對應中的path,以定義構件的設定:
# ...
artifacts:
my-artifact:
type: whl
path: ./my_package
targets:
dev:
artifacts:
my-artifact:
path: ./my_other_package
# ...
當您執行 databricks bundle validate 此範例時,產生的圖形為:
{
"...": "...",
"artifacts": {
"my-artifact": {
"type": "whl",
"path": "./my_other_package",
"...": "..."
}
},
"...": "..."
}
叢集設定覆寫
您可以覆寫或聯結目標的任務或管線叢集設定。
對於工作,請在工作定義中使用 job_cluster_key,以識別最上層的 resources 對映中的工作叢集設定,並與 targets 對映中的工作叢集設定結合。
# ...
resources:
jobs:
<some-unique-programmatic-identifier-for-this-job>:
# ...
job_clusters:
- job_cluster_key: <some-unique-programmatic-identifier-for-this-key>
new_cluster:
# Cluster settings.
targets:
<some-unique-programmatic-identifier-for-this-target>:
resources:
jobs:
<the-matching-programmatic-identifier-for-this-job>:
# ...
job_clusters:
- job_cluster_key: <the-matching-programmatic-identifier-for-this-key>
# Any more cluster settings to join with the settings from the
# resources mapping for the matching top-level job_cluster_key.
# ...
如果在最上層 resources 對應和相同 targets 的 job_cluster_key 對應中同時定義了任何叢集設定,則 targets 對應中的設定優先於最上層 resources 對應中的設定。
針對 Lakeflow Spark 宣告式管線,請在管線定義的叢集設定中使用 label,以識別最上層 resources 對應中的叢集設定,並與 targets 對應中的叢集設定聯結,例如:
# ...
resources:
pipelines:
<some-unique-programmatic-identifier-for-this-pipeline>:
# ...
clusters:
- label: default | maintenance
# Cluster settings.
targets:
<some-unique-programmatic-identifier-for-this-target>:
resources:
pipelines:
<the-matching-programmatic-identifier-for-this-pipeline>:
# ...
clusters:
- label: default | maintenance
# Any more cluster settings to join with the settings from the
# resources mapping for the matching top-level label.
# ...
如果在最上層 resources 對應和相同 targets 的 label 對應中同時定義了任何叢集設定,則 targets 對應中的設定優先於最上層 resources 對應中的設定。
範例 1:在多個資源對應中定義的新工作叢集設定,且不存在設定衝突
在此範例中,頂層 spark_version 對應中的 resources 結合 node_type_id 對應中的 num_workers 和 resources,以定義具名 targets:job_cluster_key 的設定。
# ...
resources:
jobs:
my-job:
name: my-job
job_clusters:
- job_cluster_key: my-cluster
new_cluster:
spark_version: 13.3.x-scala2.12
targets:
development:
resources:
jobs:
my-job:
name: my-job
job_clusters:
- job_cluster_key: my-cluster
new_cluster:
node_type_id: Standard_DS3_v2
num_workers: 1
# ...
當您針對此範例執行 databricks bundle validate 時,產生的圖形如下所示:
{
"...": "...",
"resources": {
"jobs": {
"my-job": {
"job_clusters": [
{
"job_cluster_key": "my-cluster",
"new_cluster": {
"node_type_id": "Standard_DS3_v2",
"num_workers": 1,
"spark_version": "13.3.x-scala2.12"
}
}
],
"...": "..."
}
}
}
}
範例 2:在多個資源對應中定義的新工作叢集設定衝突
在此範例中,spark_version 和 num_workers 定義在最上層的 resources 對映和 resources 中的 targets 對映中。 在此範例中,spark_version中的num_workers和resources對應會比頂層targets對應中的spark_version和num_workers更優先,以定義名為resources的job_cluster_key設定:
# ...
resources:
jobs:
my-job:
name: my-job
job_clusters:
- job_cluster_key: my-cluster
new_cluster:
spark_version: 13.3.x-scala2.12
node_type_id: Standard_DS3_v2
num_workers: 1
targets:
development:
resources:
jobs:
my-job:
name: my-job
job_clusters:
- job_cluster_key: my-cluster
new_cluster:
spark_version: 12.2.x-scala2.12
num_workers: 2
# ...
當您針對此範例執行 databricks bundle validate 時,產生的圖形如下所示:
{
"...": "...",
"resources": {
"jobs": {
"my-job": {
"job_clusters": [
{
"job_cluster_key": "my-cluster",
"new_cluster": {
"node_type_id": "Standard_DS3_v2",
"num_workers": 2,
"spark_version": "12.2.x-scala2.12"
}
}
],
"...": "..."
}
}
}
}
範例 3:在多個資源映射中定義且沒有設定衝突的管線叢集設定
在此範例中,頂層node_type_id中的resources會與num_workersresources中的targets結合,以定義名為label的default設定:
# ...
resources:
pipelines:
my-pipeline:
clusters:
- label: default
node_type_id: Standard_DS3_v2
targets:
development:
resources:
pipelines:
my-pipeline:
clusters:
- label: default
num_workers: 1
# ...
當您針對此範例執行 databricks bundle validate 時,產生的圖形如下所示:
{
"...": "...",
"resources": {
"pipelines": {
"my-pipeline": {
"clusters": [
{
"label": "default",
"node_type_id": "Standard_DS3_v2",
"num_workers": 1
}
],
"...": "..."
}
}
}
}
範例 4:在多個資源映射中定義的管線叢集設定發生衝突
在此範例中, num_workers 在最上層 resources 對映和 resources 中的 targets對映中定義。
num_workers在resourcestargets對應中優先於頂層num_workersresources對應中的label,以定義名稱為default的設定。
# ...
resources:
pipelines:
my-pipeline:
clusters:
- label: default
node_type_id: Standard_DS3_v2
num_workers: 1
targets:
development:
resources:
pipelines:
my-pipeline:
clusters:
- label: default
num_workers: 2
# ...
當您針對此範例執行 databricks bundle validate 時,產生的圖形如下所示:
{
"...": "...",
"resources": {
"pipelines": {
"my-pipeline": {
"clusters": [
{
"label": "default",
"node_type_id": "Standard_DS3_v2",
"num_workers": 2
}
],
"...": "..."
}
}
}
}
工作任務設定覆寫
您可以在工作定義中使用 tasks 對應,將最上層 resources 對應中的作業任務設定與 targets 對應中的作業任務設定結合,例如:
# ...
resources:
jobs:
<some-unique-programmatic-identifier-for-this-job>:
# ...
tasks:
- task_key: <some-unique-programmatic-identifier-for-this-task>
# Task settings.
targets:
<some-unique-programmatic-identifier-for-this-target>:
resources:
jobs:
<the-matching-programmatic-identifier-for-this-job>:
# ...
tasks:
- task_key: <the-matching-programmatic-identifier-for-this-key>
# Any more task settings to join with the settings from the
# resources mapping for the matching top-level task_key.
# ...
若要聯結相同工作的頂層 resources 對應和 targets 對應,必須將工作對應設定 task_key 為相同的值。
如果在最上層 resources 對映和 targets 相同 task對映中同時定義了任何工作作業設定,則對映中的 targets 設定會優先於最上層 resources 對映中的設定。
範例 1:在多個資源對應中定義且沒有設定衝突的工作任務設定
在此範例中,頂層 spark_version 對應中的 resources 結合 node_type_id 對應中的 num_workers 和 resources,以定義具名 targets:task_key 的設定。
# ...
resources:
jobs:
my-job:
name: my-job
tasks:
- task_key: my-key
new_cluster:
spark_version: 13.3.x-scala2.12
targets:
development:
resources:
jobs:
my-job:
name: my-job
tasks:
- task_key: my-task
new_cluster:
node_type_id: Standard_DS3_v2
num_workers: 1
# ...
當您執行 databricks bundle validate 此範例時,產生的圖形如下 (為了簡潔起見,省略符號表示省略的內容):
{
"...": "...",
"resources": {
"jobs": {
"my-job": {
"tasks": [
{
"new_cluster": {
"node_type_id": "Standard_DS3_v2",
"num_workers": 1,
"spark_version": "13.3.x-scala2.12"
},
"task-key": "my-task"
}
],
"...": "..."
}
}
}
}
範例 2:在多個資源對應中定義的衝突工作作業設定
在此範例中,spark_version 和 num_workers 定義在最上層的 resources 對映和 resources 中的 targets 對映中。
spark_version和num_workers在resources對應中的targets中,比頂層spark_version對應中的num_workers和resources更具優先權。 這會定義名為task_key的my-task設定 (省略符號表示省略的內容,為了簡潔起見):
# ...
resources:
jobs:
my-job:
name: my-job
tasks:
- task_key: my-task
new_cluster:
spark_version: 13.3.x-scala2.12
node_type_id: Standard_DS3_v2
num_workers: 1
targets:
development:
resources:
jobs:
my-job:
name: my-job
tasks:
- task_key: my-task
new_cluster:
spark_version: 12.2.x-scala2.12
num_workers: 2
# ...
當您針對此範例執行 databricks bundle validate 時,產生的圖形如下所示:
{
"...": "...",
"resources": {
"jobs": {
"my-job": {
"tasks": [
{
"new_cluster": {
"node_type_id": "Standard_DS3_v2",
"num_workers": 2,
"spark_version": "12.2.x-scala2.12"
},
"task_key": "my-task"
}
],
"...": "..."
}
}
}
}