# helpers.py
def add_vat(price, rate=0.21):
return round(price * (1 + rate), 2)
Module 2: Databricks Workspace & Environment
Find your way around the workspace, notebooks, compute and file storage.
Topics in this module
- Workspace Navigation
- Workspace Folders and Files
- Notebooks and Supported Languages
- Notebook Commands and Magic Commands
- Widgets and Parameters
- Git Integration and Git Folders
- Databricks Runtime
- Compute Types and Cluster Configuration
- All-Purpose vs Job Compute
- Serverless Compute
- Libraries and Dependencies
- DBFS, Workspace Files, and Unity Catalog Volumes
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.
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
- Workspace, open your home folder
- Create, Folder, name it
dbx-course - Open Catalog and note your default catalog
- In
dbx-course: Create, Notebook, name it00-explore
Habit
Number and name notebooks: 01-ingest-orders, 02-clean-orders. They sort in reading order.
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.
- 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
- In
dbx-course: Create, File, name ithelpers.py - Paste the function below and save
- Run the second cell in
00-explore
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))
121.0
Later
Real projects: code in a Git folder, packaged as a wheel (Module 15).
Notebooks and Supported Languages
By the end: switch languages inside a notebook and share data between a Python cell and a SQL cell.
- 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
spark.range(3).createOrReplaceTempView("three_rows")
%sql
SELECT * FROM three_rows
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
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 |
%md
## Course notes
Use **markdown** cells to document each step.
%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).
Widgets and Parameters
By the end: parameterize a notebook with widgets and read their values in Python and SQL.
- Types:
text,dropdown,combobox,multiselect - Arguments: name, default, choices (not for text), label
- Job parameters arrive as widget values (Module 10)
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
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.
Git Integration and Git Folders
By the end: connect a Git repository to the workspace, commit a notebook and open a pull request.
- Git folder = workspace folder linked to a remote repo
- Needs a Git account (e.g. GitHub) and credentials configured first
Run it in Databricks
- Create an empty repo, e.g.
dbx-zero-to-advanced - Workspace, Create, Git folder
- Paste the repo URL, pick the provider, Create Git folder
- In the Git dialog, create and switch to
feature/first-notebook - Add a notebook, write a commit message, Commit & Push
- Open a pull request in your provider
- 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.
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.
print(spark.version)
Classic compute
Production: pick an LTS runtime, upgrade deliberately, test jobs first.
Compute Types and Cluster Configuration
By the end: list the settings of a classic cluster and say what each one controls.
| 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.
All-Purpose vs Job Compute
By the end: choose between serverless, all-purpose and jobs compute for a task.
- 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.
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.
print(spark.conf.get("spark.sql.session.timeZone"))
Etc/UTC
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
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.
Libraries and Dependencies
By the end: install a Python library for one notebook and understand how that differs from a reproducible environment.
%pip install humanize==4.9.0
dbutils.library.restartPython() # variables before this are lost
import humanize
print(humanize.intcomma(1234567))
1,234,567
%pipis 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 pipfor 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.
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.
- 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
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()
+---+-----+ | id| name| +---+-----+ | 1| Ada| | 2|Grace| +---+-----+
display(dbutils.fs.ls(path))
Upload a file from your computer
- New, Add or upload data
- Upload files to a volume
- Drag a file in
- 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).
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_courseschema andrawvolume that Module 4 builds on