BrainBank

Databricks Quick Reference & Cheat Sheet

7/30/2026, 12:07:46 AM

#skill#databricks#delta-lake#spark#lakehouse#data-analytics#workspace-basics

A concise Databricks platform guide covering core concepts (Lakehouse, Delta Lake), workspace essentials (notebooks, clusters, jobs), and key Spark SQL / DBFS / Delta operations for everyday data engineering and analytics tasks.

Databricks Quick Reference & Cheat Sheet

Getting Started

9f622ca2-a8e8-4aeb-a9b0-1390d3dfceac.png


Cluster & Compute Configuration

SettingDescription
Cluster TypeSelect cluster mode (Single Node, Standard High Throughput, High Concurrency)
Worker NodesNumber of worker nodes; autoscaling controls min/max workers
Runtime VersionPhoton-enabled runtime recommended for performance
Init ScriptsPython scripts to run on node start-up

Cluster Configuration Basics

  • Cluster mode: Choose based on workload type (development, production, ML)
  • Worker nodes: Autoscale between configured bounds for cost efficiency
  • Photon: Enable for large-scale query acceleration
  • Job clusters: Best for one-time or scheduled workloads — no upfront cost

Databricks SQL & Warehousing

-- Create a table in Unity Catalog
CREATE TABLE catalog.schema.table_name (
    id BIGINT,
    name STRING,
    value DOUBLE
);

-- Query via Serverless SQL Warehouse
SELECT * FROM catalog.schema.table_name LIMIT 10;

-- Change warehouse / query context
ALTER WAREHOUSE warehouse_name SET AUTOSTOP = 30 MINUTE;

Key takeaway: Databricks SQL warehouses (Standard or Serverless) handle BI/SQL workloads with separate compute from Notebook clusters.


Delta Lake Essentials

OperationCommand
Read delta tablespark.read.format("delta").load("/path/to/table")
Write (overwrite)df.write.format("delta").mode("overwrite").save("/path/to/table")
OPTIMIZE & ZORDEROPTIMIZE table_name; ZORDER BY(col1, col2);

Delta Time Travel

-- Read by delta version
SELECT * FROM table_name VERSION AS OF 42;

-- Read by timestamp
SELECT * FROM table_name TIMESTAMP AS '2025-08-01 00:00:00';

ZORDER BY co-locates related information in the same set of files, drastically speeding up filtered queries.


Spark SQL Cheat Sheet

DataFrame Creation & Common Patterns

# Read from various sources
df = spark.read.format("csv").option("header", "true").load("/path/to/file.csv")
df = spark.read.json("/path/to/file.json")
df = spark.read.parquet("/path/to/data/")

# SQL-Style Querying
spark.table("catalog.schema.table_name").createOrReplaceTempView("t")
results = spark.sql("SELECT col1, COUNT(*) FROM t GROUP BY col1")

Common Spark Transformations

TransformationDescriptionExample
selectPick / rename columnsdf.select("col1", "col2")
filterFilter rowsdf.filter(df.col > 10)
groupByAggregatedf.groupBy("region").count()
joinCombine DataFramesdf1.join(df2, "id")
orderBySort resultsdf.orderBy(desc("date"))
withColumnAdd / modify columnsdf.withColumn("x2", df.x * 2)

Common Spark Aggregations

from pyspark.sql.functions import col, avg, count, sum, max, min, when

df.agg(
    avg("price").alias("avg_price"),
    count("*").alias("total_records"),
    sum("quantity").alias("total_qty"),
    max("date").alias("latest_day")
)

-- Conditional aggregation with CASE WHEN equivalent
df.withColumn("tier", when(df.amount > 1000, "high").otherwise("low"))

Unity Catalog (UC) Navigation

ObjectSyntax / Pattern
Metastorespark.conf.set("spark.sql.catalog.spark_catalog", "com.databricks.backend.catatalogs.catalyst.CatalogHandler")
Schema / DatabaseUSE CATALOG my_catalog; USE SCHEMA my_schema;
Tablecatalog.schema.table_name
ViewCREATE VIEW catalog.schema.view AS SELECT ...

Unity Catalog Permissions (GRANT/REVOKE)

-- Grant table read access
GRANT SELECT ON TABLE catalog.schema.table TO role_name;

-- Grant schema usage
GRANT USE SCHEMA ON SCHEMA catalog.schema TO role_name;

-- Revoke
REVOKE ALL ON TABLE catalog.schema.table FROM role_name;

Unity Catalog provides centralized governance across workspaces: one place for access control, data discovery, and audit logs.


Notebooks & Development Tips

FeatureShortcut / Tip
Run cellShift + Enter
Auto-completeCtrl + Space (or Cmd + Space on Mac)
SQL cellStart with %sql magic
Python cellDefault; start with %python explicitly if needed
Multi-languageUse cell headers to select language per cell

Cell Magics

%sql -- switch cell language to SQL
%python -- switch to Python  
%sh -- shell commands
%md -- Markdown rendering
%fs -- Databricks File System operations

Delta Live Tables (DLT)

@dlt.table
def clean_data():
    return (
        spark.readStream.format("delta").load("/path/to/source")
            .filter(col("status") == "active")
    )

DLT defines declarative data pipelines with built-in schema enforcement, incremental processing, and automatic refresh.


Databricks Jobs / Workflows

Triggering Jobs via CLI or API

# Databricks CLI — create a job
databricks jobs create \
  --name "ETL Pipeline" \
  --new-cluster '{"spark_version":"14.3.x-scala2.12","NodeType":"r6id.xlarge", ...}'

# Run a job now
databricks jobs run-now --job-id 12345

Workflow Task Patterns

PatternUse Case
Notebook taskRun an existing notebook as part of a larger workflow
Task dependencyDefine upstream → downstream execution order
Conditional tasksCheck task.run status before proceeding to next node

Common File Operations (DBFS / /dbfs/)

# Listing files
dbutils.fs.ls("/path/to/dir")

# Copying
dbutils.fs.cp("file:/local/path", "/dbfs/mnt/gcs/bucket/folder")

# Creating directories
dbutils.fs.mkdirs("/dbfs/tmp/new_folder")

# Downloading from external storage (mount example)
dbutils.fs.mount(
  source="gs://bucket-name/path",
  mount_point="/mnt/gs/bucket-name",
  extra_configs={"fs.gs.auth.service.account.json.keyfile": "…"}
)

Key takeaways

  • Cluster mode: Use Standard for dev, High Concurrency for BI/shared SQL warehouses. Use Photon-enabled runtimes where possible.
  • Delta Lake is the storage layer; leverage time travel and OPTIMIZE/ZORDER for performance.
  • Unity Catalog centralizes governance (metastore → catalog → schema → table).
  • Notebook cells support multi-language switching via %sql, %python, etc. — use them inline as needed.
  • DLT & Workflows turn notebooks into production-ready, scheduled pipelines with clear lineage and SLAs.

Learning map

Databricks Learning Map

Stage 1 — Foundation

  • Understand the Lakehouse architecture concept
  • Explore Delta Lake fundamentals (ACID transactions, time travel, schema enforcement)
  • Set up a Databricks workspace (community edition or cloud trial)

Stage 2 — Workspace Navigation

  • Create & run notebooks (pySpark / SQL / Python / Scala)
  • Provision and manage compute clusters (serverless vs. all-purpose, jobclusters)
  • Navigate DBFS (Databricks File System) basics

Stage 3 — Spark & SQL Operations

  • Write Spark DataFrame transformations in pySpark
  • Run Delta Lake commands (delta, create table, MERGE INTO)
  • Use Databricks SQL warehouses for dashboarding and ad-hoc queries

Stage 4 — Automation & Governance

  • Schedule Jobs (notebook-based and task-based workflows)
  • Enable Unity Catalog for data governance and access control
  • Automate ELT pipelines with Delta Live Tables (DLT)

Get hands-on — step by step

  1. Sign up for Databricks Community Edition or a free cloud trial.
  2. Log into the workspace and create a new notebook — choose pySpark as the language.
  3. Create an all-purpose cluster from your notebook, select the runtime version "Databricks Runtime 14.x" (or latest ML/Standard), and attach it.
  4. Upload a CSV file to DBFS by dragging it into the sidebar or running: dbutils.fs.put("/FileStore/my_data.csv", ...).
  5. Load the data into a DataFrame: df = spark.read.csv("/FileStore/my_data.csv", header=True, inferSchema=True). Display results with display(df.head(10)).
  6. Register as a Delta table: df.write.format("delta").mode("overwrite").saveAsTable("my_customers)`.
  7. Query the table using Spark SQL in another cell:
    %sql
    SELECT * FROM my_customers WHERE age > 25 ORDER BY revenue DESC LIMIT 10;
    
  8. Test time travel by modifying data and querying a previous version: SELECT * FROM my_customers FOR SYSTEM_TIME AS OF timestamp('2024,01').
  9. Create a MERGE (upsert): Run a Delta MERGE INTO statement to update or insert rows based on matching conditions.
  10. Schedule the notebook as a Job: go to Jobs > New Job > set Trigger to "Schedule" (e.g., daily at 2 AM) and add your notebook as a task.
  11. Create a SQL warehouse — connect with Databricks SQL editor and build a simple dashboard from results.

Top 3 sources

  1. 1
    Databricks Docs — Delta Lake Quickstart

    Official Delta Lake documentation covering table creation, merges, time travel, and best-practice patterns.

    https://docs.databricks.com/en/delta-lake/index.html

  2. 2
    Databricks Academy — Getting Started with Databricks Community Edition

    Free, self-paced training that walks you through workspaces, notebooks, clusters, and hands-on labs.

    https://www.databricks.com/learn/training/community-edition

  3. 3
    Apache Spark SQL Language Reference

    The canonical reference for Spark SQL syntax, DataFrame APIs, and built-in functions (runs identically on Databricks).

    https://spark.apache.org/docs/latest/sql-programming-guide.html

Links are AI-suggested — worth a quick sanity check before diving in.