メインコンテンツまでスキップ

バンドルの設定例

この記事では、Databricks Asset Bundles の機能と一般的なバンドルのユース ケースの構成例について説明します。

次の表に示す完全なバンドルの例は、 bundle-examples GitHub リポジトリで入手できます。

バンドル名

説明

dashboard_nyc_taxi

ダッシュボードのスナップショットをキャプチャし、それをサブスクライバーに Eメール する AI/BI dashboard とジョブを含むバンドル

databricks_app

Databricks アプリを定義するバンドル

development_cluster

開発を定義して使用するバンドル(All-Purposeクラスター

job_read_secret

シークレットスコープと、そこから読み取るタスクを持つジョブを定義するバンドル

job_with_multiple_wheels

複数のホイール依存関係を持つジョブを定義して使用するバンドル

job_with_run_job_tasks

A bundle with multiple job with rund job, task(実行ジョブ タスクを持つ複数のジョブを含むバンドル)

job_with_sql_notebook

SQL ノートブックタスクを使用するジョブのバンドル

pipeline_with_schema

Unity Catalog スキーマを定義するバンドルと、それを使用するパイプライン

private_wheel_packages

ジョブのプライベートホイールパッケージを使用するバンドル

python_wheel_poetry

Poetryでwhlを組むバンドル

serverless_job

サーバレス コンピュートを使用してジョブを実行するバンドル

share_files_across_bundles

バンドルのルートディレクトリの外部にあるファイルを含むバンドル。

spark_jar_task

Spark JAR タスクを定義して使用するバンドル

write_from_job_to_volume

Unity Catalog ボリュームにファイルを書き込むバンドル

バンドルのシナリオ

この項では、最上位のバンドル・マッピングの使用方法を示す構成例を示します。「構成リファレンス」を参照してください。

JAR ファイルを Unity Catalog にアップロードするバンドル

Unity Catalogボリュームをアーティファクトパスとして指定して、JARファイルやホイールファイルなどのすべてのアーティファクトがUnity Catalogボリュームにアップロードされるようにすることができます。次の例では、バンドルをビルドして JAR ファイルを Unity Catalog にアップロードします。artifact_pathマッピングに関する情報については、artifact_pathを参照してください。artifactsに関する情報については、アーティファクトを参照してください。

YAML
bundle:
name: jar-bundle

workspace:
host: https://myworkspace.cloud.databricks.com
artifact_path: /Volumes/main/default/my_volume

artifacts:
my_java_code:
path: ./sample-java
build: 'javac PrintArgs.java && jar cvfm PrintArgs.jar META-INF/MANIFEST.MF PrintArgs.class'
files:
- source: ./sample-java/PrintArgs.jar

resources:
jobs:
jar_job:
name: 'Spark Jar Job'
tasks:
- task_key: SparkJarTask
new_cluster:
num_workers: 1
spark_version: '14.3.x-scala2.12'
node_type_id: 'i3.xlarge'
spark_jar_task:
main_class_name: PrintArgs
libraries:
- jar: ./sample-java/PrintArgs.jar

ジョブ構成

このセクションでは、ジョブの設定例を示します。ジョブ設定の詳細については、 ジョブを参照してください。

サーバレス コンピュートを使用するジョブ

Databricks Asset Bundles は、 サーバレス コンピュートで実行されるジョブをサポートします。 ワークフローについては、 Run your LakeFlow Jobs with サーバレス コンピュート を参照してください。これを構成するには、ノートブック タスクを含むジョブの clusters 設定を省略するか、次の例に示すように環境を指定できます。Pythonスクリプト、Python wheel、およびdbtタスクの場合、サーバレス コンピュートにenvironment_keyが必要です。environment_keyを参照してください。

YAML
# A serverless job (no cluster definition)
resources:
jobs:
serverless_job_no_cluster:
name: serverless_job_no_cluster

email_notifications:
on_failure:
- someone@example.com

tasks:
- task_key: notebook_task
notebook_task:
notebook_path: ../src/notebook.ipynb
YAML
# A serverless job (environment spec)
resources:
jobs:
serverless_job_environment:
name: serverless_job_environment

tasks:
- task_key: task
spark_python_task:
python_file: ../src/main.py

# The key that references an environment spec in a job.
# https://docs.databricks.com/api/workspace/jobs/create#tasks-environment_key
environment_key: default

# A list of task execution environment specifications that can be referenced by tasks of this job.
environments:
- environment_key: default

# Full documentation of this spec can be found at:
# https://docs.databricks.com/api/workspace/jobs/create#environments-spec
spec:
client: '1'
dependencies:
- my-library

複数のホイールファイルを使用したジョブ

次の設定例では、複数の *.whl ファイルを持つジョブを含むバンドルを定義しています。

YAML
# job.yml
resources:
jobs:
example_job:
name: 'Example with multiple wheels'
tasks:
- task_key: task

spark_python_task:
python_file: ../src/call_wheel.py

libraries:
- whl: ../my_custom_wheel1/dist/*.whl
- whl: ../my_custom_wheel2/dist/*.whl

new_cluster:
node_type_id: i3.xlarge
num_workers: 0
spark_version: 14.3.x-scala2.12
spark_conf:
'spark.databricks.cluster.profile': 'singleNode'
'spark.master': 'local[*, 4]'
custom_tags:
'ResourceClass': 'SingleNode'
YAML
# databricks.yml
bundle:
name: job_with_multiple_wheels

include:
- ./resources/job.yml

workspace:
host: https://myworkspace.cloud.databricks.com

artifacts:
my_custom_wheel1:
type: whl
build: poetry build
path: ./my_custom_wheel1

my_custom_wheel2:
type: whl
build: poetry build
path: ./my_custom_wheel2

targets:
dev:
default: true
mode: development

requirements.txtファイルを使用するジョブ

次の設定例では、requirements.txt ファイルを使用するジョブを定義しています。

YAML
resources:
jobs:
job_with_requirements_txt:
name: 'Example job that uses a requirements.txt file'
tasks:
- task_key: task
job_cluster_key: default
spark_python_task:
python_file: ../src/main.py
libraries:
- requirements: /Workspace/${workspace.file_path}/requirements.txt

スケジュールに応じたジョブ

次の例は、スケジュールに従って実行されるジョブの構成を示しています。ジョブのスケジュールとトリガーに関する情報については、 スケジュールとトリガーを使用したジョブの自動化を参照してください。

この設定は、毎日指定した時刻に実行されるジョブを定義します。

YAML
resources:
jobs:
my-notebook-job:
name: my-notebook-job
tasks:
- task_key: my-notebook-task
notebook_task:
notebook_path: ./my-notebook.ipynb
schedule:
quartz_cron_expression: '0 0 8 * * ?' # daily at 8am
timezone_id: UTC
pause_status: UNPAUSED

この設定では、ジョブが最後に実行されてから 1 週間後にジョブが実行されました。

YAML
resources:
jobs:
my-notebook-job:
name: my-notebook-job
tasks:
- task_key: my-notebook-task
notebook_task:
notebook_path: ./my-notebook.ipynb
trigger:
pause_status: UNPAUSED
periodic:
interval: 1
unit: WEEKS

パイプラインの構成

このセクションでは、パイプラインの設定例を示します。パイプラインの設定情報については、「 パイプライン」を参照してください。

サーバレス コンピュートを使用するパイプライン

Databricks Asset Bundles は、 サーバレス コンピュートで実行されるパイプラインをサポートします。 これを設定するには、パイプライン serverless 設定を trueに設定します。次の設定例では、サーバレス コンピュートで実行されるパイプラインと、1 時間ごとにパイプラインの更新をトリガーするジョブを定義しています。

YAML
# A pipeline that runs on serverless compute
resources:
pipelines:
my_pipeline:
name: my_pipeline
target: ${bundle.environment}
serverless: true
catalog: users
libraries:
- notebook:
path: ../src/my_pipeline.ipynb

configuration:
bundle.sourcePath: /Workspace/${workspace.file_path}/src
YAML
# This defines a job to refresh a pipeline that is triggered every hour
resources:
jobs:
my_job:
name: my_job

# Run this job once an hour.
trigger:
periodic:
interval: 1
unit: HOURS

email_notifications:
on_failure:
- someone@example.com

tasks:
- task_key: refresh_pipeline
pipeline_task:
pipeline_id: ${resources.pipelines.my_pipeline.id}