DatabricksZero to Advanced

Your daily environment: workspace, notebooks, compute, libraries, file storage.

  • Mostly short exercises. Keep everything in one folder, dbx-course
  • Cluster-configuration topics are explanation only (Free Edition has serverless only)

On Free Edition

Notebooks run on serverless compute only. Concept topics can't be tried hands-on.

2.01Hands-on on Free Edition

Workspace Navigation

By the end: find your way around the workspace and create a folder and a notebook for this course.

Look for Use it to
New Create notebooks, queries, pipelines
Workspace Browse folders, notebooks, files, Git folders
Catalog Browse catalogs, schemas, tables, volumes
SQL Editor Run SQL on a SQL warehouse
Jobs & Pipelines Create and monitor Lakeflow jobs and pipelines
Genie, Genie Code Natural-language questions, coding help
  • The sidebar changes between releases. Look for names, not positions

Run it in Databricks

  1. Workspace, open your home folder
  2. Create, Folder, name it dbx-course
  3. Open Catalog and note your default catalog
  4. In dbx-course: Create, Notebook, name it 00-explore

Habit

Number and name notebooks: 01-ingest-orders, 02-clean-orders. They sort in reading order.

2.02Hands-on on Free Edition

Workspace Folders and Files

By the end: know where code and files live in the workspace and import your own Python module from a workspace file.

helpers.pyworkspace filesys.pathNotebookimport helpers
Shared code lives in workspace files, not copied between notebooks.
  • Workspace holds notebooks and workspace files (modules, configs, small text)
  • Your files: /Workspace/Users/<your-email>/
  • On serverless the working directory isn't guaranteed: use absolute paths

Run it in Databricks

  1. In dbx-course: Create, File, name it helpers.py
  2. Paste the function below and save
  3. Run the second cell in 00-explore
Python
# helpers.py
def add_vat(price, rate=0.21):
    return round(price * (1 + rate), 2)
Python
import sys

user = spark.sql("SELECT current_user()").first()[0]
sys.path.append(f"/Workspace/Users/{user}/dbx-course")

from helpers import add_vat
print(add_vat(100))
Output
121.0

Later

Real projects: code in a Git folder, packaged as a wheel (Module 15).

2.03Hands-on on Free Edition

Notebooks and Supported Languages

By the end: switch languages inside a notebook and share data between a Python cell and a SQL cell.

Python cellcreateOrReplaceTempViewviewSQL cell%sql SELECT ...`_sqldf`Python celldisplay(_sqldf)
Share through the Spark session (temp view), not through variables.
  • Cells run in the notebook's default language unless they start with a magic like %sql
  • Free Edition: Python and SQL only (no R, Scala)
  • Each language has its own REPL: a Python variable is invisible to SQL
Python
spark.range(3).createOrReplaceTempView("three_rows")
SQL
%sql
SELECT * FROM three_rows
Python
display(_sqldf)    # result of the last SQL cell
  • Shift+Enter runs the cell and moves on
  • Cmd/Ctrl+Shift+F formats code
  • Autocomplete needs attached compute. Python notebooks have a debugger
2.04Hands-on on Free Edition

Notebook Commands and Magic Commands

By the end: use the most common magic commands and know which one to pick for which job.

Magic Purpose
%python %sql %scala %r Run cell in that language
%md Render Markdown
%sh Shell on the driver only
%fs dbutils.fs commands, e.g. %fs ls
%run Run another notebook inline (alone in its cell)
%pip Notebook-scoped Python packages
%skip Skip the cell when the notebook runs
Markdown
%md
## Course notes
Use **markdown** cells to document each step.
SQL
%sql
SELECT current_user() AS me, current_date() AS today

%sh on serverless

Availability can differ. Test first. Prefer subprocess, os or dbutils.

Modules over %run

%run hides dependencies and is hard to test. Use importable modules or wheels (topics 2.2, 15.6).

2.05Hands-on on Free Edition

Widgets and Parameters

By the end: parameterize a notebook with widgets and read their values in Python and SQL.

Widgetalways a string`get()`int(...)convertYour code
Convert widget values before using them as numbers or dates.
  • Types: text, dropdown, combobox, multiselect
  • Arguments: name, default, choices (not for text), label
  • Job parameters arrive as widget values (Module 10)
Python
dbutils.widgets.text("country", "NL", "Country code")
dbutils.widgets.dropdown("min_qty", "1", ["1", "2", "3", "4", "5"], "Minimum quantity")

country = dbutils.widgets.get("country")
min_qty = int(dbutils.widgets.get("min_qty"))
print(country, min_qty)
SQL
%sql
SELECT :country AS country, CAST(:min_qty AS INT) AS min_qty
  • Widget as table or column name: IDENTIFIER(:table_name)
  • Clean up: dbutils.widgets.removeAll()

Slips

Widget values are strings. After removing a widget you can't recreate the same name in the same cell.

2.06Hands-on with caveats

Git Integration and Git Folders

By the end: connect a Git repository to the workspace, commit a notebook and open a pull request.

Branchfeature/...Commit & Pushin the Git dialogPull requestin your Git providerPullupdate the folder
Branch, commit, review, merge, pull.
  • Git folder = workspace folder linked to a remote repo
  • Needs a Git account (e.g. GitHub) and credentials configured first

Run it in Databricks

  1. Create an empty repo, e.g. dbx-zero-to-advanced
  2. Workspace, Create, Git folder
  3. Paste the repo URL, pick the provider, Create Git folder
  4. In the Git dialog, create and switch to feature/first-notebook
  5. Add a notebook, write a commit message, Commit & Push
  6. Open a pull request in your provider
  7. After merge, Pull in the Git dialog
  • Merge, rebase, reset are in the dialog menu (rebase and reset rewrite history)

Limits

Standard Git folder: 2 GB memory, 4 GB disk. Pulling clears notebook state. Switching branches can delete assets missing on the new branch.

Branch, don't edit main

Small commits, clear messages, merge through a pull request.

2.07Concept

Databricks Runtime

By the end: say what a Databricks Runtime is, what LTS means, and why you do not choose one on serverless compute.

  • Runtime = software compute runs: a Spark version, Python and system libraries, Databricks optimisations
  • LTS = long-term support, about three years
  • Every runtime has an ML variant with ML libraries preinstalled
  • Serverless: no runtime choice. You pick an environment version instead
Runtime Spark End of support
18 LTS 4.1.0 June 10, 2029
17.3 LTS not checked October 22, 2028
16.4 LTS 3.5.2 May 9, 2028
15.4 LTS 3.5.0 August 19, 2027
14.3 LTS 3.5.0 February 1, 2027

From the release notes as of October 2026. Check the current list.

Python
print(spark.version)

Classic compute

Production: pick an LTS runtime, upgrade deliberately, test jobs first.

2.08Concept

Compute Types and Cluster Configuration

By the end: list the settings of a classic cluster and say what each one controls.

ServerlessDatabricks-managedfast startno configAll-purposeclassic clustersinteractivesharedJobs computeper job runterminated afterSQL warehouseSQL and BIModule 13
Classic cluster setting Controls
Runtime version Spark and library versions
Node type and count Memory, CPU, GPU: speed and cost
Autoscaling Min and max workers
Auto-termination Idle time before stop
Access mode Who can use it, how data access is enforced
Spark configuration Spark properties
Libraries, init scripts Packages and setup at start
Cluster policies Admin limits on all of the above (Module 18)

On Free Edition

Custom compute isn't supported. Everything is serverless.

2.09Concept

All-Purpose vs Job Compute

By the end: choose between serverless, all-purpose and jobs compute for a task.

Serverless jobsnotebooksPython scriptswheelsdbt CLIthe defaultClassic jobsJAR tasksSpark Submitjob-run scopedAll-purposeinteractive devnot for production
  • Serverless jobs don't support every workload. Streaming: continuous scheduling only with bounded triggers like Trigger.AvailableNow
  • Pricing follows the compute that runs the task (Module 18)

Rule of thumb

Develop interactively. Run production on serverless or classic jobs compute, never on a shared all-purpose cluster.

2.10Hands-on on Free Edition

Serverless Compute

By the end: work with serverless compute and know the behaviours that differ from classic Spark.

Area On serverless
APIs Spark Connect only: no RDDs
Caching cache(), persist(), CACHE TABLE raise errors
Temp views No global temp views
Spark configs Most unsupported
SQL mode ANSI on: bad casts and overflow raise errors, not NULL
Time zone Etc/UTC
Analysis Names resolved at execution time, so errors can appear late
Languages No Scala or R
Files Volumes or workspace files. DBFS limited

Run it in Databricks

Run each cell in 00-explore and read the messages.

Python
print(spark.conf.get("spark.sql.session.timeZone"))
Output
Etc/UTC
Python
try:
    spark.sql("SELECT 1/0 AS x").collect()      # ANSI: raises
except Exception as e:
    print(str(e).splitlines()[0])

display(spark.sql("SELECT try_divide(1, 0) AS x"))   # NULL
Python
try:
    spark.range(10).cache()
except Exception as e:
    print("cache not supported:", str(e).splitlines()[0])

Instead of caching

Write the expensive intermediate result to a Delta table and read it back. Restartable and inspectable.

2.11Hands-on with caveats

Libraries and Dependencies

By the end: install a Python library for one notebook and understand how that differs from a reproducible environment.

%pip install pkg==x.y.zrestartPython()own cellimport pkg
Install, restart, then import.
Python
%pip install humanize==4.9.0
Python
dbutils.library.restartPython()    # variables before this are lost
Python
import humanize
print(humanize.intcomma(1234567))
Output
1,234,567
  • %pip is notebook-scoped and gone next session: put it at the top
  • It doesn't restart Python for you
  • Other sources: wheel in a volume (/Volumes/.../pkg.whl), workspace wheel, Git URL
  • Reproducible serverless setup: Environment side panel with pinned versions
  • Environment version 5+: %uv pip for faster installs while iterating (not for reproducible environments)

Pin versions

Always ==x.y.z. Unpinned %pip install isn't compatible with serverless.

Free Edition

Outbound internet is limited to trusted domains. A failing install may be that.

2.12Hands-on on Free Edition

DBFS, Workspace Files, and Unity Catalog Volumes

By the end: store data in a Unity Catalog volume, read it with Spark and choose the right storage location for code versus data.

Volumes/Volumes/cat/schema/vol/data filesgoverned by UCWorkspace files/Workspace/...code, configsmall filesDBFS rootdbfs:/...legacymay be disabled
  • External locations: existing cloud storage governed by Unity Catalog
  • A volume belongs to a schema: create the schema and volume first
  • Module 4 reuses this schema
Python
catalog = spark.sql("SELECT current_catalog()").first()[0]
schema = "dbx_course"

spark.sql(f"CREATE SCHEMA IF NOT EXISTS {catalog}.{schema}")
spark.sql(f"CREATE VOLUME IF NOT EXISTS {catalog}.{schema}.raw")

path = f"/Volumes/{catalog}/{schema}/raw"
with open(f"{path}/hello.csv", "w") as f:
    f.write("id,name\n1,Ada\n2,Grace\n")

spark.read.option("header", True).csv(f"{path}/hello.csv").show()
Output
+---+-----+
| id| name|
+---+-----+
|  1|  Ada|
|  2|Grace|
+---+-----+
Python
display(dbutils.fs.ls(path))

Upload a file from your computer

  1. New, Add or upload data
  2. Upload files to a volume
  3. Drag a file in
  4. Destination volume: choose raw

Needs WRITE VOLUME on the volume plus USE SCHEMA and USE CATALOG on its parents. Up to 5 GB per file.

Code in Git, data in volumes

Never hard-code a person's home folder in a job. Build paths from configuration (Module 21).

Recap

What you can do now

  • Navigate the workspace, create folders, files, notebooks, import your own module
  • Mix Python and SQL, parameterize with widgets
  • Git folders and committing from the workspace
  • Runtime, LTS and the kinds of job compute
  • Serverless behaviours that differ from classic Spark
  • You created the dbx_course schema and raw volume that Module 4 builds on