在 Databricks 资产捆绑包中动态定义项目设置

重要

此功能目前以公共预览版提供。

本文介绍了如何在 Databricks 资产捆绑包中替代项目设置。 请参阅什么是 Databricks 资产捆绑包?

在 Azure Databricks 捆绑包配置文件中,可以将顶级 artifacts 映射中的工件设置与 targets 映射中的工件设置联接,例如(为简洁起见,用省略号表示省略的内容):

# ...
artifacts:
  <some-unique-programmatic-identifier-for-this-artifact>:
    # Artifact settings.

targets:
  <some-unique-programmatic-identifier-for-this-target>:
    resources:
      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 映射和 targets 中的 artifacts 映射中定义的。 在此示例中,targetsartifacts 映射中的 path 优先于顶级 artifacts 映射中的 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",
      "...": "..."
    }
  },
  "...": "..."
}