Sub topic 2
Choosing a task type
A job task runs one unit of work. The task type decides what that work is, where it runs, and how you pass it input. This chapter assumes you have run Databricks notebooks, can read Python or SQL, and know that jobs run on compute you configure separately. The compute options, dependency wiring, and parameters each get their own chapter.
What a task type decides
Every task has a unique task_key and exactly one type-specific block, such as notebook_task or sql_task. That block defines three things:
- The code unit. This is a notebook, a script, a packaged library, a query, or a whole pipeline.
- The compute it can use. SQL tasks need a SQL warehouse. Most other types run on a job cluster, an all-purpose cluster, or serverless compute.
- How input arrives. Notebooks read widgets, scripts read command-line arguments, and wheels receive arguments through an entry point.
Switching type later usually means rewriting the code, so choose it deliberately.
Tasks that run your code
Notebook
A notebook task runs a notebook from the workspace or a Git repository. It is the default choice when the work is exploratory in origin, mixes Python, SQL, and markdown, or needs dbutils. Parameters arrive as widgets, and dbutils.notebook.exit() can return a short string.
The cost is testability. Notebooks are harder to unit test and review than plain modules.
Python script
A Python script task runs a .py file from the workspace, a Unity Catalog volume, or Git. Parameters become a list of strings, read through sys.argv.
import sys
def main(argv: list[str]) -> None:
run_date = argv[0] if argv else "1970-01-01"
print(f"Processing partition {run_date}")
if __name__ == "__main__":
main(sys.argv[1:])Choose a script when you want normal Python files, code review, and local execution without notebook syntax.
Python wheel
A Python wheel task calls an entry point in a built package. You give it the package name, the entry point, and parameters, and the wheel must be attached to the task as a library. Pick it when the logic already lives in a versioned package that you test and release through CI.
JAR
A JAR task runs a main class from a JVM library. Use it for existing Scala or Java Spark code. Two rules apply:
- Do not call
System.exit()in your code. - Obtain the Spark session with
SparkSession.builder().getOrCreate()instead of creating your own context.
Spark Submit
Spark Submit exists for jobs written for spark-submit. It has more restrictions than the other code types. It runs only on new job clusters, it does not support autoscaling, and it cannot use dbutils. Prefer a JAR or Python script task unless you are migrating an existing command line unchanged.
Tasks that run managed work
SQL
A SQL task runs on a SQL warehouse, not on a cluster. It can run a saved query, a file from the workspace or Git, a legacy dashboard refresh, or an alert. It is the lightest way to schedule pure SQL, because no cluster has to start.
Pipeline
A pipeline task starts an update of a Lakeflow Declarative Pipeline (formerly Delta Live Tables). The pipeline owns its own compute and table definitions, and the job only triggers it and waits. You can request a full refresh when you need to reprocess everything.
dbt
A dbt task runs dbt commands such as dbt deps, dbt seed, and dbt run against a dbt project in Git or the workspace. It needs a SQL warehouse to execute models. Use it when your transformations are already dbt models.
Tasks that control the workflow
Three types run no data work of their own. They shape the graph.
- Run Job starts another job and waits for it. Later chapters cover it.
- If/else condition compares two values and sends execution down a true or false branch.
- For each runs a nested task once per input value.
Comparing the types
| Task type | Code lives in | Runs on | Input arrives as |
|---|---|---|---|
| Notebook | Workspace or Git | Job cluster, all-purpose cluster, or serverless | Widgets |
| Python script | Workspace, volume, or Git | Cluster or serverless | `sys.argv` |
| Python wheel | Attached package | Cluster or serverless | Entry-point arguments |
| JAR | Attached JAR | Cluster | `main` method arguments |
| Spark Submit | JAR or Python file | New job cluster only | Command-line arguments |
| SQL | Query, file, dashboard, or alert | SQL warehouse | Query parameters |
| Pipeline | Pipeline definition | Pipeline's own compute | Refresh options |
| dbt | dbt project | SQL warehouse | dbt command and variables |
Serverless availability varies by type and by cloud, so check your workspace before assuming a combination works.
A decision path
Mixing types in one job
One job can combine types freely. The next fragment ingests with a script, builds a table with a wheel, and refreshes a saved query. It omits compute settings, which the compute chapter covers. The two placeholder values are yours to supply.
[
{
"task_key": "ingest",
"spark_python_task": {
"python_file": "/Workspace/Shared/ingest.py",
"parameters": ["2026-12-04"]
}
},
{
"task_key": "build_tables",
"depends_on": [{"task_key": "ingest"}],
"python_wheel_task": {
"package_name": "sales_etl",
"entry_point": "build",
"parameters": ["--date", "2026-12-04"]
},
"libraries": [{"whl": "/Volumes/main/default/libs/sales_etl-1.0.0-py3-none-any.whl"}]
},
{
"task_key": "refresh_report",
"depends_on": [{"task_key": "build_tables"}],
"sql_task": {
"warehouse_id": "<your-warehouse-id>",
"query": {"query_id": "<your-query-id>"}
}
}
]Each task has its own type block, so a SQL warehouse task can sit next to cluster-based tasks without conflict.
Common mistakes
- Using a notebook for everything. Notebooks work, but shared logic copied between them drifts. Move reusable code into a wheel or a module.
- Running simple SQL on a cluster. A notebook that only runs SQL pays for cluster startup. A SQL task on a warehouse avoids that.
- Calling
dbutilsfrom a Spark Submit task. It is not supported there, so the task fails at runtime. - Expecting a script to read widgets. Script tasks pass plain arguments, and
dbutils.widgetsdoes not apply. - Ending a JAR with
System.exit(). This can make a successful run report failure. - Creating a second Spark context in a JAR. Use
getOrCreate()so you share the one the cluster provides.
Exercise
A team has a daily job that runs three saved SQL queries to build summary tables, then calls a Scala library for a model score. Which task types should they use, and why is a notebook not the best choice for the SQL step?
Show answer
Use SQL tasks for the three queries and a JAR task for the Scala library. SQL tasks run on a SQL warehouse, so no cluster has to start for the SQL work. A notebook would need cluster compute, and it would add startup time and cost for work that is only SQL. The JAR task fits the Scala code directly and avoids rewriting it.
Exercise
You must migrate an existing spark-submit command that uses autoscaling and calls dbutils.fs. Why is a Spark Submit task a poor target, and what should you use instead?
Show answer
Spark Submit tasks run only on new job clusters, do not support autoscaling, and do not support dbutils. Repackage the code as a Python script task, JAR task, or notebook task. Each of these can use compute with autoscaling, and notebooks can use dbutils.